From: Dan Carpenter <dan.carpenter@linaro.org>
To: Herbert Xu <herbert@gondor.apana.org.au>,
Justin Stitt <justinstitt@google.com>,
Kees Cook <kees@kernel.org>
Cc: Steffen Klassert <steffen.klassert@secunet.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH net] xfrm: Rewrite key length conversion to avoid overflows
Date: Wed, 18 Dec 2024 13:54:38 +0300 [thread overview]
Message-ID: <cedbaec9-d149-48af-8068-182f0af5a89c@stanley.mountain> (raw)
In-Reply-To: <Z2KZC71JZ0QnrhfU@gondor.apana.org.au>
On Wed, Dec 18, 2024 at 05:42:35PM +0800, Herbert Xu wrote:
> On Tue, Dec 17, 2024 at 03:32:31PM +0300, Dan Carpenter wrote:
> >
> > That seems like basic algebra but we have a long history of getting
> > integer overflow checks wrong so these days I like to just use
> > INT_MAX where ever I can. I wanted to use USHRT_MAX. We aren't allowed
> > to use more than USHRT_MAX bytes, but maybe we're allowed USHRT_MAX
> > bits, so I didn't do that.
>
> There is no reason for this to overflow if we rewrite it do do
> the division carefully. Something like this:
>
I like it! So obvious in retrospect. Kees, Justin, this is probably a
good strategy for dealing with round_up() related integer overflows
generally.
overflows to zero: (len + 7) / 8
no overflow: len / 8 + !!(len & 7)
> Steffen, this raises a new question: Can normal users create socket
> policies of arbtirarily long key lengths? If so we probably should
> look into limiting the key length to a sane value. Of course, given
> namespaces we probably should do that in any case.
The length is capped in verify_one_alg() type functions:
if (nla_len(rt) < (int)xfrm_alg_len(algp)) {
nla_len() is a USHRT_MAX so the rounded value can't be higher than that.
The (int) cast is unnecessary and confusing. The condition should
probably flipped around so the untrusted part is on the left.
if (xfrm_alg_len(algp) > nla_len(rt))
return -EINVAL;
regards,
dan carpenter
next prev parent reply other threads:[~2024-12-18 10:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-17 8:42 [PATCH net] xfrm: prevent some integer overflows in verify_ functions Dan Carpenter
2024-12-17 12:03 ` Herbert Xu
2024-12-17 12:32 ` Dan Carpenter
2024-12-18 9:42 ` [PATCH net] xfrm: Rewrite key length conversion to avoid overflows Herbert Xu
2024-12-18 10:54 ` Dan Carpenter [this message]
2024-12-18 11:58 ` Herbert Xu
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=cedbaec9-d149-48af-8068-182f0af5a89c@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=justinstitt@google.com \
--cc=kees@kernel.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=steffen.klassert@secunet.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