* [PATCH net] gro: ensure frag0 meets IP header alignment
@ 2021-04-13 12:41 Eric Dumazet
2021-04-13 12:58 ` Michael S. Tsirkin
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Eric Dumazet @ 2021-04-13 12:41 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski
Cc: netdev, Eric Dumazet, Eric Dumazet, Guenter Roeck, Xuan Zhuo,
Michael S. Tsirkin, Jason Wang
From: Eric Dumazet <edumazet@google.com>
After commit 0f6925b3e8da ("virtio_net: Do not pull payload in skb->head")
Guenter Roeck reported one failure in his tests using sh architecture.
After much debugging, we have been able to spot silent unaligned accesses
in inet_gro_receive()
The issue at hand is that upper networking stacks assume their header
is word-aligned. Low level drivers are supposed to reserve NET_IP_ALIGN
bytes before the Ethernet header to make that happen.
This patch hardens skb_gro_reset_offset() to not allow frag0 fast-path
if the fragment is not properly aligned.
Some arches like x86, arm64 and powerpc do not care and define NET_IP_ALIGN
as 0, this extra check will be a NOP for them.
Note that if frag0 is not used, GRO will call pskb_may_pull()
as many times as needed to pull network and transport headers.
Fixes: 0f6925b3e8da ("virtio_net: Do not pull payload in skb->head")
Fixes: 78a478d0efd9 ("gro: Inline skb_gro_header and cache frag0 virtual address")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Guenter Roeck <linux@roeck-us.net>
Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
---
net/core/dev.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/core/dev.c b/net/core/dev.c
index af8c1ea040b9364b076e2d72f04dc3de2d7e2f11..1f79b9aa9a3f2392fddd1401f95ad098b5e03204 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5924,7 +5924,8 @@ static void skb_gro_reset_offset(struct sk_buff *skb)
NAPI_GRO_CB(skb)->frag0_len = 0;
if (!skb_headlen(skb) && pinfo->nr_frags &&
- !PageHighMem(skb_frag_page(frag0))) {
+ !PageHighMem(skb_frag_page(frag0)) &&
+ (!NET_IP_ALIGN || !(skb_frag_off(frag0) & 3))) {
NAPI_GRO_CB(skb)->frag0 = skb_frag_address(frag0);
NAPI_GRO_CB(skb)->frag0_len = min_t(unsigned int,
skb_frag_size(frag0),
--
2.31.1.295.g9ea45b61b8-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net] gro: ensure frag0 meets IP header alignment
2021-04-13 12:41 [PATCH net] gro: ensure frag0 meets IP header alignment Eric Dumazet
@ 2021-04-13 12:58 ` Michael S. Tsirkin
2021-04-13 14:44 ` Guenter Roeck
2021-04-13 22:20 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2021-04-13 12:58 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Jakub Kicinski, netdev, Eric Dumazet,
Guenter Roeck, Xuan Zhuo, Jason Wang
On Tue, Apr 13, 2021 at 05:41:35AM -0700, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
>
> After commit 0f6925b3e8da ("virtio_net: Do not pull payload in skb->head")
> Guenter Roeck reported one failure in his tests using sh architecture.
>
> After much debugging, we have been able to spot silent unaligned accesses
> in inet_gro_receive()
>
> The issue at hand is that upper networking stacks assume their header
> is word-aligned. Low level drivers are supposed to reserve NET_IP_ALIGN
> bytes before the Ethernet header to make that happen.
>
> This patch hardens skb_gro_reset_offset() to not allow frag0 fast-path
> if the fragment is not properly aligned.
>
> Some arches like x86, arm64 and powerpc do not care and define NET_IP_ALIGN
> as 0, this extra check will be a NOP for them.
>
> Note that if frag0 is not used, GRO will call pskb_may_pull()
> as many times as needed to pull network and transport headers.
>
> Fixes: 0f6925b3e8da ("virtio_net: Do not pull payload in skb->head")
> Fixes: 78a478d0efd9 ("gro: Inline skb_gro_header and cache frag0 virtual address")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Jason Wang <jasowang@redhat.com>
Seems to make sense.
Acked-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> net/core/dev.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/core/dev.c b/net/core/dev.c
> index af8c1ea040b9364b076e2d72f04dc3de2d7e2f11..1f79b9aa9a3f2392fddd1401f95ad098b5e03204 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -5924,7 +5924,8 @@ static void skb_gro_reset_offset(struct sk_buff *skb)
> NAPI_GRO_CB(skb)->frag0_len = 0;
>
> if (!skb_headlen(skb) && pinfo->nr_frags &&
> - !PageHighMem(skb_frag_page(frag0))) {
> + !PageHighMem(skb_frag_page(frag0)) &&
> + (!NET_IP_ALIGN || !(skb_frag_off(frag0) & 3))) {
> NAPI_GRO_CB(skb)->frag0 = skb_frag_address(frag0);
> NAPI_GRO_CB(skb)->frag0_len = min_t(unsigned int,
> skb_frag_size(frag0),
> --
> 2.31.1.295.g9ea45b61b8-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] gro: ensure frag0 meets IP header alignment
2021-04-13 12:41 [PATCH net] gro: ensure frag0 meets IP header alignment Eric Dumazet
2021-04-13 12:58 ` Michael S. Tsirkin
@ 2021-04-13 14:44 ` Guenter Roeck
2021-04-13 22:20 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2021-04-13 14:44 UTC (permalink / raw)
To: Eric Dumazet, David S . Miller, Jakub Kicinski
Cc: netdev, Eric Dumazet, Xuan Zhuo, Michael S. Tsirkin, Jason Wang
On 4/13/21 5:41 AM, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
>
> After commit 0f6925b3e8da ("virtio_net: Do not pull payload in skb->head")
> Guenter Roeck reported one failure in his tests using sh architecture.
>
> After much debugging, we have been able to spot silent unaligned accesses
> in inet_gro_receive()
>
> The issue at hand is that upper networking stacks assume their header
> is word-aligned. Low level drivers are supposed to reserve NET_IP_ALIGN
> bytes before the Ethernet header to make that happen.
>
> This patch hardens skb_gro_reset_offset() to not allow frag0 fast-path
> if the fragment is not properly aligned.
>
> Some arches like x86, arm64 and powerpc do not care and define NET_IP_ALIGN
> as 0, this extra check will be a NOP for them.
>
> Note that if frag0 is not used, GRO will call pskb_may_pull()
> as many times as needed to pull network and transport headers.
>
> Fixes: 0f6925b3e8da ("virtio_net: Do not pull payload in skb->head")
> Fixes: 78a478d0efd9 ("gro: Inline skb_gro_header and cache frag0 virtual address")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Jason Wang <jasowang@redhat.com>
Nice catch.
Tested-by: Guenter Roeck <linux@roeck-us.net>
.... and thanks a lot for tracking this down!
Guenter
> ---
> net/core/dev.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/core/dev.c b/net/core/dev.c
> index af8c1ea040b9364b076e2d72f04dc3de2d7e2f11..1f79b9aa9a3f2392fddd1401f95ad098b5e03204 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -5924,7 +5924,8 @@ static void skb_gro_reset_offset(struct sk_buff *skb)
> NAPI_GRO_CB(skb)->frag0_len = 0;
>
> if (!skb_headlen(skb) && pinfo->nr_frags &&
> - !PageHighMem(skb_frag_page(frag0))) {
> + !PageHighMem(skb_frag_page(frag0)) &&
> + (!NET_IP_ALIGN || !(skb_frag_off(frag0) & 3))) {
> NAPI_GRO_CB(skb)->frag0 = skb_frag_address(frag0);
> NAPI_GRO_CB(skb)->frag0_len = min_t(unsigned int,
> skb_frag_size(frag0),
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] gro: ensure frag0 meets IP header alignment
2021-04-13 12:41 [PATCH net] gro: ensure frag0 meets IP header alignment Eric Dumazet
2021-04-13 12:58 ` Michael S. Tsirkin
2021-04-13 14:44 ` Guenter Roeck
@ 2021-04-13 22:20 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-04-13 22:20 UTC (permalink / raw)
To: Eric Dumazet
Cc: davem, kuba, netdev, edumazet, linux, xuanzhuo, mst, jasowang
Hello:
This patch was applied to netdev/net.git (refs/heads/master):
On Tue, 13 Apr 2021 05:41:35 -0700 you wrote:
> From: Eric Dumazet <edumazet@google.com>
>
> After commit 0f6925b3e8da ("virtio_net: Do not pull payload in skb->head")
> Guenter Roeck reported one failure in his tests using sh architecture.
>
> After much debugging, we have been able to spot silent unaligned accesses
> in inet_gro_receive()
>
> [...]
Here is the summary with links:
- [net] gro: ensure frag0 meets IP header alignment
https://git.kernel.org/netdev/net/c/38ec4944b593
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-04-13 22:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-13 12:41 [PATCH net] gro: ensure frag0 meets IP header alignment Eric Dumazet
2021-04-13 12:58 ` Michael S. Tsirkin
2021-04-13 14:44 ` Guenter Roeck
2021-04-13 22:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).