netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ipconfig: replace strncpy with strscpy_pad
@ 2025-04-08 18:57 Pranav Tyagi
  2025-04-08 21:44 ` Nelson, Shannon
  0 siblings, 1 reply; 5+ messages in thread
From: Pranav Tyagi @ 2025-04-08 18:57 UTC (permalink / raw)
  To: davem, dsahern, edumazet, kuba, pabeni, horms, skhan, netdev,
	linux-kernel, linux-kernel-mentees
  Cc: Pranav Tyagi

Replace the deprecated strncpy() function with strscpy_pad() as the
destination buffer is NUL-terminated and requires
trailing NUL-padding

Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
---
 net/ipv4/ipconfig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index c56b6fe6f0d7..7c238d19328f 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -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_pad(dhcp_client_identifier + 1, v + 1, 251);
 			*v = ',';
 		}
 		return 1;
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: ipconfig: replace strncpy with strscpy_pad
  2025-04-08 18:57 [PATCH] net: ipconfig: replace strncpy with strscpy_pad Pranav Tyagi
@ 2025-04-08 21:44 ` Nelson, Shannon
  2025-04-10 19:59   ` Pranav Tyagi
  2025-04-10 20:05   ` Simon Horman
  0 siblings, 2 replies; 5+ messages in thread
From: Nelson, Shannon @ 2025-04-08 21:44 UTC (permalink / raw)
  To: Pranav Tyagi, davem, dsahern, edumazet, kuba, pabeni, horms,
	skhan, netdev, linux-kernel, linux-kernel-mentees

On 4/8/2025 11:57 AM, Pranav Tyagi wrote:
> 
> Replace the deprecated strncpy() function with strscpy_pad() as the
> destination buffer is NUL-terminated and requires
> trailing NUL-padding
> 
> Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>

There should be a Fixes tag here, and usually we put the 'net' tree 
indicator inside the tag, like this: [PATCH net]


> ---
>   net/ipv4/ipconfig.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
> index c56b6fe6f0d7..7c238d19328f 100644
> --- a/net/ipv4/ipconfig.c
> +++ b/net/ipv4/ipconfig.c
> @@ -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_pad(dhcp_client_identifier + 1, v + 1, 251);

The strncpy() action, as well as the memcpy() into 
dhcp_client_identifier elsewhere, are not padding to the end, so I think 
this only needs to be null-terminated, not fully padded.  If full 
padding is needed, please let us know why.

sln

>                          *v = ',';
>                  }
>                  return 1;
> --
> 2.49.0
> 
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: ipconfig: replace strncpy with strscpy_pad
  2025-04-08 21:44 ` Nelson, Shannon
@ 2025-04-10 19:59   ` Pranav Tyagi
  2025-04-10 20:40     ` Nelson, Shannon
  2025-04-10 20:05   ` Simon Horman
  1 sibling, 1 reply; 5+ messages in thread
From: Pranav Tyagi @ 2025-04-10 19:59 UTC (permalink / raw)
  To: Nelson, Shannon
  Cc: davem, dsahern, edumazet, kuba, pabeni, horms, skhan, netdev,
	linux-kernel, linux-kernel-mentees

On Wed, Apr 9, 2025 at 3:14 AM Nelson, Shannon <shannon.nelson@amd.com> wrote:
>
> On 4/8/2025 11:57 AM, Pranav Tyagi wrote:
> >
> > Replace the deprecated strncpy() function with strscpy_pad() as the
> > destination buffer is NUL-terminated and requires
> > trailing NUL-padding
> >
> > Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
>
> There should be a Fixes tag here, and usually we put the 'net' tree
> indicator inside the tag, like this: [PATCH net]
>
>
> > ---
> >   net/ipv4/ipconfig.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
> > index c56b6fe6f0d7..7c238d19328f 100644
> > --- a/net/ipv4/ipconfig.c
> > +++ b/net/ipv4/ipconfig.c
> > @@ -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_pad(dhcp_client_identifier + 1, v + 1, 251);
>
> The strncpy() action, as well as the memcpy() into
> dhcp_client_identifier elsewhere, are not padding to the end, so I think
> this only needs to be null-terminated, not fully padded.  If full
> padding is needed, please let us know why.
>
> sln
>
> >                          *v = ',';
> >                  }
> >                  return 1;
> > --
> > 2.49.0
> >
> >
>

My initial assumption was on the fact that dhcp_client_identifier
is directly used in DHCP packet construction
and may be parsed byte-wise. But on going through the code again
I see that it does not require to be fully padded.
Would strscpy() suffice? as it ensures null-termination and
does not fully pad the buffer.

Regards
Pranav Tyagi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: ipconfig: replace strncpy with strscpy_pad
  2025-04-08 21:44 ` Nelson, Shannon
  2025-04-10 19:59   ` Pranav Tyagi
@ 2025-04-10 20:05   ` Simon Horman
  1 sibling, 0 replies; 5+ messages in thread
From: Simon Horman @ 2025-04-10 20:05 UTC (permalink / raw)
  To: Nelson, Shannon
  Cc: Pranav Tyagi, davem, dsahern, edumazet, kuba, pabeni, skhan,
	netdev, linux-kernel, linux-kernel-mentees

On Tue, Apr 08, 2025 at 02:44:42PM -0700, Nelson, Shannon wrote:
> On 4/8/2025 11:57 AM, Pranav Tyagi wrote:
> > 
> > Replace the deprecated strncpy() function with strscpy_pad() as the
> > destination buffer is NUL-terminated and requires
> > trailing NUL-padding
> > 
> > Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
> 
> There should be a Fixes tag here, and usually we put the 'net' tree
> indicator inside the tag, like this: [PATCH net]

FWIIW, this feels more line net-next material to me:
I'm not seeing a bug that is being fixed.

> 
> 
> > ---
> >   net/ipv4/ipconfig.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
> > index c56b6fe6f0d7..7c238d19328f 100644
> > --- a/net/ipv4/ipconfig.c
> > +++ b/net/ipv4/ipconfig.c
> > @@ -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_pad(dhcp_client_identifier + 1, v + 1, 251);
> 
> The strncpy() action, as well as the memcpy() into dhcp_client_identifier
> elsewhere, are not padding to the end, so I think this only needs to be
> null-terminated, not fully padded.  If full padding is needed, please let
> us know why.
> 
> sln
> 
> >                          *v = ',';
> >                  }
> >                  return 1;
> > --
> > 2.49.0
> > 
> > 
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: ipconfig: replace strncpy with strscpy_pad
  2025-04-10 19:59   ` Pranav Tyagi
@ 2025-04-10 20:40     ` Nelson, Shannon
  0 siblings, 0 replies; 5+ messages in thread
From: Nelson, Shannon @ 2025-04-10 20:40 UTC (permalink / raw)
  To: Pranav Tyagi
  Cc: davem, dsahern, edumazet, kuba, pabeni, horms, skhan, netdev,
	linux-kernel, linux-kernel-mentees

On 4/10/2025 12:59 PM, Pranav Tyagi wrote:
> 
> On Wed, Apr 9, 2025 at 3:14 AM Nelson, Shannon <shannon.nelson@amd.com> wrote:
>>
>> On 4/8/2025 11:57 AM, Pranav Tyagi wrote:
>>>
>>> Replace the deprecated strncpy() function with strscpy_pad() as the
>>> destination buffer is NUL-terminated and requires
>>> trailing NUL-padding
>>>
>>> Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
>>
>> There should be a Fixes tag here, and usually we put the 'net' tree
>> indicator inside the tag, like this: [PATCH net]
>>
>>
>>> ---
>>>    net/ipv4/ipconfig.c | 2 +-
>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
>>> index c56b6fe6f0d7..7c238d19328f 100644
>>> --- a/net/ipv4/ipconfig.c
>>> +++ b/net/ipv4/ipconfig.c
>>> @@ -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_pad(dhcp_client_identifier + 1, v + 1, 251);
>>
>> The strncpy() action, as well as the memcpy() into
>> dhcp_client_identifier elsewhere, are not padding to the end, so I think
>> this only needs to be null-terminated, not fully padded.  If full
>> padding is needed, please let us know why.
>>
>> sln
>>
>>>                           *v = ',';
>>>                   }
>>>                   return 1;
>>> --
>>> 2.49.0
>>>
>>>
>>
> 
> My initial assumption was on the fact that dhcp_client_identifier
> is directly used in DHCP packet construction
> and may be parsed byte-wise. But on going through the code again
> I see that it does not require to be fully padded.
> Would strscpy() suffice? as it ensures null-termination and
> does not fully pad the buffer.

Yes, strscpy() should work.
sln


> 
> Regards
> Pranav Tyagi


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-04-10 20:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-08 18:57 [PATCH] net: ipconfig: replace strncpy with strscpy_pad Pranav Tyagi
2025-04-08 21:44 ` Nelson, Shannon
2025-04-10 19:59   ` Pranav Tyagi
2025-04-10 20:40     ` Nelson, Shannon
2025-04-10 20:05   ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).