From: Steffen Klassert <steffen.klassert@secunet.com>
To: David Miller <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
Steffen Klassert <steffen.klassert@secunet.com>,
<netdev@vger.kernel.org>
Subject: [PATCH 19/20] af_key: validate families in pfkey_send_migrate()
Date: Mon, 23 Mar 2026 09:34:00 +0100 [thread overview]
Message-ID: <20260323083440.2741292-20-steffen.klassert@secunet.com> (raw)
In-Reply-To: <20260323083440.2741292-1-steffen.klassert@secunet.com>
From: Eric Dumazet <edumazet@google.com>
syzbot was able to trigger a crash in skb_put() [1]
Issue is that pfkey_send_migrate() does not check old/new families,
and that set_ipsecrequest() @family argument was truncated,
thus possibly overfilling the skb.
Validate families early, do not wait set_ipsecrequest().
[1]
skbuff: skb_over_panic: text:ffffffff8a752120 len:392 put:16 head:ffff88802a4ad040 data:ffff88802a4ad040 tail:0x188 end:0x180 dev:<NULL>
kernel BUG at net/core/skbuff.c:214 !
Call Trace:
<TASK>
skb_over_panic net/core/skbuff.c:219 [inline]
skb_put+0x159/0x210 net/core/skbuff.c:2655
skb_put_zero include/linux/skbuff.h:2788 [inline]
set_ipsecrequest net/key/af_key.c:3532 [inline]
pfkey_send_migrate+0x1270/0x2e50 net/key/af_key.c:3636
km_migrate+0x155/0x260 net/xfrm/xfrm_state.c:2848
xfrm_migrate+0x2140/0x2450 net/xfrm/xfrm_policy.c:4705
xfrm_do_migrate+0x8ff/0xaa0 net/xfrm/xfrm_user.c:3150
Fixes: 08de61beab8a ("[PFKEYV2]: Extension for dynamic update of endpoint address(es)")
Reported-by: syzbot+b518dfc8e021988fbd55@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/69b5933c.050a0220.248e02.00f2.GAE@google.com/T/#u
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
net/key/af_key.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 571200433aa9..bc91aeeb74bb 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -3518,7 +3518,7 @@ static int set_sadb_kmaddress(struct sk_buff *skb, const struct xfrm_kmaddress *
static int set_ipsecrequest(struct sk_buff *skb,
uint8_t proto, uint8_t mode, int level,
- uint32_t reqid, uint8_t family,
+ uint32_t reqid, sa_family_t family,
const xfrm_address_t *src, const xfrm_address_t *dst)
{
struct sadb_x_ipsecrequest *rq;
@@ -3583,12 +3583,17 @@ static int pfkey_send_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
/* ipsecrequests */
for (i = 0, mp = m; i < num_bundles; i++, mp++) {
- /* old locator pair */
- size_pol += sizeof(struct sadb_x_ipsecrequest) +
- pfkey_sockaddr_pair_size(mp->old_family);
- /* new locator pair */
- size_pol += sizeof(struct sadb_x_ipsecrequest) +
- pfkey_sockaddr_pair_size(mp->new_family);
+ int pair_size;
+
+ pair_size = pfkey_sockaddr_pair_size(mp->old_family);
+ if (!pair_size)
+ return -EINVAL;
+ size_pol += sizeof(struct sadb_x_ipsecrequest) + pair_size;
+
+ pair_size = pfkey_sockaddr_pair_size(mp->new_family);
+ if (!pair_size)
+ return -EINVAL;
+ size_pol += sizeof(struct sadb_x_ipsecrequest) + pair_size;
}
size += sizeof(struct sadb_msg) + size_pol;
--
2.43.0
next prev parent reply other threads:[~2026-03-23 8:35 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 8:33 [PATCH 0/20] pull request (net): ipsec 2026-03-23 Steffen Klassert
2026-03-23 8:33 ` [PATCH 01/20] xfrm: add missing extack for XFRMA_SA_PCPU in add_acquire and allocspi Steffen Klassert
2026-03-24 14:30 ` patchwork-bot+netdevbpf
2026-03-23 8:33 ` [PATCH 02/20] xfrm: fix the condition on x->pcpu_num in xfrm_sa_len Steffen Klassert
2026-03-23 8:33 ` [PATCH 03/20] xfrm: call xdo_dev_state_delete during state update Steffen Klassert
2026-03-23 8:33 ` [PATCH 04/20] esp: fix skb leak with espintcp and async crypto Steffen Klassert
2026-03-23 8:33 ` [PATCH 05/20] xfrm: iptfs: validate inner IPv4 header length in IPTFS payload Steffen Klassert
2026-03-23 8:33 ` [PATCH 06/20] xfrm: iptfs: fix skb_put() panic on non-linear skb during reassembly Steffen Klassert
2026-03-23 8:33 ` [PATCH 07/20] xfrm: state: fix sparse warnings on xfrm_state_hold_rcu Steffen Klassert
2026-03-23 8:33 ` [PATCH 08/20] xfrm: state: fix sparse warnings in xfrm_state_init Steffen Klassert
2026-03-23 8:33 ` [PATCH 09/20] xfrm: state: fix sparse warnings around XFRM_STATE_INSERT Steffen Klassert
2026-03-23 8:33 ` [PATCH 10/20] xfrm: state: add xfrm_state_deref_prot to state_by* walk under lock Steffen Klassert
2026-03-23 8:33 ` [PATCH 11/20] xfrm: remove rcu/state_hold from xfrm_state_lookup_spi_proto Steffen Klassert
2026-03-23 8:33 ` [PATCH 12/20] xfrm: state: silence sparse warnings during netns exit Steffen Klassert
2026-03-23 8:33 ` [PATCH 13/20] xfrm: policy: fix sparse warnings in xfrm_policy_{init,fini} Steffen Klassert
2026-03-23 8:33 ` [PATCH 14/20] xfrm: policy: silence sparse warning in xfrm_policy_unregister_afinfo Steffen Klassert
2026-03-23 8:33 ` [PATCH 15/20] xfrm: add rcu_access_pointer to silence sparse warning for xfrm_input_afinfo Steffen Klassert
2026-03-23 8:33 ` [PATCH 16/20] xfrm: avoid RCU warnings around the per-netns netlink socket Steffen Klassert
2026-03-23 8:33 ` [PATCH 17/20] xfrm: Fix work re-schedule after cancel in xfrm_nat_keepalive_net_fini() Steffen Klassert
2026-03-23 8:33 ` [PATCH 18/20] xfrm: prevent policy_hthresh.work from racing with netns teardown Steffen Klassert
2026-03-23 8:34 ` Steffen Klassert [this message]
2026-03-23 8:34 ` [PATCH 20/20] xfrm: iptfs: only publish mode_data after clone setup Steffen Klassert
2026-03-24 11:33 ` Paolo Abeni
2026-03-24 11:52 ` Steffen Klassert
2026-03-24 12:35 ` Paolo Abeni
2026-03-24 12:40 ` Steffen Klassert
2026-03-24 14:22 ` Paolo Abeni
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=20260323083440.2741292-20-steffen.klassert@secunet.com \
--to=steffen.klassert@secunet.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
/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