* [PATCH net-next] net/sunrpc/svcauth_unix: Use strscpy() to copy strings into arrays
@ 2026-06-08 9:55 david.laight.linux
2026-06-09 0:33 ` Chuck Lever
0 siblings, 1 reply; 2+ messages in thread
From: david.laight.linux @ 2026-06-08 9:55 UTC (permalink / raw)
To: Kees Cook, linux-hardening, linux-kernel, linux-nfs, netdev
Cc: Arnd Bergmann, Anna Schumaker, Chuck Lever, David S. Miller,
Eric Dumazet, Jakub Kicinski, Jeff Layton, Paolo Abeni,
Trond Myklebust, David Laight
From: David Laight <david.laight.linux@gmail•com>
Replacing strcpy() with strscpy() ensures that overflow of the target
buffer cannot happen.
Signed-off-by: David Laight <david.laight.linux@gmail•com>
---
This is one of a group of patches that remove potentially unbounded
strcpy() calls.
They are mostly replaced by strscpy() or, when strlen() has just been
called, with memcpy() (usually including the '\0').
Calls with copy string literals into arrays are left unchanged.
They are safe and easily detected as such.
The changes were made by getting the compiler to detect the calls and
then fixing the code by hand.
Note that all the changes are only compile tested.
Some Makefiles were changed to allow files to contain strcpy().
As well as 'difficult to fix' files, this included 'show' functions
as they really need to use sysfs_emit() or seq_printf().
All the patches are being sent individually to avoid very long cc lists.
Apologies for the terse commit messages and likely unexpected tags.
(There are about 100 patches in total.)
net/sunrpc/svcauth_unix.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 3be69c145d2a..71efec9618f5 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -130,7 +130,7 @@ static void ip_map_init(struct cache_head *cnew, struct cache_head *citem)
struct ip_map *new = container_of(cnew, struct ip_map, h);
struct ip_map *item = container_of(citem, struct ip_map, h);
- strcpy(new->m_class, item->m_class);
+ strscpy(new->m_class, item->m_class);
new->m_addr = item->m_addr;
}
static void update(struct cache_head *cnew, struct cache_head *citem)
@@ -293,7 +293,7 @@ static struct ip_map *__ip_map_lookup(struct cache_detail *cd, char *class,
struct ip_map ip;
struct cache_head *ch;
- strcpy(ip.m_class, class);
+ strscpy(ip.m_class, class);
ip.m_addr = *addr;
ch = sunrpc_cache_lookup_rcu(cd, &ip.h,
hash_str(class, IP_HASHBITS) ^
--
2.39.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] net/sunrpc/svcauth_unix: Use strscpy() to copy strings into arrays
2026-06-08 9:55 [PATCH net-next] net/sunrpc/svcauth_unix: Use strscpy() to copy strings into arrays david.laight.linux
@ 2026-06-09 0:33 ` Chuck Lever
0 siblings, 0 replies; 2+ messages in thread
From: Chuck Lever @ 2026-06-09 0:33 UTC (permalink / raw)
To: Kees Cook, linux-hardening, linux-kernel, linux-nfs, netdev,
david.laight.linux
Cc: Chuck Lever, Arnd Bergmann, Anna Schumaker, David S. Miller,
Eric Dumazet, Jakub Kicinski, Jeff Layton, Paolo Abeni,
Trond Myklebust
From: Chuck Lever <chuck.lever@oracle•com>
On Mon, 08 Jun 2026 10:55:00 +0100, david.laight.linux@gmail•com wrote:
> Replacing strcpy() with strscpy() ensures that overflow of the target
> buffer cannot happen.
Applied to nfsd-testing, thanks!
[1/1] net/sunrpc/svcauth_unix: Use strscpy() to copy strings into arrays
commit: cea9ba4f71e82766d782ed423c99bb12a69bbdf0
--
Chuck Lever <chuck.lever@oracle•com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-09 0:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-08 9:55 [PATCH net-next] net/sunrpc/svcauth_unix: Use strscpy() to copy strings into arrays david.laight.linux
2026-06-09 0:33 ` Chuck Lever
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox