ipv6: xfrm6: release dst on error in xfrm6_rcv_encap()
Subsystems (3)
PATCH 1/1 ipv6: xfrm6: release dst on error in xfrm6_rcv_encap()
In reply to a message not in the archiveFrom: Yilin Zhu <[email protected]>
xfrm6_rcv_encap() performs an IPv6 route lookup when the skb does not already have a dst attached. ip6_route_input_lookup() returns a referenced dst entry even when the lookup resolves to an error route.
If dst->error is set, xfrm6_rcv_encap() drops the skb without attaching the dst to the skb and without releasing the reference returned by the lookup. Repeated packets hitting this path therefore leak dst entries.
Release the dst before jumping to the drop path.
--- net/ipv6/xfrm6_protocol.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/ipv6/xfrm6_protocol.c +3 -1
@@ -88,8 +88,10 @@ int xfrm6_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi, dst =ip6_route_input_lookup (dev_net (skb->dev), skb->dev, &fl6, skb, flags); -if (dst->error) +if (dst->error) { +dst_release (dst); goto drop; + }skb_dst_set (skb, dst); }
Signature · 1 line
2.43.0
Quoted 22 lines · Ren Wei
From: Yilin Zhu <[email protected]>
xfrm6_rcv_encap()performs an IPv6 route lookup when the skb does not already have a dst attached.ip6_route_input_lookup()returns a referenced dst entry even when the lookup resolves to an error route.If
dst->erroris set,xfrm6_rcv_encap()drops the skb without attaching the dst to the skb and without releasing the reference returned by the lookup. Repeated packets hitting this path therefore leak dst entries.Release the dst before jumping to the drop path.
Fixes 0146dca70b87 ("xfrm: add support for UDPv6 encapsulation of ESP")Reported-by Yifan Wu <[email protected]>Reported-by Juefei Pu <[email protected]>Co-developed-by Yuan Tan <[email protected]>Signed-off-by Yuan Tan <[email protected]>Suggested-by Xin Liu <[email protected]>Tested-by Ruide Cao <[email protected]>Signed-off-by Yilin Zhu <[email protected]>Signed-off-by Ren Wei <[email protected]>
Quoted 3 lines
--- net/ipv6/xfrm6_protocol.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Simon Horman
reviewerFrom: 'Simon Horman' <[email protected]>
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
---
ipv6: xfrm6: release dst on error in xfrm6_rcv_encap()
This commit fixes a dst entry leak in xfrm6_rcv_encap() by ensuring the dst is released when ip6_route_input_lookup() returns an error route.
net/ipv6/xfrm6_protocol.c int xfrm6_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi, · line 90
Quoted 8 lines
net/ipv6/xfrm6_protocol.c +0
-0@@ -88,8 +88,10 @@ int xfrm6_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi, dst =ip6_route_input_lookup (dev_net (skb->dev), skb->dev, &fl6, skb, flags);
This isn't a bug introduced by this patch, but is it possible for skb->dev to be NULL here?
When ESP packets are delivered over TCP, they are processed asynchronously via handle_esp() in net/xfrm/espintcp.c. This dynamically resolves skb->dev using dev_get_by_index_rcu(). If the interface was removed before this runs, it returns NULL.
Because TCP receive paths drop the skb's dst entry, skb_dst(skb) is NULL. When handle_esp() passes the skb to xfrm6_rcv_encap(), it enters the !skb_dst(skb) block and unconditionally accesses skb->dev->ifindex and calls dev_net(skb->dev).
Could this result in a NULL pointer dereference if the interface is torn down while packets are being processed asynchronously?
Quoted 8 lines
net/ipv6/xfrm6_protocol.c +3
-1-if (dst->error) +if (dst->error) { +dst_release (dst); goto drop; + }skb_dst_set (skb, dst); }
Quoted 12 lines · Ren Wei
From: Yilin Zhu <[email protected]>
xfrm6_rcv_encap()performs an IPv6 route lookup when the skb does not already have a dst attached.ip6_route_input_lookup()returns a referenced dst entry even when the lookup resolves to an error route.If
dst->erroris set,xfrm6_rcv_encap()drops the skb without attaching the dst to the skb and without releasing the reference returned by the lookup. Repeated packets hitting this path therefore leak dst entries.Release the dst before jumping to the drop path.
Quoted 10 lines
Fixes 0146dca70b87 ("xfrm: add support for UDPv6 encapsulation of ESP")Reported-by Yifan Wu <[email protected]>Reported-by Juefei Pu <[email protected]>Co-developed-by Yuan Tan <[email protected]>Signed-off-by Yuan Tan <[email protected]>Suggested-by Xin Liu <[email protected]>Tested-by Ruide Cao <[email protected]>Signed-off-by Yilin Zhu <[email protected]>Signed-off-by Ren Wei <[email protected]>
Applied to the ipsec tree, thanks a lot!