From: Gax-c <zichenxie0106@gmail.com>
To: trondmy@kernel.org, anna@kernel.org, bcodding@redhat.com
Cc: linux-nfs@vger.kernel.org, chenyuan0y@gmail.com,
zzjas98@gmail.com, Zichen Xie <zichenxie0106@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] NFS: Fix potential buffer overflowin nfs_sysfs_link_rpc_client()
Date: Wed, 18 Dec 2024 00:13:12 +0800 [thread overview]
Message-ID: <20241217161311.28640-1-zichenxie0106@gmail.com> (raw)
From: Zichen Xie <zichenxie0106@gmail.com>
name is char[64] where the size of clnt->cl_program->name remains
unknown. Invoking strcat() directly will also lead to potential buffer
overflow. Change them to strscpy() and strncat() to fix potential
issues.
Fixes: e13b549319a6 ("NFS: Add sysfs links to sunrpc clients for nfs_clients")
Signed-off-by: Zichen Xie <zichenxie0106@gmail.com>
Cc: stable@vger.kernel.org
---
fs/nfs/sysfs.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
index bf378ecd5d9f..7b59a40d40c0 100644
--- a/fs/nfs/sysfs.c
+++ b/fs/nfs/sysfs.c
@@ -280,9 +280,9 @@ void nfs_sysfs_link_rpc_client(struct nfs_server *server,
char name[RPC_CLIENT_NAME_SIZE];
int ret;
- strcpy(name, clnt->cl_program->name);
- strcat(name, uniq ? uniq : "");
- strcat(name, "_client");
+ strscpy(name, clnt->cl_program->name, sizeof(name));
+ strncat(name, uniq ? uniq : "", sizeof(name) - strlen(name) - 1);
+ strncat(name, "_client", sizeof(name) - strlen(name) - 1);
ret = sysfs_create_link_nowarn(&server->kobj,
&clnt->cl_sysfs->kobject, name);
--
2.25.1
next reply other threads:[~2024-12-17 16:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-17 16:13 Gax-c [this message]
2024-12-17 16:51 ` [PATCH] NFS: Fix potential buffer overflowin nfs_sysfs_link_rpc_client() Trond Myklebust
2024-12-17 17:07 ` Trond Myklebust
2024-12-18 14:28 ` Benjamin Coddington
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=20241217161311.28640-1-zichenxie0106@gmail.com \
--to=zichenxie0106@gmail.com \
--cc=anna@kernel.org \
--cc=bcodding@redhat.com \
--cc=chenyuan0y@gmail.com \
--cc=linux-nfs@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=trondmy@kernel.org \
--cc=zzjas98@gmail.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