Skip to content

Commit 5447f97

Browse files
skorpion17davem330
authored andcommitted
ipv6: sr: fix missing sk_buff release in seg6_input_core
The seg6_input() function is responsible for adding the SRH into a packet, delegating the operation to the seg6_input_core(). This function uses the skb_cow_head() to ensure that there is sufficient headroom in the sk_buff for accommodating the link-layer header. In the event that the skb_cow_header() function fails, the seg6_input_core() catches the error but it does not release the sk_buff, which will result in a memory leak. This issue was introduced in commit af3b515 ("ipv6: sr: fix BUG due to headroom too small after SRH push") and persists even after commit 7a3f5b0 ("netfilter: add netfilter hooks to SRv6 data plane"), where the entire seg6_input() code was refactored to deal with netfilter hooks. The proposed patch addresses the identified memory leak by requiring the seg6_input_core() function to release the sk_buff in the event that skb_cow_head() fails. Fixes: af3b515 ("ipv6: sr: fix BUG due to headroom too small after SRH push") Signed-off-by: Andrea Mayer <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b1fa60e commit 5447f97

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

net/ipv6/seg6_iptunnel.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,8 @@ static int seg6_input_core(struct net *net, struct sock *sk,
459459
int err;
460460

461461
err = seg6_do_srh(skb);
462-
if (unlikely(err)) {
463-
kfree_skb(skb);
464-
return err;
465-
}
462+
if (unlikely(err))
463+
goto drop;
466464

467465
slwt = seg6_lwt_lwtunnel(orig_dst->lwtstate);
468466

@@ -486,14 +484,17 @@ static int seg6_input_core(struct net *net, struct sock *sk,
486484

487485
err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
488486
if (unlikely(err))
489-
return err;
487+
goto drop;
490488

491489
if (static_branch_unlikely(&nf_hooks_lwtunnel_enabled))
492490
return NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT,
493491
dev_net(skb->dev), NULL, skb, NULL,
494492
skb_dst(skb)->dev, seg6_input_finish);
495493

496494
return seg6_input_finish(dev_net(skb->dev), NULL, skb);
495+
drop:
496+
kfree_skb(skb);
497+
return err;
497498
}
498499

499500
static int seg6_input_nf(struct sk_buff *skb)

0 commit comments

Comments
 (0)