lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Sun, 21 Jun 2020 10:56:56 +0200
From:   Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To:     Denis Efremov <efremov@...ux.com>
Cc:     "Rafael J. Wysocki" <rafael@...nel.org>,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] driver core: Use scnprintf() instead of snprintf() in
 device show functions

On Sat, Jun 20, 2020 at 06:05:29PM +0300, Denis Efremov wrote:
> >From Documentation/filesystems/sysfs.txt:
> - show() must not use snprintf() when formatting the value to be
>   returned to user space. If you can guarantee that an overflow
>   will never happen you can use sprintf() otherwise you must use
>   scnprintf().
> 
> The reason is that snprintf() returns the length the resulting string
> would be, assuming the data will fit into the destination array.
> scnprintf() returns the length of the string actually created in buf.
> 
> device_show_{ulong,int,bool}() functions are reference implementation
> and should respect the kernel documentation.

Ok, but you are not following that documentation below, why not?

> 
> Signed-off-by: Denis Efremov <efremov@...ux.com>
> ---
> 
> Actually, I don't know why snprintf() is used here initially. It looks
> safe to use sprintf().
> 
>  drivers/base/core.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 67d39a90b45c..2815deb511fc 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -1472,7 +1472,7 @@ ssize_t device_show_ulong(struct device *dev,
>  			  char *buf)
>  {
>  	struct dev_ext_attribute *ea = to_ext_attr(attr);
> -	return snprintf(buf, PAGE_SIZE, "%lx\n", *(unsigned long *)(ea->var));
> +	return scnprintf(buf, PAGE_SIZE, "%lx\n", *(unsigned long *)(ea->var));

As the documentation states, these should just be sprintf(), if you
really want to change these.

As-is, these are also ok, there is no need to change.

thanks,

greg k-h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ