]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
lockd: Avoid hashing uninitialized bytes in nlm4svc_lookup_file()
authorChuck Lever <chuck.lever@oracle.com>
Thu, 14 May 2026 20:56:07 +0000 (16:56 -0400)
committerChuck Lever <cel@kernel.org>
Tue, 9 Jun 2026 20:32:59 +0000 (16:32 -0400)
file_hash() digests the first LOCKD_FH_HASH_SIZE bytes of
nfs_fh.data when bucketing nlm_files[], independent of fh.size.
Commit 3de744ee4e45 ("lockd: Use xdrgen XDR functions for the
NLMv4 TEST procedure") set .pc_argzero to zero for the converted
procedures and moved file-handle population into
nlm4svc_lookup_file(), which copies only xdr_lock->fh.len bytes
into lock->fh.data.

When an NLMv4 client presents a file handle shorter than
LOCKD_FH_HASH_SIZE, bytes fh.len..31 retain whatever the argument
buffer held from an earlier request.  The same wire handle then
hashes to different buckets across calls; nlm_lookup_file() misses
the existing nlm_file entry, and lock-state lookups fail.

Zero only the tail bytes that file_hash() would otherwise consume.
Handles of LOCKD_FH_HASH_SIZE or larger already populate every byte
that file_hash() reads.

Reported-by: Jeff Layton <jlayton@kernel.org>
Closes: https://lore.kernel.org/r/5229a9746d723a3f830120c0b966510f75badfc2.camel@kernel.org
Fixes: 3de744ee4e45 ("lockd: Use xdrgen XDR functions for the NLMv4 TEST procedure")
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/lockd/lockd.h
fs/lockd/svc4proc.c
fs/lockd/svcsubs.c

index 0be0dac59ea29b1fc67e1a4883c64d9d9d83a58a..e418a50c41803571bc3db0c615bf046e6863f879 100644 (file)
  */
 #define LOCKD_DFLT_TIMEO       10
 
+/*
+ * Number of leading bytes of nfs_fh.data that file_hash()
+ * digests when bucketing nlm_files[]. Sized for historical
+ * NFSv2 handles; nfs_fh.data must be initialized at least
+ * this far before lookup, regardless of fh.size.
+ */
+#define LOCKD_FH_HASH_SIZE     32
+
 /* error codes new to NLMv4 */
 #define        nlm4_deadlock           cpu_to_be32(NLM_DEADLCK)
 #define        nlm4_rofs               cpu_to_be32(NLM_ROFS)
index 997f4f437997f32937800f28048fb3edc0cbb949..78e675470c4b289ff123b7759990f0574a542e9f 100644 (file)
@@ -156,6 +156,9 @@ nlm4svc_lookup_file(struct svc_rqst *rqstp, struct nlm_host *host,
                return nlm_lck_denied_nolocks;
        lock->fh.size = xdr_lock->fh.len;
        memcpy(lock->fh.data, xdr_lock->fh.data, xdr_lock->fh.len);
+       if (xdr_lock->fh.len < LOCKD_FH_HASH_SIZE)
+               memset(lock->fh.data + xdr_lock->fh.len, 0,
+                      LOCKD_FH_HASH_SIZE - xdr_lock->fh.len);
 
        lock->oh.len = xdr_lock->oh.len;
        lock->oh.data = xdr_lock->oh.data;
index 58b87ec529308d871dac2114abee75c07e3e25d8..a0d1a6fbf61ee9041aacfe569a88d9af874aa854 100644 (file)
@@ -17,7 +17,6 @@
 #include <linux/sunrpc/addr.h>
 #include <linux/module.h>
 #include <linux/mount.h>
-#include <uapi/linux/nfs2.h>
 
 #include "lockd.h"
 #include "share.h"
@@ -67,7 +66,7 @@ static inline unsigned int file_hash(struct nfs_fh *f)
 {
        unsigned int tmp=0;
        int i;
-       for (i=0; i<NFS2_FHSIZE;i++)
+       for (i = 0; i < LOCKD_FH_HASH_SIZE; i++)
                tmp += f->data[i];
        return tmp & (FILE_NRHASH - 1);
 }