* [PATCH] net/smc: replace strncpy with strscpy for ib_name
@ 2025-09-08 18:09 Kriish Sharma
2025-09-09 3:23 ` Dust Li
2025-09-10 10:01 ` Leon Romanovsky
0 siblings, 2 replies; 8+ messages in thread
From: Kriish Sharma @ 2025-09-08 18:09 UTC (permalink / raw)
To: alibuda, dust.li, sidraya, wenjia
Cc: mjambigi, tonylu, guwen, davem, edumazet, kuba, pabeni, horms,
linux-rdma, linux-s390, netdev, linux-kernel, skhan,
linux-kernel-mentees, kriish.sharma2006
Replace the deprecated strncpy() with strscpy() for ib_name in
smc_pnet_add_ib(). The destination buffer should be NUL-terminated and
does not require any trailing NUL-padding. Since ib_name is a fixed-size
array, the two-argument form of strscpy() is sufficient and preferred.
Signed-off-by: Kriish Sharma <kriish.sharma2006@gmail.com>
---
net/smc/smc_pnet.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c
index 76ad29e31d60..b90337f86e83 100644
--- a/net/smc/smc_pnet.c
+++ b/net/smc/smc_pnet.c
@@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
return -ENOMEM;
new_pe->type = SMC_PNET_IB;
memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
- strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
+ strscpy(new_pe->ib_name, ib_name);
new_pe->ib_port = ib_port;
new_ibdev = true;
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] net/smc: replace strncpy with strscpy for ib_name
2025-09-08 18:09 [PATCH] net/smc: replace strncpy with strscpy for ib_name Kriish Sharma
@ 2025-09-09 3:23 ` Dust Li
2025-09-10 10:01 ` Leon Romanovsky
1 sibling, 0 replies; 8+ messages in thread
From: Dust Li @ 2025-09-09 3:23 UTC (permalink / raw)
To: Kriish Sharma, alibuda, sidraya, wenjia
Cc: mjambigi, tonylu, guwen, davem, edumazet, kuba, pabeni, horms,
linux-rdma, linux-s390, netdev, linux-kernel, skhan,
linux-kernel-mentees
On 2025-09-08 18:09:13, Kriish Sharma wrote:
>Replace the deprecated strncpy() with strscpy() for ib_name in
>smc_pnet_add_ib(). The destination buffer should be NUL-terminated and
>does not require any trailing NUL-padding. Since ib_name is a fixed-size
>array, the two-argument form of strscpy() is sufficient and preferred.
>
>Signed-off-by: Kriish Sharma <kriish.sharma2006@gmail.com>
I think d250f14f5f0754ce2d05d9c0ce778e4a51f488b0 has already done the
same thing.
Best regards,
Dust
>---
> net/smc/smc_pnet.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c
>index 76ad29e31d60..b90337f86e83 100644
>--- a/net/smc/smc_pnet.c
>+++ b/net/smc/smc_pnet.c
>@@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
> return -ENOMEM;
> new_pe->type = SMC_PNET_IB;
> memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
>- strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
>+ strscpy(new_pe->ib_name, ib_name);
> new_pe->ib_port = ib_port;
>
> new_ibdev = true;
>--
>2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net/smc: replace strncpy with strscpy for ib_name
2025-09-08 18:09 [PATCH] net/smc: replace strncpy with strscpy for ib_name Kriish Sharma
2025-09-09 3:23 ` Dust Li
@ 2025-09-10 10:01 ` Leon Romanovsky
2025-09-12 7:48 ` Mahanta Jambigi
1 sibling, 1 reply; 8+ messages in thread
From: Leon Romanovsky @ 2025-09-10 10:01 UTC (permalink / raw)
To: Kriish Sharma
Cc: alibuda, dust.li, sidraya, wenjia, mjambigi, tonylu, guwen, davem,
edumazet, kuba, pabeni, horms, linux-rdma, linux-s390, netdev,
linux-kernel, skhan, linux-kernel-mentees
On Mon, Sep 08, 2025 at 06:09:13PM +0000, Kriish Sharma wrote:
> Replace the deprecated strncpy() with strscpy() for ib_name in
> smc_pnet_add_ib(). The destination buffer should be NUL-terminated and
> does not require any trailing NUL-padding. Since ib_name is a fixed-size
> array, the two-argument form of strscpy() is sufficient and preferred.
>
> Signed-off-by: Kriish Sharma <kriish.sharma2006@gmail.com>
> ---
> net/smc/smc_pnet.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c
> index 76ad29e31d60..b90337f86e83 100644
> --- a/net/smc/smc_pnet.c
> +++ b/net/smc/smc_pnet.c
> @@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
> return -ENOMEM;
> new_pe->type = SMC_PNET_IB;
> memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
> - strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
> + strscpy(new_pe->ib_name, ib_name);
It is worth to mention that caching ib_name is wrong as IB/core provides
IB device rename functionality.
Thanks
> new_pe->ib_port = ib_port;
>
> new_ibdev = true;
> --
> 2.34.1
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net/smc: replace strncpy with strscpy for ib_name
2025-09-10 10:01 ` Leon Romanovsky
@ 2025-09-12 7:48 ` Mahanta Jambigi
2025-09-12 9:07 ` Leon Romanovsky
0 siblings, 1 reply; 8+ messages in thread
From: Mahanta Jambigi @ 2025-09-12 7:48 UTC (permalink / raw)
To: Leon Romanovsky, Kriish Sharma
Cc: alibuda, dust.li, sidraya, wenjia, tonylu, guwen, davem, edumazet,
kuba, pabeni, horms, linux-rdma, linux-s390, netdev, linux-kernel,
skhan, linux-kernel-mentees
On 10/09/25 3:31 pm, Leon Romanovsky wrote:
>> --- a/net/smc/smc_pnet.c
>> +++ b/net/smc/smc_pnet.c
>> @@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
>> return -ENOMEM;
>> new_pe->type = SMC_PNET_IB;
>> memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
>> - strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
>> + strscpy(new_pe->ib_name, ib_name);
>
> It is worth to mention that caching ib_name is wrong as IB/core provides
> IB device rename functionality.
In our case we hit this code path where we pass *PCI_ID*
as the *ib_name* using *smc_pnet* tool(smc_pnet -a <pnet_name> -D
<PCI_ID>). I believe PCI_ID will not change, so caching it here is fine.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net/smc: replace strncpy with strscpy for ib_name
2025-09-12 7:48 ` Mahanta Jambigi
@ 2025-09-12 9:07 ` Leon Romanovsky
2025-09-15 6:54 ` Mahanta Jambigi
0 siblings, 1 reply; 8+ messages in thread
From: Leon Romanovsky @ 2025-09-12 9:07 UTC (permalink / raw)
To: Mahanta Jambigi
Cc: Kriish Sharma, alibuda, dust.li, sidraya, wenjia, tonylu, guwen,
davem, edumazet, kuba, pabeni, horms, linux-rdma, linux-s390,
netdev, linux-kernel, skhan, linux-kernel-mentees
On Fri, Sep 12, 2025 at 01:18:52PM +0530, Mahanta Jambigi wrote:
> On 10/09/25 3:31 pm, Leon Romanovsky wrote:
> >> --- a/net/smc/smc_pnet.c
> >> +++ b/net/smc/smc_pnet.c
> >> @@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
> >> return -ENOMEM;
> >> new_pe->type = SMC_PNET_IB;
> >> memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
> >> - strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
> >> + strscpy(new_pe->ib_name, ib_name);
> >
> > It is worth to mention that caching ib_name is wrong as IB/core provides
> > IB device rename functionality.
>
> In our case we hit this code path where we pass *PCI_ID*
> as the *ib_name* using *smc_pnet* tool(smc_pnet -a <pnet_name> -D
> <PCI_ID>). I believe PCI_ID will not change, so caching it here is fine.
If I remember, you are reporting that cached ib_name through netlink much later.
The caching itself is not an issue, but incorrect reported name can be seen as
a wrong thing to do.
Thanks
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net/smc: replace strncpy with strscpy for ib_name
2025-09-12 9:07 ` Leon Romanovsky
@ 2025-09-15 6:54 ` Mahanta Jambigi
2025-09-15 8:02 ` Leon Romanovsky
0 siblings, 1 reply; 8+ messages in thread
From: Mahanta Jambigi @ 2025-09-15 6:54 UTC (permalink / raw)
To: Leon Romanovsky
Cc: Kriish Sharma, alibuda, dust.li, sidraya, wenjia, tonylu, guwen,
davem, edumazet, kuba, pabeni, horms, linux-rdma, linux-s390,
netdev, linux-kernel, skhan, linux-kernel-mentees
On 12/09/25 2:37 pm, Leon Romanovsky wrote:
> On Fri, Sep 12, 2025 at 01:18:52PM +0530, Mahanta Jambigi wrote:
>> On 10/09/25 3:31 pm, Leon Romanovsky wrote:
>>>> --- a/net/smc/smc_pnet.c
>>>> +++ b/net/smc/smc_pnet.c
>>>> @@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
>>>> return -ENOMEM;
>>>> new_pe->type = SMC_PNET_IB;
>>>> memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
>>>> - strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
>>>> + strscpy(new_pe->ib_name, ib_name);
>>>
>>> It is worth to mention that caching ib_name is wrong as IB/core provides
>>> IB device rename functionality.
>>
>> In our case we hit this code path where we pass *PCI_ID*
>> as the *ib_name* using *smc_pnet* tool(smc_pnet -a <pnet_name> -D
>> <PCI_ID>). I believe PCI_ID will not change, so caching it here is fine.
>
> If I remember, you are reporting that cached ib_name through netlink much later.
>
> The caching itself is not an issue, but incorrect reported name can be seen as
> a wrong thing to do.
In what case we can see this incorrect reported name, could you please
elaborate.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net/smc: replace strncpy with strscpy for ib_name
2025-09-15 6:54 ` Mahanta Jambigi
@ 2025-09-15 8:02 ` Leon Romanovsky
2025-09-15 9:44 ` Mahanta Jambigi
0 siblings, 1 reply; 8+ messages in thread
From: Leon Romanovsky @ 2025-09-15 8:02 UTC (permalink / raw)
To: Mahanta Jambigi
Cc: Kriish Sharma, alibuda, dust.li, sidraya, wenjia, tonylu, guwen,
davem, edumazet, kuba, pabeni, horms, linux-rdma, linux-s390,
netdev, linux-kernel, skhan, linux-kernel-mentees
On Mon, Sep 15, 2025 at 12:24:16PM +0530, Mahanta Jambigi wrote:
> On 12/09/25 2:37 pm, Leon Romanovsky wrote:
> > On Fri, Sep 12, 2025 at 01:18:52PM +0530, Mahanta Jambigi wrote:
> >> On 10/09/25 3:31 pm, Leon Romanovsky wrote:
> >>>> --- a/net/smc/smc_pnet.c
> >>>> +++ b/net/smc/smc_pnet.c
> >>>> @@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
> >>>> return -ENOMEM;
> >>>> new_pe->type = SMC_PNET_IB;
> >>>> memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
> >>>> - strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
> >>>> + strscpy(new_pe->ib_name, ib_name);
> >>>
> >>> It is worth to mention that caching ib_name is wrong as IB/core provides
> >>> IB device rename functionality.
> >>
> >> In our case we hit this code path where we pass *PCI_ID*
> >> as the *ib_name* using *smc_pnet* tool(smc_pnet -a <pnet_name> -D
> >> <PCI_ID>). I believe PCI_ID will not change, so caching it here is fine.
> >
> > If I remember, you are reporting that cached ib_name through netlink much later.
> >
> > The caching itself is not an issue, but incorrect reported name can be seen as
> > a wrong thing to do.
>
> In what case we can see this incorrect reported name, could you please
> elaborate.
Did you open net/smc/smc_pnet.c?
Everything that uses ib_name in that file is incorrect.
From glance look:
1. smc_pnet_find_ib() returns completely random results if device is
renamed in parallel.
2. SMC_PNETID_GET returns wrong names. It returns cached name which
doesn't exist anymore.
IB devices have stable indexes in similar way to netdevice. The code
should rely on it and not on the name.
Thanks
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net/smc: replace strncpy with strscpy for ib_name
2025-09-15 8:02 ` Leon Romanovsky
@ 2025-09-15 9:44 ` Mahanta Jambigi
0 siblings, 0 replies; 8+ messages in thread
From: Mahanta Jambigi @ 2025-09-15 9:44 UTC (permalink / raw)
To: Leon Romanovsky
Cc: Kriish Sharma, alibuda, dust.li, sidraya, wenjia, tonylu, guwen,
davem, edumazet, kuba, pabeni, horms, linux-rdma, linux-s390,
netdev, linux-kernel, skhan, linux-kernel-mentees
On 15/09/25 1:32 pm, Leon Romanovsky wrote:
> On Mon, Sep 15, 2025 at 12:24:16PM +0530, Mahanta Jambigi wrote:
>> On 12/09/25 2:37 pm, Leon Romanovsky wrote:
>>> On Fri, Sep 12, 2025 at 01:18:52PM +0530, Mahanta Jambigi wrote:
>>>> On 10/09/25 3:31 pm, Leon Romanovsky wrote:
>>>>>> --- a/net/smc/smc_pnet.c
>>>>>> +++ b/net/smc/smc_pnet.c
>>>>>> @@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
>>>>>> return -ENOMEM;
>>>>>> new_pe->type = SMC_PNET_IB;
>>>>>> memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
>>>>>> - strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
>>>>>> + strscpy(new_pe->ib_name, ib_name);
>>>>>
>>>>> It is worth to mention that caching ib_name is wrong as IB/core provides
>>>>> IB device rename functionality.
>>>>
>>>> In our case we hit this code path where we pass *PCI_ID*
>>>> as the *ib_name* using *smc_pnet* tool(smc_pnet -a <pnet_name> -D
>>>> <PCI_ID>). I believe PCI_ID will not change, so caching it here is fine.
>>>
>>> If I remember, you are reporting that cached ib_name through netlink much later.
>>>
>>> The caching itself is not an issue, but incorrect reported name can be seen as
>>> a wrong thing to do.
>>
>> In what case we can see this incorrect reported name, could you please
>> elaborate.
>
> Did you open net/smc/smc_pnet.c?
Yes, I have gone through it focusing on *ib_name* usage.
>
> Everything that uses ib_name in that file is incorrect.
>
> From glance look:
> 1. smc_pnet_find_ib() returns completely random results if device is
> renamed in parallel.
I agree. Currently we are *not* handling the change of IB device names &
when that happens the cached *ib_name* doesn't match anymore with the
changed ib_name. We are looking into this internally.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-09-15 9:44 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-08 18:09 [PATCH] net/smc: replace strncpy with strscpy for ib_name Kriish Sharma
2025-09-09 3:23 ` Dust Li
2025-09-10 10:01 ` Leon Romanovsky
2025-09-12 7:48 ` Mahanta Jambigi
2025-09-12 9:07 ` Leon Romanovsky
2025-09-15 6:54 ` Mahanta Jambigi
2025-09-15 8:02 ` Leon Romanovsky
2025-09-15 9:44 ` Mahanta Jambigi
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 read-only IMAP folder(s) and NNTP newsgroup(s).