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] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241024105508.GA1202098@kernel.org>
Date: Thu, 24 Oct 2024 11:55:08 +0100
From: Simon Horman <horms@...nel.org>
To: Gax-c <zichenxie0106@...il.com>
Cc: kuba@...nel.org, andrew+netdev@...n.ch, davem@...emloft.net,
	edumazet@...gle.com, pabeni@...hat.com, petrm@...dia.com,
	idosch@...dia.com, netdev@...r.kernel.org, zzjas98@...il.com,
	chenyuan0y@...il.com
Subject: Re: [PATCH v2] netdevsim: Add trailing zero to terminate the string
 in nsim_nexthop_bucket_activity_write()

On Tue, Oct 22, 2024 at 12:19:08PM -0500, Gax-c wrote:
> From: Zichen Xie <zichenxie0106@...il.com>
> 
> This was found by a static analyzer.
> We should not forget the trailing zero after copy_from_user()
> if we will further do some string operations, sscanf() in this
> case. Adding a trailing zero will ensure that the function
> performs properly.
> 
> Fixes: c6385c0b67c5 ("netdevsim: Allow reporting activity on nexthop buckets")
> Signed-off-by: Zichen Xie <zichenxie0106@...il.com>
> ---
> v2: adjust code format.
> ---
>  drivers/net/netdevsim/fib.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/netdevsim/fib.c b/drivers/net/netdevsim/fib.c
> index 41e80f78b316..16c382c42227 100644
> --- a/drivers/net/netdevsim/fib.c
> +++ b/drivers/net/netdevsim/fib.c
> @@ -1377,10 +1377,12 @@ static ssize_t nsim_nexthop_bucket_activity_write(struct file *file,
>  
>  	if (pos != 0)
>  		return -EINVAL;
> -	if (size > sizeof(buf))
> +	if (size > sizeof(buf) - 1)

I don't think this change for the best.
If the input data is well formatted it will end with a '\0'.
Which may be copied into the last byte of buf.

With this change the maximum size of the input data is
unnecessarily reduced by one.

>  		return -EINVAL;
>  	if (copy_from_user(buf, user_buf, size))
>  		return -EFAULT;
> +	buf[size] = 0;
> +
>  	if (sscanf(buf, "%u %hu", &nhid, &bucket_index) != 2)
>  		return -EINVAL;
>  
> -- 
> 2.34.1
> 
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ