]> www.infradead.org Git - users/hch/misc.git/commitdiff
NFSD: Fix destination buffer size in nfsd4_ssc_setup_dul()
authorThorsten Blum <thorsten.blum@linux.dev>
Wed, 6 Aug 2025 01:10:01 +0000 (03:10 +0200)
committerChuck Lever <chuck.lever@oracle.com>
Sun, 21 Sep 2025 23:24:50 +0000 (19:24 -0400)
Commit 5304877936c0 ("NFSD: Fix strncpy() fortify warning") replaced
strncpy(,, sizeof(..)) with strlcpy(,, sizeof(..) - 1), but strlcpy()
already guaranteed NUL-termination of the destination buffer and
subtracting one byte potentially truncated the source string.

The incorrect size was then carried over in commit 72f78ae00a8e ("NFSD:
move from strlcpy with unused retval to strscpy") when switching from
strlcpy() to strscpy().

Fix this off-by-one error by using the full size of the destination
buffer again.

Cc: stable@vger.kernel.org
Fixes: 5304877936c0 ("NFSD: Fix strncpy() fortify warning")
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfsd/nfs4proc.c

index bfebe6e25638a76d3607bb79a239bdc92e42e7b5..d7c58aa64f06e8f15295bb5e4bf460beed5b422c 100644 (file)
@@ -1519,7 +1519,7 @@ try_again:
                return 0;
        }
        if (work) {
-               strscpy(work->nsui_ipaddr, ipaddr, sizeof(work->nsui_ipaddr) - 1);
+               strscpy(work->nsui_ipaddr, ipaddr, sizeof(work->nsui_ipaddr));
                refcount_set(&work->nsui_refcnt, 2);
                work->nsui_busy = true;
                list_add_tail(&work->nsui_list, &nn->nfsd_ssc_mount_list);