* [PATCH] nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy
@ 2024-11-06 2:49 Daniel Yang
2024-11-06 19:30 ` Benjamin Coddington
2024-11-06 20:20 ` Roland Mainz
0 siblings, 2 replies; 7+ messages in thread
From: Daniel Yang @ 2024-11-06 2:49 UTC (permalink / raw)
To: Trond Myklebust, Anna Schumaker,
open list:NFS, SUNRPC, AND LOCKD CLIENTS, open list
Cc: Daniel Yang
The function strcpy is deprecated due to lack of bounds checking. The
recommended replacement is strscpy.
Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
---
fs/nfs/sysfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
index bf378ecd5..f3d0b2ef9 100644
--- a/fs/nfs/sysfs.c
+++ b/fs/nfs/sysfs.c
@@ -280,7 +280,7 @@ void nfs_sysfs_link_rpc_client(struct nfs_server *server,
char name[RPC_CLIENT_NAME_SIZE];
int ret;
- strcpy(name, clnt->cl_program->name);
+ strscpy(name, clnt->cl_program->name);
strcat(name, uniq ? uniq : "");
strcat(name, "_client");
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy
2024-11-06 2:49 [PATCH] nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy Daniel Yang
@ 2024-11-06 19:30 ` Benjamin Coddington
2024-11-06 20:20 ` Roland Mainz
1 sibling, 0 replies; 7+ messages in thread
From: Benjamin Coddington @ 2024-11-06 19:30 UTC (permalink / raw)
To: Daniel Yang
Cc: Trond Myklebust, Anna Schumaker, open list:NFS,
SUNRPC, AND LOCKD CLIENTS),
On 5 Nov 2024, at 21:49, Daniel Yang wrote:
> The function strcpy is deprecated due to lack of bounds checking. The
> recommended replacement is strscpy.
>
> Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
Reviewed-by: Benjamin Coddington <bcodding@redhat.com>
Ben
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy
2024-11-06 2:49 [PATCH] nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy Daniel Yang
2024-11-06 19:30 ` Benjamin Coddington
@ 2024-11-06 20:20 ` Roland Mainz
2024-11-06 20:40 ` Benjamin Coddington
1 sibling, 1 reply; 7+ messages in thread
From: Roland Mainz @ 2024-11-06 20:20 UTC (permalink / raw)
To: open list, Linux NFS Mailing List
On Wed, Nov 6, 2024 at 3:49 AM Daniel Yang <danielyangkang@gmail.com> wrote:
>
> The function strcpy is deprecated due to lack of bounds checking. The
> recommended replacement is strscpy.
>
> Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
> ---
> fs/nfs/sysfs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
> index bf378ecd5..f3d0b2ef9 100644
> --- a/fs/nfs/sysfs.c
> +++ b/fs/nfs/sysfs.c
> @@ -280,7 +280,7 @@ void nfs_sysfs_link_rpc_client(struct nfs_server *server,
> char name[RPC_CLIENT_NAME_SIZE];
> int ret;
>
> - strcpy(name, clnt->cl_program->name);
> + strscpy(name, clnt->cl_program->name);
How should the "bounds checking" work in this case if you only pass
two arguments ?
Per https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html
|strscpy()| takes three arguments...
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz@nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy
2024-11-06 20:20 ` Roland Mainz
@ 2024-11-06 20:40 ` Benjamin Coddington
2024-11-09 11:11 ` Kernel strscpy() should be renamed to kstrscpy() " Sebastian Feld
0 siblings, 1 reply; 7+ messages in thread
From: Benjamin Coddington @ 2024-11-06 20:40 UTC (permalink / raw)
To: Roland Mainz; +Cc: open list, Linux NFS Mailing List
On 6 Nov 2024, at 15:20, Roland Mainz wrote:
> On Wed, Nov 6, 2024 at 3:49 AM Daniel Yang <danielyangkang@gmail.com> wrote:
>>
>> The function strcpy is deprecated due to lack of bounds checking. The
>> recommended replacement is strscpy.
>>
>> Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
>> ---
>> fs/nfs/sysfs.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
>> index bf378ecd5..f3d0b2ef9 100644
>> --- a/fs/nfs/sysfs.c
>> +++ b/fs/nfs/sysfs.c
>> @@ -280,7 +280,7 @@ void nfs_sysfs_link_rpc_client(struct nfs_server *server,
>> char name[RPC_CLIENT_NAME_SIZE];
>> int ret;
>>
>> - strcpy(name, clnt->cl_program->name);
>> + strscpy(name, clnt->cl_program->name);
>
> How should the "bounds checking" work in this case if you only pass
> two arguments ?
The linux kernel strscpy() checks the sizeof the destination.
Ben
^ permalink raw reply [flat|nested] 7+ messages in thread
* Kernel strscpy() should be renamed to kstrscpy() Re: [PATCH] nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy
2024-11-06 20:40 ` Benjamin Coddington
@ 2024-11-09 11:11 ` Sebastian Feld
2024-11-09 11:28 ` Benjamin Coddington
2024-11-09 12:01 ` Theodore Ts'o
0 siblings, 2 replies; 7+ messages in thread
From: Sebastian Feld @ 2024-11-09 11:11 UTC (permalink / raw)
To: open list, Linux NFS Mailing List
On Wed, Nov 6, 2024 at 9:40 PM Benjamin Coddington <bcodding@redhat.com> wrote:
>
> On 6 Nov 2024, at 15:20, Roland Mainz wrote:
>
> > On Wed, Nov 6, 2024 at 3:49 AM Daniel Yang <danielyangkang@gmail.com> wrote:
> >>
> >> The function strcpy is deprecated due to lack of bounds checking. The
> >> recommended replacement is strscpy.
> >>
> >> Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
> >> ---
> >> fs/nfs/sysfs.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
> >> index bf378ecd5..f3d0b2ef9 100644
> >> --- a/fs/nfs/sysfs.c
> >> +++ b/fs/nfs/sysfs.c
> >> @@ -280,7 +280,7 @@ void nfs_sysfs_link_rpc_client(struct nfs_server *server,
> >> char name[RPC_CLIENT_NAME_SIZE];
> >> int ret;
> >>
> >> - strcpy(name, clnt->cl_program->name);
> >> + strscpy(name, clnt->cl_program->name);
> >
> > How should the "bounds checking" work in this case if you only pass
> > two arguments ?
>
> The linux kernel strscpy() checks the sizeof the destination.
Then the kernel strscpy() should be renamed accordingly, and not
confuse people. Suggested name would be kstrscpy().
Otherwise this would disqualify strscpy() ever from being adopted as a
POSIX standard, as there are two - kernel and glibc - conflicting
implementations
Sebi
--
Sebastian Feld - IT secruity expert
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Kernel strscpy() should be renamed to kstrscpy() Re: [PATCH] nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy
2024-11-09 11:11 ` Kernel strscpy() should be renamed to kstrscpy() " Sebastian Feld
@ 2024-11-09 11:28 ` Benjamin Coddington
2024-11-09 12:01 ` Theodore Ts'o
1 sibling, 0 replies; 7+ messages in thread
From: Benjamin Coddington @ 2024-11-09 11:28 UTC (permalink / raw)
To: Sebastian Feld; +Cc: open list, Linux NFS Mailing List
On 9 Nov 2024, at 6:11, Sebastian Feld wrote:
> On Wed, Nov 6, 2024 at 9:40 PM Benjamin Coddington <bcodding@redhat.com> wrote:
>>
>> On 6 Nov 2024, at 15:20, Roland Mainz wrote:
>>
>>> On Wed, Nov 6, 2024 at 3:49 AM Daniel Yang <danielyangkang@gmail.com> wrote:
>>>>
>>>> The function strcpy is deprecated due to lack of bounds checking. The
>>>> recommended replacement is strscpy.
>>>>
>>>> Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
>>>> ---
>>>> fs/nfs/sysfs.c | 2 +-
>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
>>>> index bf378ecd5..f3d0b2ef9 100644
>>>> --- a/fs/nfs/sysfs.c
>>>> +++ b/fs/nfs/sysfs.c
>>>> @@ -280,7 +280,7 @@ void nfs_sysfs_link_rpc_client(struct nfs_server *server,
>>>> char name[RPC_CLIENT_NAME_SIZE];
>>>> int ret;
>>>>
>>>> - strcpy(name, clnt->cl_program->name);
>>>> + strscpy(name, clnt->cl_program->name);
>>>
>>> How should the "bounds checking" work in this case if you only pass
>>> two arguments ?
>>
>> The linux kernel strscpy() checks the sizeof the destination.
>
> Then the kernel strscpy() should be renamed accordingly, and not
> confuse people. Suggested name would be kstrscpy().
> Otherwise this would disqualify strscpy() ever from being adopted as a
> POSIX standard, as there are two - kernel and glibc - conflicting
> implementations
I should have said the linux kernel strscpy() can accept only two args if
the destination is a statically-defined array. Most uses are the three arg
version.
Ben
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Kernel strscpy() should be renamed to kstrscpy() Re: [PATCH] nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy
2024-11-09 11:11 ` Kernel strscpy() should be renamed to kstrscpy() " Sebastian Feld
2024-11-09 11:28 ` Benjamin Coddington
@ 2024-11-09 12:01 ` Theodore Ts'o
1 sibling, 0 replies; 7+ messages in thread
From: Theodore Ts'o @ 2024-11-09 12:01 UTC (permalink / raw)
To: Sebastian Feld; +Cc: open list, Linux NFS Mailing List
On Sat, Nov 09, 2024 at 12:11:02PM +0100, Sebastian Feld wrote:
> > > How should the "bounds checking" work in this case if you only pass
> > > two arguments ?
> >
> > The linux kernel strscpy() checks the sizeof the destination.
>
> Then the kernel strscpy() should be renamed accordingly, and not
> confuse people. Suggested name would be kstrscpy().
> Otherwise this would disqualify strscpy() ever from being adopted as a
> POSIX standard, as there are two - kernel and glibc - conflicting
> implementations
If POSIX decided that this meant they couldn't adopt strscpy(), that
is ANSI / ISO's problem, not ours. Note that strscpy() supports the 3
argument version of glibc, and POSIX has always been willing to
standardize a subset of a particullar interface.
Otherwise, any Legacy Unix system which added some one or more flags
to some particular interface could potentially disqualify anything
with the same name of that interface from ever being standardized,
which is (a) stupid, and (b) not what has been done in historical
practice.
- Ted
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-11-09 12:02 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-06 2:49 [PATCH] nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy Daniel Yang
2024-11-06 19:30 ` Benjamin Coddington
2024-11-06 20:20 ` Roland Mainz
2024-11-06 20:40 ` Benjamin Coddington
2024-11-09 11:11 ` Kernel strscpy() should be renamed to kstrscpy() " Sebastian Feld
2024-11-09 11:28 ` Benjamin Coddington
2024-11-09 12:01 ` Theodore Ts'o
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox