* [PATCH 1/2] afs: replace deprecated strcpy with strscpy in afs_lookup_atsys
@ 2026-03-24 15:45 Thorsten Blum
2026-03-24 15:45 ` [PATCH 2/2] afs: replace goto with direct return " Thorsten Blum
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-03-24 15:45 UTC (permalink / raw)
To: David Howells, Marc Dionne; +Cc: Thorsten Blum, linux-afs, linux-kernel
strcpy() has been deprecated [1] because it performs no bounds checking
on the destination buffer, which can lead to buffer overflows. Replace
it with the safer strscpy(), drop the manual length check and the
now-unused local length variable.
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
fs/afs/dir.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 78caef3f1338..89d5c9c354d4 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -9,6 +9,7 @@
#include <linux/fs.h>
#include <linux/namei.h>
#include <linux/pagemap.h>
+#include <linux/string.h>
#include <linux/swap.h>
#include <linux/ctype.h>
#include <linux/sched.h>
@@ -914,7 +915,7 @@ static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry)
struct afs_net *net = afs_i2net(dir);
struct dentry *ret;
char *buf, *p, *name;
- int len, i;
+ int i;
_enter("");
@@ -935,13 +936,11 @@ static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry)
for (i = 0; i < subs->nr; i++) {
name = subs->subs[i];
- len = dentry->d_name.len - 4 + strlen(name);
- if (len >= AFSNAMEMAX) {
+ if (strscpy(p, name, AFSNAMEMAX - (p - buf)) < 0) {
ret = ERR_PTR(-ENAMETOOLONG);
goto out_s;
}
- strcpy(p, name);
ret = lookup_noperm(&QSTR(buf), dentry->d_parent);
if (IS_ERR(ret) || d_is_positive(ret))
goto out_s;
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] afs: replace goto with direct return in afs_lookup_atsys
2026-03-24 15:45 [PATCH 1/2] afs: replace deprecated strcpy with strscpy in afs_lookup_atsys Thorsten Blum
@ 2026-03-24 15:45 ` Thorsten Blum
0 siblings, 0 replies; 2+ messages in thread
From: Thorsten Blum @ 2026-03-24 15:45 UTC (permalink / raw)
To: David Howells, Marc Dionne; +Cc: Thorsten Blum, linux-afs, linux-kernel
Return ERR_PTR(-ENOMEM) directly and remove the obsolete 'out_p' label.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
fs/afs/dir.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 89d5c9c354d4..aec16ceebd94 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -919,10 +919,9 @@ static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry)
_enter("");
- ret = ERR_PTR(-ENOMEM);
p = buf = kmalloc(AFSNAMEMAX, GFP_KERNEL);
if (!buf)
- goto out_p;
+ return ERR_PTR(-ENOMEM);
if (dentry->d_name.len > 4) {
memcpy(p, dentry->d_name.name, dentry->d_name.len - 4);
p += dentry->d_name.len - 4;
@@ -954,7 +953,6 @@ static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry)
out_s:
afs_put_sysnames(subs);
kfree(buf);
-out_p:
return ret;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-24 15:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-24 15:45 [PATCH 1/2] afs: replace deprecated strcpy with strscpy in afs_lookup_atsys Thorsten Blum
2026-03-24 15:45 ` [PATCH 2/2] afs: replace goto with direct return " Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox