]> git.hungrycats.org Git - linux/commitdiff
NFSD: Fix out-of-bounds read in the rpc_status dump
authorChuck Lever <cel@kernel.org>
Mon, 24 Aug 2026 14:04:40 +0000 (10:04 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:06:06 +0000 (12:06 -0500)
commit cbea14890783fead76f878caf0775a62a42049bf upstream.

nfsd_nl_rpc_status_get_dumpit() loads args->opcnt and
args->ops separately, then walks ops[] before rechecking
rq_status_counter. A COMPOUND that completes between the two loads
runs nfsd4_release_compoundargs(), which zeroes opcnt and points ops
back at the eight-entry inline array. A dump that already sampled an
opcnt of 200 clamps it to the sixteen slots in rq_opnum, then indexes
iops[0..15]. iops is the last member of struct nfsd4_compoundargs and
rq_argp is allocated at exactly that size, so the walk runs off the
end of the allocation. The trailing recheck discards the sampled data,
but the read has already happened. NFSD_CMD_RPC_STATUS_GET carries
no GENL_ADMIN_PERM, so an unprivileged local user can repeat the dump
against a busy server until it lands in the window.

Sample opcnt and ops into locals, then finish the counter recheck
before dereferencing ops. An unchanged counter means both came from the
same COMPOUND, where opcnt cannot exceed what ops holds.

Fixes: bd9d6a3efa97 ("NFSD: add rpc_status netlink support")
Cc: stable@vger.kernel.org
Reported-by: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
Closes: https://lore.kernel.org/linux-nfs/20260823113255.3417-1-prabhakar.pujeri@dell.com/
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Link: https://patch.msgid.link/20260824-nfsd-posix-acl-ownership-v1-1-090fffc608ec@kernel.org
Signed-off-by: Chuck Lever <cel@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/nfsd/nfsctl.c

index ec33b5e4f54648de57a762262d4dbbd765f7744b..a0c30a10f9bce0b078f7e04e49173106a1bfb155 100644 (file)
@@ -1576,14 +1576,29 @@ int nfsd_nl_rpc_status_get_dumpit(struct sk_buff *skb,
                            rqstp->rq_proc == NFSPROC4_COMPOUND) {
                                /* NFSv4 compound */
                                struct nfsd4_compoundargs *args;
+                               struct nfsd4_op *ops;
+                               u32 opcnt;
                                int j;
 
                                args = rqstp->rq_argp;
-                               genl_rqstp.rq_opcnt = min_t(u32, args->opcnt,
+                               opcnt = READ_ONCE(args->opcnt);
+                               ops = READ_ONCE(args->ops);
+
+                               /*
+                                * Finish the seqcount retry before
+                                * dereferencing ops. An unchanged counter means
+                                * opcnt and ops came from the same COMPOUND,
+                                * where opcnt cannot exceed what ops holds.
+                                */
+                               smp_rmb();
+                               if (READ_ONCE(rqstp->rq_status_counter) !=
+                                   status_counter)
+                                       continue;
+
+                               genl_rqstp.rq_opcnt = min_t(u32, opcnt,
                                                            ARRAY_SIZE(genl_rqstp.rq_opnum));
                                for (j = 0; j < genl_rqstp.rq_opcnt; j++)
-                                       genl_rqstp.rq_opnum[j] =
-                                               args->ops[j].opnum;
+                                       genl_rqstp.rq_opnum[j] = ops[j].opnum;
                        }
 #endif /* CONFIG_NFSD_V4 */