Skip to contentSkip to conversation

skb_try_coalesce and fraglists (bug?)

PATCH Erik Hugne 2 participants 2 messages Feb 4, 2015

Subsystems (2)
lore
Share & tools
lore

Erik Hugne

author
#0 lore raw

skb_try_coalesce should bail out for a number of reasons, if the target skb is cloned, doesn't have enough room, or if either source or target skb have fraglists.

However, it seems that the skb_has_frag_list check is done too late, and a small skb may be copied into the tailroom of the head, even if it has a fraglist.

Wouldn't this be more correct?

net/core/skbuff.c +3 -3
index 56db472..8d02140 100644
@@ -4056,6 +4056,9 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
        if (skb_cloned(to))
                return false;
 
+       if (skb_has_frag_list(to) || skb_has_frag_list(from))
+               return false;
+
        if (len <= skb_tailroom(to)) {
                if (len)
                        BUG_ON(skb_copy_bits(from, 0, skb_put(to, len), len));
@@ -4063,9 +4066,6 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
                return true;
        }
 
-       if (skb_has_frag_list(to) || skb_has_frag_list(from))
-               return false;
-
        if (skb_headlen(from) != 0) {
                struct page *page;
                unsigned int offset;
#1 lore raw
Quoted 25 lines · Erik Hugne

skb_try_coalesce should bail out for a number of reasons, if the target skb is cloned, doesn't have enough room, or if either source or target skb have fraglists.

However, it seems that the skb_has_frag_list check is done too late, and a small skb may be copied into the tailroom of the head, even if it has a fraglist.

Wouldn't this be more correct?

net/core/skbuff.c +3 -0
index 56db472..8d02140 100644
@@ -4056,6 +4056,9 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
        if (skb_cloned(to))
                return false;
 
+       if (skb_has_frag_list(to) || skb_has_frag_list(from))
+               return false;
+
        if (len <= skb_tailroom(to)) {
                if (len)
                        BUG_ON(skb_copy_bits(from, 0, skb_put(to, len), len));

net/core/skbuff.c bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from, · line 4071

Quoted 9 lines
net/core/skbuff.c +0 -3
@@ -4063,9 +4066,6 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
                return true;
        }
 
-       if (skb_has_frag_list(to) || skb_has_frag_list(from))
-               return false;
-
        if (skb_headlen(from) != 0) {
                struct page *page;
                unsigned int offset;

Patch is not needed.

If to had a fraglist, skb_tailroom(to) would be 0