* [PATCH] sysfs: Replace %p with %pK in the warning of sysfs_emit*
@ 2023-06-23 14:20 Kyle Tso
2023-06-23 14:30 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: Kyle Tso @ 2023-06-23 14:20 UTC (permalink / raw)
To: gregkh, rafael; +Cc: badhri, linux-kernel, Kyle Tso
According to Documentation/core-api/printk-formats.rst, kernel pointers
need to be printed with %pK format specifier to respect kptr_restrict in
sysctl.
Also replace the function names in the strings with %s and __func__ as
checkpatch.pl suggested.
Signed-off-by: Kyle Tso <kyletso@google.com>
---
fs/sysfs/file.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index a12ac0356c69..56712f0886ef 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -732,7 +732,7 @@ int sysfs_emit(char *buf, const char *fmt, ...)
int len;
if (WARN(!buf || offset_in_page(buf),
- "invalid sysfs_emit: buf:%p\n", buf))
+ "invalid %s: buf:%pK\n", __func__, buf))
return 0;
va_start(args, fmt);
@@ -760,7 +760,7 @@ int sysfs_emit_at(char *buf, int at, const char *fmt, ...)
int len;
if (WARN(!buf || offset_in_page(buf) || at < 0 || at >= PAGE_SIZE,
- "invalid sysfs_emit_at: buf:%p at:%d\n", buf, at))
+ "invalid %s: buf:%pK at:%d\n", __func__, buf, at))
return 0;
va_start(args, fmt);
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sysfs: Replace %p with %pK in the warning of sysfs_emit*
2023-06-23 14:20 [PATCH] sysfs: Replace %p with %pK in the warning of sysfs_emit* Kyle Tso
@ 2023-06-23 14:30 ` Greg KH
2023-06-23 14:51 ` Kyle Tso
0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2023-06-23 14:30 UTC (permalink / raw)
To: Kyle Tso; +Cc: rafael, badhri, linux-kernel
On Fri, Jun 23, 2023 at 10:20:54PM +0800, Kyle Tso wrote:
> According to Documentation/core-api/printk-formats.rst, kernel pointers
> need to be printed with %pK format specifier to respect kptr_restrict in
> sysctl.
>
> Also replace the function names in the strings with %s and __func__ as
> checkpatch.pl suggested.
>
> Signed-off-by: Kyle Tso <kyletso@google.com>
> ---
> fs/sysfs/file.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
> index a12ac0356c69..56712f0886ef 100644
> --- a/fs/sysfs/file.c
> +++ b/fs/sysfs/file.c
> @@ -732,7 +732,7 @@ int sysfs_emit(char *buf, const char *fmt, ...)
> int len;
>
> if (WARN(!buf || offset_in_page(buf),
> - "invalid sysfs_emit: buf:%p\n", buf))
> + "invalid %s: buf:%pK\n", __func__, buf))
Wait, no, these are not going out in sysfs files, as they are still
going to dmesg, right?
So I think this line in the documentation matters:
This modifier is *only* intended when producing content of a file read by
userspace from e.g. procfs or sysfs, not for dmesg. Please refer to the
section about %p above for discussion about how to manage hashing pointers
in printk().
so %p should still be ok here, the hashed value will end up in the
kernerl log, which is what we want, and the WARN() traceback will show
the problem properly, right?
> return 0;
>
> va_start(args, fmt);
> @@ -760,7 +760,7 @@ int sysfs_emit_at(char *buf, int at, const char *fmt, ...)
> int len;
>
> if (WARN(!buf || offset_in_page(buf) || at < 0 || at >= PAGE_SIZE,
> - "invalid sysfs_emit_at: buf:%p at:%d\n", buf, at))
> + "invalid %s: buf:%pK at:%d\n", __func__, buf, at))
Same here, %p should be correct.
Sorry for missing this before.
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sysfs: Replace %p with %pK in the warning of sysfs_emit*
2023-06-23 14:30 ` Greg KH
@ 2023-06-23 14:51 ` Kyle Tso
0 siblings, 0 replies; 3+ messages in thread
From: Kyle Tso @ 2023-06-23 14:51 UTC (permalink / raw)
To: Greg KH; +Cc: rafael, badhri, linux-kernel
On Fri, Jun 23, 2023 at 10:30 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Fri, Jun 23, 2023 at 10:20:54PM +0800, Kyle Tso wrote:
> > According to Documentation/core-api/printk-formats.rst, kernel pointers
> > need to be printed with %pK format specifier to respect kptr_restrict in
> > sysctl.
> >
> > Also replace the function names in the strings with %s and __func__ as
> > checkpatch.pl suggested.
> >
> > Signed-off-by: Kyle Tso <kyletso@google.com>
> > ---
> > fs/sysfs/file.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
> > index a12ac0356c69..56712f0886ef 100644
> > --- a/fs/sysfs/file.c
> > +++ b/fs/sysfs/file.c
> > @@ -732,7 +732,7 @@ int sysfs_emit(char *buf, const char *fmt, ...)
> > int len;
> >
> > if (WARN(!buf || offset_in_page(buf),
> > - "invalid sysfs_emit: buf:%p\n", buf))
> > + "invalid %s: buf:%pK\n", __func__, buf))
>
> Wait, no, these are not going out in sysfs files, as they are still
> going to dmesg, right?
>
> So I think this line in the documentation matters:
> This modifier is *only* intended when producing content of a file read by
> userspace from e.g. procfs or sysfs, not for dmesg. Please refer to the
> section about %p above for discussion about how to manage hashing pointers
> in printk().
>
> so %p should still be ok here, the hashed value will end up in the
> kernerl log, which is what we want, and the WARN() traceback will show
> the problem properly, right?
>
> > return 0;
> >
> > va_start(args, fmt);
> > @@ -760,7 +760,7 @@ int sysfs_emit_at(char *buf, int at, const char *fmt, ...)
> > int len;
> >
> > if (WARN(!buf || offset_in_page(buf) || at < 0 || at >= PAGE_SIZE,
> > - "invalid sysfs_emit_at: buf:%p at:%d\n", buf, at))
> > + "invalid %s: buf:%pK at:%d\n", __func__, buf, at))
>
>
> Same here, %p should be correct.
>
> Sorry for missing this before.
>
> greg k-h
Yes, you are right. Sorry for the noise.
Kyle
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-23 14:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-23 14:20 [PATCH] sysfs: Replace %p with %pK in the warning of sysfs_emit* Kyle Tso
2023-06-23 14:30 ` Greg KH
2023-06-23 14:51 ` Kyle Tso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®