From: Dan Carpenter <dan.carpenter@linaro.org>
To: Herbert Xu <herbert@gondor.apana.org.au>
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
Subject: [PATCH net] xfrm: prevent some integer overflows in verify_ functions
Date: Tue, 17 Dec 2024 11:42:31 +0300 [thread overview]
Message-ID: <92dc4619-7598-439e-8544-4b3b2cf5e597@stanley.mountain> (raw)
The xfrm_alg_len() type functions take the alg->alg_key_len which
is the length in bits and converts it to bytes and add it to
sizeof(*alg).
return sizeof(*alg) + ((alg->alg_key_len + 7) / 8);
The alg->alg_key_len is type unsigned int. That means that if we pick
an ->alg_key_len which is greater than "UINT_MAX - 7" it leads to an
integer overflow and the key length is treated as zero. The result
is that xfrm_alg_len() function will return "sizeof(*alg) + 0".
However, so far as I can see this does not cause a problem. All the
places which use this length consistently do the same conversion. The
type of thing I was looking for would be code which uses partial keys
or code which uses a different type instead of u32 for ->alg_key_len.
I didn't find anything like that so I can't see a negative impact from
this bug. Still fixing it is the right thing to do.
Fixes: 31c26852cb2a ("[IPSEC]: Verify key payload in verify_one_algo")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
net/xfrm/xfrm_user.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 08c6d6f0179f..686c6a24d92b 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -45,6 +45,10 @@ static int verify_one_alg(struct nlattr **attrs, enum xfrm_attr_type_t type,
return 0;
algp = nla_data(rt);
+ if (algp->alg_key_len > INT_MAX) {
+ NL_SET_ERR_MSG(extack, "Invalid AUTH/CRYPT/COMP key length");
+ return -EINVAL;
+ }
if (nla_len(rt) < (int)xfrm_alg_len(algp)) {
NL_SET_ERR_MSG(extack, "Invalid AUTH/CRYPT/COMP attribute length");
return -EINVAL;
@@ -75,6 +79,10 @@ static int verify_auth_trunc(struct nlattr **attrs,
return 0;
algp = nla_data(rt);
+ if (algp->alg_key_len > INT_MAX) {
+ NL_SET_ERR_MSG(extack, "Invalid AUTH_TRUNC key length");
+ return -EINVAL;
+ }
if (nla_len(rt) < (int)xfrm_alg_auth_len(algp)) {
NL_SET_ERR_MSG(extack, "Invalid AUTH_TRUNC attribute length");
return -EINVAL;
@@ -93,6 +101,10 @@ static int verify_aead(struct nlattr **attrs, struct netlink_ext_ack *extack)
return 0;
algp = nla_data(rt);
+ if (algp->alg_key_len > INT_MAX) {
+ NL_SET_ERR_MSG(extack, "Invalid AEAD key length");
+ return -EINVAL;
+ }
if (nla_len(rt) < (int)aead_len(algp)) {
NL_SET_ERR_MSG(extack, "Invalid AEAD attribute length");
return -EINVAL;
--
2.45.2
next reply other threads:[~2024-12-17 8:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-17 8:42 Dan Carpenter [this message]
2024-12-17 12:03 ` [PATCH net] xfrm: prevent some integer overflows in verify_ functions 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
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=92dc4619-7598-439e-8544-4b3b2cf5e597@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=kernel-janitors@vger.kernel.org \
--cc=kuba@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