GRO: fix merging a paged skb after non-paged skbs
Subsystems (2)
PATCH 1/1 GRO: fix merging a paged skb after non-paged skbs
Suppose that several linear skbs of the same flow were received by GRO. They were thus merged into one skb with a frag_list. Then a new skb of the same flow arrives, but it is a paged skb with data starting in its frags[].
Before adding the skb to the frag_list skb_gro_receive() will of course adjust the skb to throw away the headers. It correctly modifies the page_offset and size of the frag, but it leaves incorrect information in the skb:
->data_len is not decreased at all.
->len is decreased only by headlen, as if no change were done to the frag.
Later in a receiving process this causes skb_copy_datagram_iovec() to return -EFAULT and this is seen in userspace as the result of the recv() syscall.
In practice the bug can be reproduced with the sfc driver. By default the driver uses an adaptive scheme when it switches between using napi_gro_receive() (with skbs) and napi_gro_frags() (with pages). The bug is reproduced when under rx load with enough successful GRO merging the driver decides to switch from the former to the latter.
Manual control is also possible, so reproducing this is easy with netcat:
- on machine1 (with sfc): nc -l 12345 > /dev/null
- on machine2: nc machine1 12345 < /dev/zero
- on machine1:
echo 1 > /sys/module/sfc/parameters/rx_alloc_method # use skbs echo 2 > /sys/module/sfc/parameters/rx_alloc_method # use pages
- See that nc has quit suddenly.
--- net/core/skbuff.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/core/skbuff.c +1 -1
@@ -2746,7 +2746,7 @@ merge:if (offset > headlen) { skbinfo->frags[0 ].page_offset += offset - headlen; skbinfo->frags[0 ].size -= offset - headlen; - offset = headlen; + skb->data_len -= offset - headlen; }__skb_pull (skb, offset);
Signature · 1 line
1.7.1
Quoted 36 lines · Michal Schmidt
Suppose that several linear skbs of the same flow were received by GRO. They were thus merged into one skb with a
frag_list. Then a new skb of the same flow arrives, but it is a paged skb with data starting in its frags[].Before adding the skb to the
frag_listskb_gro_receive()will of course adjust the skb to throw away the headers. It correctly modifies thepage_offsetand size of the frag, but it leaves incorrect information in the skb:
->data_len is not decreased at all.
->len is decreased only by headlen, as if no change were done to the frag.
Later in a receiving process this causesskb_copy_datagram_iovec()to return-EFAULTand this is seen in userspace as the result of therecv()syscall.In practice the bug can be reproduced with the sfc driver. By default the driver uses an adaptive scheme when it switches between using
napi_gro_receive()(with skbs) andnapi_gro_frags()(with pages). The bug is reproduced when under rx load with enough successful GRO merging the driver decides to switch from the former to the latter.Manual control is also possible, so reproducing this is easy with netcat:
- on machine1 (with sfc): nc -l 12345 >/dev/null
- on machine2: nc machine1 12345 </dev/zero
- on machine1:
echo 1 >/sys/module/sfc/parameters/rx_alloc_method# use skbs echo 2 >/sys/module/sfc/parameters/rx_alloc_method# use pages
- See that nc has quit suddenly.Signed-off-by Michal Schmidt <[email protected]>--- net/core/skbuff.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)net/core/skbuff.c +0
-0
net/core/skbuff.c merge: · line 2752
Quoted 8 lines
net/core/skbuff.c +1
-1@@ -2746,7 +2746,7 @@ merge:if (offset > headlen) { skbinfo->frags[0 ].page_offset += offset - headlen; skbinfo->frags[0 ].size -= offset - headlen; - offset = headlen; + skb->data_len -= offset - headlen; }__skb_pull (skb, offset);
Hi Michal
Hmm, I dont really understand how __skb_pull(skb, offset) can be ok if offset > headlen
skb->data might reach tail/end ?
Maybe I am too confused, this code is a bit complex :(
Thanks !
net/core/skbuff.c +6 -2
@@ -2744,8 +2744,12 @@ int skb_gro_receive(struct sk_buff **head, struct sk_buff *skb) merge:if (offset > headlen) { - skbinfo->frags[0 ].page_offset += offset - headlen; - skbinfo->frags[0 ].size -= offset - headlen; +unsigned int eat = offset - headlen; + + skbinfo->frags[0 ].page_offset += eat; + skbinfo->frags[0 ].size -= eat; + skb->data_len -= eat; + skb->len -= eat; offset = headlen; }
PATCH v2 1/1 GRO: fix merging a paged skb after non-paged skbs
Suppose that several linear skbs of the same flow were received by GRO. They were thus merged into one skb with a frag_list. Then a new skb of the same flow arrives, but it is a paged skb with data starting in its frags[].
Before adding the skb to the frag_list skb_gro_receive() will of course adjust the skb to throw away the headers. It correctly modifies the page_offset and size of the frag, but it leaves incorrect information in the skb:
->data_len is not decreased at all.
->len is decreased only by headlen, as if no change were done to the frag.
Later in a receiving process this causes skb_copy_datagram_iovec() to return -EFAULT and this is seen in userspace as the result of the recv() syscall.
In practice the bug can be reproduced with the sfc driver. By default the driver uses an adaptive scheme when it switches between using napi_gro_receive() (with skbs) and napi_gro_frags() (with pages). The bug is reproduced when under rx load with enough successful GRO merging the driver decides to switch from the former to the latter.
Manual control is also possible, so reproducing this is easy with netcat:
- on machine1 (with sfc): nc -l 12345 > /dev/null
- on machine2: nc machine1 12345 < /dev/zero
- on machine1:
echo 1 > /sys/module/sfc/parameters/rx_alloc_method # use skbs echo 2 > /sys/module/sfc/parameters/rx_alloc_method # use pages
- See that nc has quit suddenly.
[v2: Modified by Eric Dumazet to avoid advancing skb->data past the end
and to use a temporary variable.]
---
Eric,
I think skb->data is pretty much irrelevant at that point, because the skb's headlen is going to become zero, but admittedly it seems cleaner this way.
Thanks.
net/core/skbuff.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
net/core/skbuff.c +6 -2
@@ -2744,8 +2744,12 @@ int skb_gro_receive(struct sk_buff **head, struct sk_buff *skb) merge:if (offset > headlen) { - skbinfo->frags[0 ].page_offset += offset - headlen; - skbinfo->frags[0 ].size -= offset - headlen; +unsigned int eat = offset - headlen; + + skbinfo->frags[0 ].page_offset += eat; + skbinfo->frags[0 ].size -= eat; + skb->data_len -= eat; + skb->len -= eat; offset = headlen; }
Signature · 1 line
1.7.3.4
Quoted 49 lines · Michal Schmidt
Suppose that several linear skbs of the same flow were received by GRO. They were thus merged into one skb with a
frag_list. Then a new skb of the same flow arrives, but it is a paged skb with data starting in its frags[].Before adding the skb to the
frag_listskb_gro_receive()will of course adjust the skb to throw away the headers. It correctly modifies thepage_offsetand size of the frag, but it leaves incorrect information in the skb:
->data_len is not decreased at all.
->len is decreased only by headlen, as if no change were done to the frag.
Later in a receiving process this causesskb_copy_datagram_iovec()to return-EFAULTand this is seen in userspace as the result of therecv()syscall.In practice the bug can be reproduced with the sfc driver. By default the driver uses an adaptive scheme when it switches between using
napi_gro_receive()(with skbs) andnapi_gro_frags()(with pages). The bug is reproduced when under rx load with enough successful GRO merging the driver decides to switch from the former to the latter.Manual control is also possible, so reproducing this is easy with netcat:
- on machine1 (with sfc): nc -l 12345 >/dev/null
- on machine2: nc machine1 12345 </dev/zero
- on machine1:
echo 1 >/sys/module/sfc/parameters/rx_alloc_method# use skbs echo 2 >/sys/module/sfc/parameters/rx_alloc_method# use pages
- See that nc has quit suddenly.[v2: Modified by Eric Dumazet to avoid advancing
skb->datapast the end
and to use a temporary variable.]Signed-off-by Michal Schmidt <[email protected]>---
Eric,
I thinkskb->datais pretty much irrelevant at that point, because the skb's headlen is going to become zero, but admittedly it seems cleaner this way.
Thanks.net/core/skbuff.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)net/core/skbuff.c +0
-1@@ -2744,8 +2744,12 @@ int skb_gro_receive(struct sk_buff **head, struct sk_buff *skb) merge:if (offset > headlen) { - skbinfo->frags[0 ].page_offset += offset - headlen;
net/core/skbuff.c int skb_gro_receive(struct sk_buff **head, struct sk_buff *skb) · line 2755
Quoted 10 lines
net/core/skbuff.c +6
-1- skbinfo->frags[0 ].size -= offset - headlen; +unsigned int eat = offset - headlen; + + skbinfo->frags[0 ].page_offset += eat; + skbinfo->frags[0 ].size -= eat; + skb->data_len -= eat; + skb->len -= eat; offset = headlen; }
Thanks !
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Mon, 24 Jan 2011 23:22:25 +0100
Quoted 31 lines · Michal Schmidt
Quoted 30 lines
Suppose that several linear skbs of the same flow were received by GRO. They were thus merged into one skb with a
frag_list. Then a new skb of the same flow arrives, but it is a paged skb with data starting in its frags[].Before adding the skb to the
frag_listskb_gro_receive()will of course adjust the skb to throw away the headers. It correctly modifies thepage_offsetand size of the frag, but it leaves incorrect information in the skb:
->data_len is not decreased at all.
->len is decreased only by headlen, as if no change were done to the frag.
Later in a receiving process this causesskb_copy_datagram_iovec()to return-EFAULTand this is seen in userspace as the result of therecv()syscall.In practice the bug can be reproduced with the sfc driver. By default the driver uses an adaptive scheme when it switches between using
napi_gro_receive()(with skbs) andnapi_gro_frags()(with pages). The bug is reproduced when under rx load with enough successful GRO merging the driver decides to switch from the former to the latter.Manual control is also possible, so reproducing this is easy with netcat:
- on machine1 (with sfc): nc -l 12345 >/dev/null
- on machine2: nc machine1 12345 </dev/zero
- on machine1:
echo 1 >/sys/module/sfc/parameters/rx_alloc_method# use skbs echo 2 >/sys/module/sfc/parameters/rx_alloc_method# use pages
- See that nc has quit suddenly.[v2: Modified by Eric Dumazet to avoid advancing
skb->datapast the end
and to use a temporary variable.]Signed-off-by Michal Schmidt <[email protected]>
...
Quoted 1 line
Acked-by Eric Dumazet <[email protected]>
Applied and queued up for -stable, thanks!
Quoted 12 lines · Michal Schmidt
Suppose that several linear skbs of the same flow were received by GRO. They were thus merged into one skb with a
frag_list. Then a new skb of the same flow arrives, but it is a paged skb with data starting in its frags[].Before adding the skb to the
frag_listskb_gro_receive()will of course adjust the skb to throw away the headers. It correctly modifies thepage_offsetand size of the frag, but it leaves incorrect information in the skb:
->data_len is not decreased at all.
->len is decreased only by headlen, as if no change were done to the frag.
Later in a receiving process this causesskb_copy_datagram_iovec()to return-EFAULTand this is seen in userspace as the result of therecv()syscall.
Quoted 5 lines
In practice the bug can be reproduced with the sfc driver. By default the driver uses an adaptive scheme when it switches between using
napi_gro_receive()(with skbs) andnapi_gro_frags()(with pages). The bug is reproduced when under rx load with enough successful GRO merging the driver decides to switch from the former to the latter.
[...]
This is odd because I thought we made sure to flush before making such a change. Perhaps that got lost during the conversion from inet_lro to GRO?
Anyway, thanks very much for fixing this.
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Quoted 18 lines · Ben Hutchings
Quoted 12 lines · Michal Schmidt
Suppose that several linear skbs of the same flow were received by GRO. They were thus merged into one skb with a
frag_list. Then a new skb of the same flow arrives, but it is a paged skb with data starting in its frags[].Before adding the skb to the
frag_listskb_gro_receive()will of course adjust the skb to throw away the headers. It correctly modifies thepage_offsetand size of the frag, but it leaves incorrect information in the skb:
->data_len is not decreased at all.
->len is decreased only by headlen, as if no change were done to the frag.
Later in a receiving process this causesskb_copy_datagram_iovec()to return-EFAULTand this is seen in userspace as the result of therecv()syscall.Quoted 5 lines
In practice the bug can be reproduced with the sfc driver. By default the driver uses an adaptive scheme when it switches between using
napi_gro_receive()(with skbs) andnapi_gro_frags()(with pages). The bug is reproduced when under rx load with enough successful GRO merging the driver decides to switch from the former to the latter.
Quoted 5 lines
[...]
This is odd because I thought we made sure to flush before making such a change. Perhaps that got lost during the conversion from
inet_lroto GRO?
That is indeed the case; commit da3bc07171dff957906cbe2ad5abb443eccf57c4 made the following deletions:
- /* Both our generic-LRO and SFC-SSR support skb and page based
- * allocation, but neither support switching from one to the - * other on the fly. If we spot that the allocation mode has - * changed, then flush the LRO state. - */
- if (unlikely(channel->rx_alloc_pop_pages != (rx_buf->page != NULL))) {
- efx_flush_lro(channel);
- channel->rx_alloc_pop_pages = (rx_buf->page != NULL);
- }
Ben.
Quoted 4 lines
Anyway, thanks very much for fixing this.
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Review
Quoted 13 lines · Ben Hutchings
That is indeed the case; commit
da3bc07171dff957906cbe2ad5abb443eccf57c4made the following deletions:(quoted diff) +0
-9- /* Both our generic-LRO and SFC-SSR support skb and page based - * allocation, but neither support switching from one to the - * other on the fly. If we spot that the allocation mode has - * changed, then flush the LRO state. - */ - if (unlikely(channel->rx_alloc_pop_pages != (rx_buf->page != NULL))) { - efx_flush_lro(channel); - channel->rx_alloc_pop_pages = (rx_buf->page != NULL); - }
Oops, sorry about that.
How about changing skb_gro_receive to detect such switches and simply return an error, which should have the same effect as flushing that flow?
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 15 lines · Herbert Xu
Review
Quoted 13 lines · Ben Hutchings
That is indeed the case; commit
da3bc07171dff957906cbe2ad5abb443eccf57c4made the following deletions:(quoted diff) +0
-9- /* Both our generic-LRO and SFC-SSR support skb and page based - * allocation, but neither support switching from one to the - * other on the fly. If we spot that the allocation mode has - * changed, then flush the LRO state. - */ - if (unlikely(channel->rx_alloc_pop_pages != (rx_buf->page != NULL))) { - efx_flush_lro(channel); - channel->rx_alloc_pop_pages = (rx_buf->page != NULL); - }
Quoted 5 lines
Oops, sorry about that.
How about changing
skb_gro_receiveto detect such switches and simply return an error, which should have the same effect as flushing that flow?
That would work, though it looks like Michal has managed to make it tolerate switches. (I haven't yet tested the result myself.)
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Quoted 3 lines · Ben Hutchings
That would work, though it looks like Michal has managed to make it tolerate switches. (I haven't yet tested the result myself.)
Well the question is do we really want to still keep merging in case of a switch? It could potentially get messy if it switches back over and over again.
However, I suppose other merging criteria will stop the merging in such cases so it's probably not a big deal.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt