From: Thorsten Blum <thorsten.blum@linux.dev>
To: David Howells <dhowells@redhat.com>,
Marc Dionne <marc.dionne@auristor.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] afs: replace deprecated strcpy with strscpy in afs_lookup_atsys
Date: Tue, 24 Mar 2026 16:45:16 +0100 [thread overview]
Message-ID: <20260324154515.205796-4-thorsten.blum@linux.dev> (raw)
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;
next reply other threads:[~2026-03-24 15:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-24 15:45 Thorsten Blum [this message]
2026-03-24 15:45 ` [PATCH 2/2] afs: replace goto with direct return in afs_lookup_atsys Thorsten Blum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260324154515.205796-4-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=dhowells@redhat.com \
--cc=linux-afs@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.dionne@auristor.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox