Skip to content

Commit 623670a

Browse files
congwanggregkh
authored andcommitted
net: drop skb on failure in ip_check_defrag()
[ Upstream commit 7de414a ] Most callers of pskb_trim_rcsum() simply drop the skb when it fails, however, ip_check_defrag() still continues to pass the skb up to stack. This is suspicious. In ip_check_defrag(), after we learn the skb is an IP fragment, passing the skb to callers makes no sense, because callers expect fragments are defrag'ed on success. So, dropping the skb when we can't defrag it is reasonable. Note, prior to commit 88078d9, this is not a big problem as checksum will be fixed up anyway. After it, the checksum is not correct on failure. Found this during code review. Fixes: 88078d9 ("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends") Cc: Eric Dumazet <edumazet@google.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fd090ba commit 623670a

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

net/ipv4/ip_fragment.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,10 +720,14 @@ struct sk_buff *ip_check_defrag(struct net *net, struct sk_buff *skb, u32 user)
720720
if (ip_is_fragment(&iph)) {
721721
skb = skb_share_check(skb, GFP_ATOMIC);
722722
if (skb) {
723-
if (!pskb_may_pull(skb, netoff + iph.ihl * 4))
724-
return skb;
725-
if (pskb_trim_rcsum(skb, netoff + len))
726-
return skb;
723+
if (!pskb_may_pull(skb, netoff + iph.ihl * 4)) {
724+
kfree_skb(skb);
725+
return NULL;
726+
}
727+
if (pskb_trim_rcsum(skb, netoff + len)) {
728+
kfree_skb(skb);
729+
return NULL;
730+
}
727731
memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
728732
if (ip_defrag(net, skb, user))
729733
return NULL;

0 commit comments

Comments
 (0)