From: Trond Myklebust <trondmy@hammerspace.com>
To: "bfields@fieldses.org" <bfields@fieldses.org>,
"chuck.lever@oracle.com" <chuck.lever@oracle.com>
Cc: "linux-nfs@vger.kernel.org" <linux-nfs@vger.kernel.org>,
"rtm@csail.mit.edu" <rtm@csail.mit.edu>
Subject: Re: NFS client can crash server due to overrun in nfsd4_decode_bitmap4()
Date: Mon, 13 Dec 2021 04:52:41 +0000 [thread overview]
Message-ID: <a8d3392e2a4e287b343fa5189b615e98a862fc4c.camel@hammerspace.com> (raw)
In-Reply-To: <4D63A33B-5E6C-4703-BD02-9E6D43782BD4@oracle.com>
On Mon, 2021-12-13 at 04:21 +0000, Chuck Lever III wrote:
>
> > On Dec 12, 2021, at 9:10 PM, Bruce Fields <bfields@fieldses.org>
> > wrote:
> >
> > On Sat, Nov 13, 2021 at 09:31:40PM +0000, Chuck Lever III wrote:
> > > Sure, but that's more restrictive than what the old decoder
> > > did. I have this instead (also yet to be tested):
> > >
> > > NFSD: Fix exposure in nfsd4_decode_bitmap()
> > >
> > > 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>
> > >
> > > diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> > > index 10883e6d80ac..c2f753233fcf 100644
> > > --- a/fs/nfsd/nfs4xdr.c
> > > +++ b/fs/nfsd/nfs4xdr.c
> > > @@ -288,12 +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;
> > > }
> > >
> > > This allows the client to send bitmaps larger than bmval[],
> > > as the old decoder did, and ensures that decode_bitmap()
> > > cannot write farther than @bmlen into the bmval array.
> >
> > But I notice now that your tree has "NFSD: Replace
> > nfsd4_decode_bitmap4()", which does error out on large bitmaps.
> > (Noticed because pynfs checks for this case (see GATT4s and
> > similar) and
> > is seeing BADXDR returns).
>
> D’oh! I can drop “Replace nfsd4_decode_bitmap4()” or we can update
> the generic helper to handle large bitmaps. Dropping the clean-up
> seems safer.
>
The xdr_stream_decode_uint32_array() generic helper already handles
large bitmaps. It will decode as many entries as will fit in @array,
but return -EMSGSIZE to let you know that size was truncated.
IOW: you should treat -EMSGSIZE as a sign that @array_size elements
were actually decoded, rather than as a sign that no elements were
decoded.
--
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trond.myklebust@hammerspace.com
next prev parent reply other threads:[~2021-12-13 4:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-13 20:58 NFS client can crash server due to overrun in nfsd4_decode_bitmap4() rtm
2021-11-13 21:06 ` Chuck Lever III
2021-11-13 21:25 ` Bruce Fields
2021-11-13 21:31 ` Chuck Lever III
2021-11-13 21:57 ` Bruce Fields
2021-11-14 2:44 ` Chuck Lever III
2021-12-13 2:10 ` Bruce Fields
2021-12-13 4:21 ` Chuck Lever III
2021-12-13 4:52 ` Trond Myklebust [this message]
2021-11-13 21:33 ` J. Bruce Fields
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a8d3392e2a4e287b343fa5189b615e98a862fc4c.camel@hammerspace.com \
--to=trondmy@hammerspace.com \
--cc=bfields@fieldses.org \
--cc=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=rtm@csail.mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox