]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
NFSD: Fix exposure in nfsd4_decode_bitmap()
authorChuck Lever <chuck.lever@oracle.com>
Sun, 14 Nov 2021 20:16:04 +0000 (15:16 -0500)
committerAndrea Righi <andrea.righi@canonical.com>
Tue, 4 Jan 2022 08:48:49 +0000 (09:48 +0100)
BugLink: https://bugs.launchpad.net/bugs/1952579
[ Upstream commit c0019b7db1d7ac62c711cda6b357a659d46428fe ]

rtm@csail.mit.edu reports:
> nfsd4_decode_bitmap4() will write beyond bmval[bmlen-1] if the RPC
> directs it to do so. This can cause nfsd4_decode_state_protect4_a()
> to write client-supplied data beyond the end of
> nfsd4_exchange_id.spo_must_allow[] when called by
> nfsd4_decode_exchange_id().

Rewrite the loops so nfsd4_decode_bitmap() cannot iterate beyond
@bmlen.

Reported by: rtm@csail.mit.edu
Fixes: d1c263a031e8 ("NFSD: Replace READ* macros in nfsd4_decode_fattr()")
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
fs/nfsd/nfs4xdr.c

index be64d3f5e411ee4f114539f8a2a3a24ef12cf1c9..0017da5bf23f1e13b08ad66611978142c3b1fb7c 100644 (file)
@@ -288,11 +288,8 @@ nfsd4_decode_bitmap4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen)
        p = xdr_inline_decode(argp->xdr, count << 2);
        if (!p)
                return nfserr_bad_xdr;
-       i = 0;
-       while (i < count)
-               bmval[i++] = be32_to_cpup(p++);
-       while (i < bmlen)
-               bmval[i++] = 0;
+       for (i = 0; i < bmlen; i++)
+               bmval[i] = (i < count) ? be32_to_cpup(p++) : 0;
 
        return nfs_ok;
 }