Skip to contentSkip to conversation

tuntap: properly align skb->head before building skb

PATCH Superseded Jason Wang 2 participants 3 messages Oct 26, 2017 – Oct 27, 2017

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 1/1 tuntap: properly align skb->head before building skb

An unaligned alloc_frag->offset caused by previous allocation will result an unaligned skb->head. This will lead unaligned skb_shared_info and then unaligned dataref which requires to be aligned for accessing on some architecture. Fix this by aligning alloc_frag->offset before the frag refilling.

Fixes 0bbd7dad34f8 ("tun: make tun_build_skb() thread safe")
Cc Eric Dumazet <[email protected]>
Cc Willem de Bruijn <[email protected]>
Cc Wei Wei <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc Mark Rutland <[email protected]>

---
- The patch is needed for -stable.
- Wei, can you try this patch to see if it solves your issue?

---
 drivers/net/tun.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/tun.c +1 -0
index b9973fb..60e44f2 100644
@@ -1286,6 +1286,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
 	buflen += SKB_DATA_ALIGN(len + pad);
 	rcu_read_unlock();
 
+	alloc_frag->offset = ALIGN((u64)alloc_frag->offset, TUN_RX_PAD);
 	if (unlikely(!skb_page_frag_refill(buflen, alloc_frag, GFP_KERNEL)))
 		return ERR_PTR(-ENOMEM);
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 26 lines · Jason Wang

An unaligned alloc_frag->offset caused by previous allocation will result an unaligned skb->head. This will lead unaligned skb_shared_info and then unaligned dataref which requires to be aligned for accessing on some architecture. Fix this by aligning alloc_frag->offset before the frag refilling.

Fixes 0bbd7dad34f8 ("tun: make tun_build_skb() thread safe")
Cc Eric Dumazet <[email protected]>
Cc Willem de Bruijn <[email protected]>
Cc Wei Wei <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc Mark Rutland <[email protected]>

---
- The patch is needed for -stable.
- Wei, can you try this patch to see if it solves your issue?

---
 drivers/net/tun.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/tun.c +0 -0
index b9973fb..60e44f2 100644

drivers/net/tun.c static struct sk_buff *tun_build_skb(struct tun_struct *tun, · line 1289

Quoted 4 lines
drivers/net/tun.c +1 -0
@@ -1286,6 +1286,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
        buflen += SKB_DATA_ALIGN(len + pad);
        rcu_read_unlock();
 
+       alloc_frag->offset = ALIGN((u64)alloc_frag->offset, TUN_RX_PAD);

You have to align to one cache line (SMP_CACHE_BYTES), or SKB_DATA_ALIGN(1)

Then eventually use skb_reserve() for NET_IP_ALIGN, but I guess it is already done.

author
#2 lore raw
Quoted 30 lines · Eric Dumazet
Quoted 29 lines · Jason Wang

An unaligned alloc_frag->offset caused by previous allocation will result an unaligned skb->head. This will lead unaligned skb_shared_info and then unaligned dataref which requires to be aligned for accessing on some architecture. Fix this by aligning alloc_frag->offset before the frag refilling.

Fixes 0bbd7dad34f8 ("tun: make tun_build_skb() thread safe")
Cc Eric Dumazet <[email protected]>
Cc Willem de Bruijn <[email protected]>
Cc Wei Wei <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc Mark Rutland <[email protected]>

---
- The patch is needed for -stable.
- Wei, can you try this patch to see if it solves your issue?

---
  drivers/net/tun.c | 1 +
  1 file changed, 1 insertion(+)
drivers/net/tun.c +0 -0
index b9973fb..60e44f2 100644
@@ -1286,6 +1286,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
         buflen += SKB_DATA_ALIGN(len + pad);
         rcu_read_unlock();
 
Quoted 2 lines

drivers/net/tun.c static struct sk_buff *tun_build_skb(struct tun_struct *tun, · line 1289

Quoted 1 line
drivers/net/tun.c +1 -0
+       alloc_frag->offset = ALIGN((u64)alloc_frag->offset, TUN_RX_PAD);

You have to align to one cache line (SMP_CACHE_BYTES), or SKB_DATA_ALIGN(1)

Oh right.

Quoted 2 lines

Then eventually use skb_reserve() for NET_IP_ALIGN, but I guess it is already done.

Yes.

Thanks