6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chuck Lever commit e27c63245903402ccfdb46c576462981a7e032e3 upstream. 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 Fixes: eed2965af1ba ("[PATCH] knfsd: allow admin to set nthreads per node") Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260812193349.13347-1-david.laight.linux@gmail.com Signed-off-by: Chuck Lever Signed-off-by: Greg Kroah-Hartman --- fs/nfsd/nfsctl.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -471,7 +471,7 @@ static ssize_t write_pool_threads(struct char *mesg = buf; int i; int rv; - int len; + size_t len; int npools; int *nthreads; struct net *net = netns(file); @@ -525,9 +525,13 @@ static ssize_t write_pool_threads(struct 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; }