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: <20250416111727.GO395307@horms.kernel.org>
Date: Wed, 16 Apr 2025 12:17:27 +0100
From: Simon Horman <horms@...nel.org>
To: Jakub Kicinski <kuba@...nel.org>
Cc: Pranav Tyagi <pranav.tyagi03@...il.com>, davem@...emloft.net,
	dsahern@...nel.org, edumazet@...gle.com, pabeni@...hat.com,
	skhan@...uxfoundation.org, netdev@...r.kernel.org,
	linux-kernel@...r.kernel.org, linux-kernel-mentees@...ts.linux.dev
Subject: Re: [PATCH net-next] net: ipconfig: replace strncpy with strscpy

On Tue, Apr 15, 2025 at 05:19:27PM -0700, Jakub Kicinski wrote:
> On Tue, 15 Apr 2025 17:35:36 +0100 Simon Horman wrote:
> > > @@ -1690,7 +1690,7 @@ static int __init ic_proto_name(char *name)
> > >  			*v = 0;
> > >  			if (kstrtou8(client_id, 0, dhcp_client_identifier))
> > >  				pr_debug("DHCP: Invalid client identifier type\n");
> > > -			strncpy(dhcp_client_identifier + 1, v + 1, 251);
> > > +			strscpy(dhcp_client_identifier + 1, v + 1, 251);  
> > 
> > As an aside, I'm curious to know why the length is 251
> > rather than 252 (sizeof(dhcp_client_identifier) -1).
> > But that isn't strictly related to this patch.
> 
> Isn't this because strncpy() doesn't nul-terminate, and since this is a
> static variable if we use len - 1 we guarantee that there will be a null
> byte at the end? If we switch to strscpy we'll make the max string len
> 1 char shorter.

Yes, that makes sense to me.
And so I think the patch should also increase 251 to 252.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ