Skip to contentSkip to conversation

net: key: Validate address family in set_ipsecrequest()

PATCH New [email protected] 1 participant 1 message Oct 19, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: key: Validate address family in set_ipsecrequest()

From: Shaurya Rane <[email protected]>

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 [email protected]
Fixes 08de61beab8a ("[PFKEYV2]: Extension for dynamic update of endpoint address(es)")
---
 net/key/af_key.c | 4 ++++
 1 file changed, 4 insertions(+)
net/key/af_key.c +4 -0
index 2ebde0352245..713344c594d4 100644
@@ -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);
 
Signature · 1 line
2.34.1