* [PATCH v1] NFSD: Fail a pool_threads read whose reply does not fit
@ 2026-08-16 17:41 Chuck Lever
0 siblings, 0 replies; only message in thread
From: Chuck Lever @ 2026-08-16 17:41 UTC (permalink / raw)
To: NeilBrown, Jeff Layton, Olga Kornievskaia, Dai Ngo, Tom Talpey
Cc: linux-nfs, David Laight
The reply to a pool_threads read is the list of per-pool thread counts,
formatted into a buffer of SIMPLE_TRANSACTION_LIMIT bytes. snprintf()
truncates its last write and strlen() measures only what fit, so a reply
too long for that buffer ends mid-number with no terminating newline. A
pool running 4096 threads is reported as 40. Nothing marks the reply as
incomplete, so an administrator reads a plausible but wrong count.
Take snprintf()'s return value, which reports the truncation strlen()
cannot see, and fail the read with -ENAMETOOLONG when the list does
not fit. That is the errno svc_one_xprt_name() already returns for the
same condition.
Suggested-by: David Laight <david.laight.linux@gmail.com>
Fixes: eed2965af1ba ("[PATCH] knfsd: allow admin to set nthreads per node")
Link: https://patch.msgid.link/20260812193349.13347-1-david.laight.linux@gmail.com
Signed-off-by: Chuck Lever <cel@kernel.org>
---
fs/nfsd/nfsctl.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index 4e5e083d8477..f9fd6df57b79 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -479,7 +479,7 @@ static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
char *mesg = buf;
int i;
int rv;
- int len;
+ size_t len;
int npools;
int *nthreads;
struct net *net = netns(file);
@@ -533,9 +533,13 @@ static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
mesg = buf;
size = SIMPLE_TRANSACTION_LIMIT;
- for (i = 0; i < npools && size > 0; i++) {
- snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
- len = strlen(mesg);
+ for (i = 0; i < npools; i++) {
+ len = snprintf(mesg, size, "%d%c", nthreads[i],
+ (i == npools - 1 ? '\n' : ' '));
+ if (len >= size) {
+ rv = -ENAMETOOLONG;
+ goto out_free;
+ }
size -= len;
mesg += len;
}
--
2.54.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-08-16 17:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-16 17:41 [PATCH v1] NFSD: Fail a pool_threads read whose reply does not fit Chuck Lever
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox