From: Chuck Lever <chuck.lever@oracle.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Jeff Layton <jlayton@kernel.org>, Neil Brown <neilb@suse.de>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] nfsd: prevent integer overflow in decode_cb_compound4res()
Date: Mon, 16 Sep 2024 11:44:13 -0400 [thread overview]
Message-ID: <ZuhSTekyyM2mNu+B@tissot.1015granger.net> (raw)
In-Reply-To: <65cdbbab-7dca-4a73-af07-29863ab8f526@stanley.mountain>
On Mon, Sep 16, 2024 at 06:14:15PM +0300, Dan Carpenter wrote:
> If "length" is >= U32_MAX - 3 then the "length + 4" addition can result
> in an integer overflow. The impact of this bug is not totally clear to
> me, but it's safer to not allow the integer overflow.
>
> There is also some math in xdr_inline_decode() which could overflow, so
> really it's ">= U32_MAX - 7" which is problematic. Let's just check
> against INT_MAX and make it easy.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> fs/nfsd/nfs4callback.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
> index 43b8320c8255..12b44c9246d1 100644
> --- a/fs/nfsd/nfs4callback.c
> +++ b/fs/nfsd/nfs4callback.c
> @@ -317,6 +317,8 @@ static int decode_cb_compound4res(struct xdr_stream *xdr,
> hdr->status = be32_to_cpup(p++);
> /* Ignore the tag */
> length = be32_to_cpup(p++);
> + if (unlikely(length > INT_MAX))
> + goto out_overflow;
I think we assume (wrongly) that xdr_inline_decode() will kick
back any length request that is larger than the xdr_stream's
xdr_buf. Here, the test could be the same: any @length value that is
larger than xdr->buf->len is bogus.
Another way to avoid the overflow would be to split the decode of
the tag and the following op count field. Untested:
length = be32_to_cpup(p);
p = xdr_inline_decode(xdr, length);
if (unlikely(p == NULL))
goto out_overflow;
if (xdr_stream_decode_u32(xdr, &hdr->nops) < 0)
goto out_overflow;
I have generally been using this approach in other NFSD XDR decoding
functions.
I wonder how many other xdr_inline_decode() call sites have a
similar issue.
> p = xdr_inline_decode(xdr, length + 4);
> if (unlikely(p == NULL))
> goto out_overflow;
> --
> 2.45.2
>
--
Chuck Lever
prev parent reply other threads:[~2024-09-16 15:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-16 15:14 Dan Carpenter
2024-09-16 15:44 ` Chuck Lever [this message]
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=ZuhSTekyyM2mNu+B@tissot.1015granger.net \
--to=chuck.lever@oracle.com \
--cc=Dai.Ngo@oracle.com \
--cc=dan.carpenter@linaro.org \
--cc=jlayton@kernel.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neilb@suse.de \
--cc=okorniev@redhat.com \
--cc=tom@talpey.com \
/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
all inboxes | Powered by JetHome®