* [PATCH] net: key: Validate address family in set_ipsecrequest()
@ 2025-10-19 18:14 ssrane_b23
0 siblings, 0 replies; 4+ messages in thread
From: ssrane_b23 @ 2025-10-19 18:14 UTC (permalink / raw)
To: netdev
Cc: david.hunter.linux, linux-kernel-mentees, shuah, steffen.klassert,
herbert, davem, edumazet, kuba, pabeni, horms, shinta.sugimoto,
yoshfuji, nakam, linux-kernel, Shaurya Rane,
syzbot+be97dd4da14ae88b6ba4
From: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
syzbot reported a kernel BUG in set_ipsecrequest() due to an
skb_over_panic when processing XFRM_MSG_MIGRATE messages.
The root cause is that set_ipsecrequest() does not validate the
address family parameter before using it to calculate buffer sizes.
When an unsupported family value (such as 0) is passed,
pfkey_sockaddr_len() returns 0, leading to incorrect size calculations.
In pfkey_send_migrate(), the buffer size is calculated based on
pfkey_sockaddr_pair_size(), which uses pfkey_sockaddr_len(). When
family=0, this returns 0, so only sizeof(struct sadb_x_ipsecrequest)
(16 bytes) is allocated per entry. However, set_ipsecrequest() is
called multiple times in a loop (once for old_family, once for
new_family, for each migration bundle), repeatedly calling skb_put_zero()
with 16 bytes each time.
This causes the tail pointer to exceed the end pointer of the skb,
triggering skb_over_panic:
tail: 0x188 (392 bytes)
end: 0x180 (384 bytes)
Fix this by validating that pfkey_sockaddr_len() returns a non-zero
value before proceeding with buffer operations. This ensures proper
size calculations and prevents buffer overflow. Checking socklen
instead of just family==0 provides comprehensive validation for all
unsupported address families.
Reported-by: syzbot+be97dd4da14ae88b6ba4@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=be97dd4da14ae88b6ba4
Fixes: 08de61beab8a ("[PFKEYV2]: Extension for dynamic update of endpoint address(es)")
Signed-off-by: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
---
net/key/af_key.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 2ebde0352245..713344c594d4 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -3526,6 +3526,10 @@ static int set_ipsecrequest(struct sk_buff *skb,
int socklen = pfkey_sockaddr_len(family);
int size_req;
+ /* Reject invalid/unsupported address families */
+ if (!socklen)
+ return -EINVAL;
+
size_req = sizeof(struct sadb_x_ipsecrequest) +
pfkey_sockaddr_pair_size(family);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] net: key: Validate address family in set_ipsecrequest()
@ 2025-10-20 2:49 SHAURYA RANE
2025-10-20 2:52 ` [syzbot] [net?] kernel BUG in set_ipsecrequest syzbot
2025-10-27 20:59 ` [PATCH] net: key: Validate address family in set_ipsecrequest() Simon Horman
0 siblings, 2 replies; 4+ messages in thread
From: SHAURYA RANE @ 2025-10-20 2:49 UTC (permalink / raw)
To: syzbot+be97dd4da14ae88b6ba4
Cc: netdev, linux-kernel, pabeni, steffen.klassert
Hi syzbot,
Please test the following patch.
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
Thanks,
Shaurya Rane
From 123c5ac9ba261681b58a6217409c94722fde4249 Mon Sep 17 00:00:00 2001
From: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
Date: Sun, 19 Oct 2025 23:18:30 +0530
Subject: [PATCH] net: key: Validate address family in set_ipsecrequest()
syzbot reported a kernel BUG in set_ipsecrequest() due to an
skb_over_panic when processing XFRM_MSG_MIGRATE messages.
The root cause is that set_ipsecrequest() does not validate the
address family parameter before using it to calculate buffer sizes.
When an unsupported family value (such as 0) is passed,
pfkey_sockaddr_len() returns 0, leading to incorrect size calculations.
In pfkey_send_migrate(), the buffer size is calculated based on
pfkey_sockaddr_pair_size(), which uses pfkey_sockaddr_len(). When
family=0, this returns 0, so only sizeof(struct sadb_x_ipsecrequest)
(16 bytes) is allocated per entry. However, set_ipsecrequest() is
called multiple times in a loop (once for old_family, once for
new_family, for each migration bundle), repeatedly calling skb_put_zero()
with 16 bytes each time.
This causes the tail pointer to exceed the end pointer of the skb,
triggering skb_over_panic:
tail: 0x188 (392 bytes)
end: 0x180 (384 bytes)
Fix this by validating that pfkey_sockaddr_len() returns a non-zero
value before proceeding with buffer operations. This ensures proper
size calculations and prevents buffer overflow. Checking socklen
instead of just family==0 provides comprehensive validation for all
unsupported address families.
Reported-by: syzbot+be97dd4da14ae88b6ba4@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=be97dd4da14ae88b6ba4
Fixes: 08de61beab8a ("[PFKEYV2]: Extension for dynamic update of
endpoint address(es)")
Signed-off-by: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
---
net/key/af_key.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 2ebde0352245..713344c594d4 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -3526,6 +3526,10 @@ static int set_ipsecrequest(struct sk_buff *skb,
int socklen = pfkey_sockaddr_len(family);
int size_req;
+ /* Reject invalid/unsupported address families */
+ if (!socklen)
+ return -EINVAL;
+
size_req = sizeof(struct sadb_x_ipsecrequest) +
pfkey_sockaddr_pair_size(family);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [syzbot] [net?] kernel BUG in set_ipsecrequest
2025-10-20 2:49 [PATCH] net: key: Validate address family in set_ipsecrequest() SHAURYA RANE
@ 2025-10-20 2:52 ` syzbot
2025-10-27 20:59 ` [PATCH] net: key: Validate address family in set_ipsecrequest() Simon Horman
1 sibling, 0 replies; 4+ messages in thread
From: syzbot @ 2025-10-20 2:52 UTC (permalink / raw)
To: linux-kernel, netdev, pabeni, ssrane_b23, steffen.klassert,
syzkaller-bugs
Hello,
syzbot tried to test the proposed patch but the build/boot failed:
failed to apply patch:
checking file net/key/af_key.c
patch: **** unexpected end of file in patch
Tested on:
commit: 7361c864 selftests/bpf: Fix list_del() in arena list
git tree: bpf-next
kernel config: https://syzkaller.appspot.com/x/.config?x=9ad7b090a18654a7
dashboard link: https://syzkaller.appspot.com/bug?extid=be97dd4da14ae88b6ba4
compiler:
patch: https://syzkaller.appspot.com/x/patch.diff?x=11031492580000
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net: key: Validate address family in set_ipsecrequest()
2025-10-20 2:49 [PATCH] net: key: Validate address family in set_ipsecrequest() SHAURYA RANE
2025-10-20 2:52 ` [syzbot] [net?] kernel BUG in set_ipsecrequest syzbot
@ 2025-10-27 20:59 ` Simon Horman
1 sibling, 0 replies; 4+ messages in thread
From: Simon Horman @ 2025-10-27 20:59 UTC (permalink / raw)
To: SHAURYA RANE
Cc: syzbot+be97dd4da14ae88b6ba4, netdev, linux-kernel, pabeni,
steffen.klassert, Edward Adam Davis, clingfei
+ clingfei, Edward Adam Davis
On Mon, Oct 20, 2025 at 08:19:50AM +0530, SHAURYA RANE wrote:
> Hi syzbot,
>
> Please test the following patch.
>
> #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
>
> Thanks,
> Shaurya Rane
>
>
> >From 123c5ac9ba261681b58a6217409c94722fde4249 Mon Sep 17 00:00:00 2001
> From: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
> Date: Sun, 19 Oct 2025 23:18:30 +0530
> Subject: [PATCH] net: key: Validate address family in set_ipsecrequest()
>
> syzbot reported a kernel BUG in set_ipsecrequest() due to an
> skb_over_panic when processing XFRM_MSG_MIGRATE messages.
>
> The root cause is that set_ipsecrequest() does not validate the
> address family parameter before using it to calculate buffer sizes.
> When an unsupported family value (such as 0) is passed,
> pfkey_sockaddr_len() returns 0, leading to incorrect size calculations.
>
> In pfkey_send_migrate(), the buffer size is calculated based on
> pfkey_sockaddr_pair_size(), which uses pfkey_sockaddr_len(). When
> family=0, this returns 0, so only sizeof(struct sadb_x_ipsecrequest)
> (16 bytes) is allocated per entry. However, set_ipsecrequest() is
> called multiple times in a loop (once for old_family, once for
> new_family, for each migration bundle), repeatedly calling skb_put_zero()
> with 16 bytes each time.
>
> This causes the tail pointer to exceed the end pointer of the skb,
> triggering skb_over_panic:
> tail: 0x188 (392 bytes)
> end: 0x180 (384 bytes)
>
> Fix this by validating that pfkey_sockaddr_len() returns a non-zero
> value before proceeding with buffer operations. This ensures proper
> size calculations and prevents buffer overflow. Checking socklen
> instead of just family==0 provides comprehensive validation for all
> unsupported address families.
>
> Reported-by: syzbot+be97dd4da14ae88b6ba4@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=be97dd4da14ae88b6ba4
> Fixes: 08de61beab8a ("[PFKEYV2]: Extension for dynamic update of
> endpoint address(es)")
> Signed-off-by: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
Hi,
There are several patches relating to this issue. And they seem
to take one of two approaches.
1. As with this patch, [a], and [b]: check the return value of
pfkey_sockaddr_len()
2. As in [c]: correct the type of the family argument to set_ipsecrequest()
[a] net: key: Validate address family in set_ipsecrequest()
https://lore.kernel.org/all/CANNWa05pX3ratdawb2A6AUBocUgYo+EKZeHBZohQWuBC6_W1AA@mail.gmail.com/
[b] key: No support for family zero
https://lore.kernel.org/all/tencent_57525DE2DDF41911CFDB8DF525A08D9D9207@qq.com/
[c] fix integer overflow in set_ipsecrequest
https://lore.kernel.org/all/20251021030035.1424912-1-1599101385@qq.com/
I would appreciate it if the patch authors could coordinate creating a
patch(set) to address this issue. And look over the more detailed response
I provided to [c].
Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-10-27 20:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-20 2:49 [PATCH] net: key: Validate address family in set_ipsecrequest() SHAURYA RANE
2025-10-20 2:52 ` [syzbot] [net?] kernel BUG in set_ipsecrequest syzbot
2025-10-27 20:59 ` [PATCH] net: key: Validate address family in set_ipsecrequest() Simon Horman
-- strict thread matches above, loose matches on Subject: below --
2025-10-19 18:14 ssrane_b23
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).