Skip to content

Commit a257f09

Browse files
author
Paolo Abeni
committed
Merge branch 'net-gro-add-flush-flush_id-checks-and-fix-wrong-offset-in-udp'
Richard Gobert says: ==================== net: gro: add flush/flush_id checks and fix wrong offset in udp This series fixes a bug in the complete phase of UDP in GRO, in which socket lookup fails due to using network_header when parsing encapsulated packets. The fix is to add network_offset and inner_network_offset to napi_gro_cb and use these offsets for socket lookup. In addition p->flush/flush_id should be checked in all UDP flows. The same logic from tcp_gro_receive is applied for all flows in udp_gro_receive_segment. This prevents packets with mismatching network headers (flush/flush_id turned on) from merging in UDP GRO. The original series includes a change to vxlan test which adds the local parameter to prevent similar future bugs. I plan to submit it separately to net-next. This series is part of a previously submitted series to net-next: https://lore.kernel.org/all/[email protected]/ v3 -> v4: - Store network offsets, and use them only in udp_gro_complete flows - Correct commit hash used in Fixes tag - v3: https://lore.kernel.org/netdev/[email protected]/ v2 -> v3: - Add network_offsets and fix udp bug in a single commit to make backporting easier - Write to inner_network_offset in {inet,ipv6}_gro_receive - Use network_offsets union in tcp[46]_gro_complete as well - v2: https://lore.kernel.org/netdev/[email protected]/ v1 -> v2: - Use network_offsets instead of p_poff param as suggested by Willem - Check flush before postpull, and for all UDP GRO flows - v1: https://lore.kernel.org/netdev/[email protected]/ ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents fc1092f + 5babae7 commit a257f09

File tree

9 files changed

+33
-5
lines changed

9 files changed

+33
-5
lines changed

include/net/gro.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ struct napi_gro_cb {
8787

8888
/* used to support CHECKSUM_COMPLETE for tunneling protocols */
8989
__wsum csum;
90+
91+
/* L3 offsets */
92+
union {
93+
struct {
94+
u16 network_offset;
95+
u16 inner_network_offset;
96+
};
97+
u16 network_offsets[2];
98+
};
9099
};
91100

92101
#define NAPI_GRO_CB(skb) ((struct napi_gro_cb *)(skb)->cb)

net/8021q/vlan_core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ static struct sk_buff *vlan_gro_receive(struct list_head *head,
478478
if (unlikely(!vhdr))
479479
goto out;
480480

481+
NAPI_GRO_CB(skb)->network_offsets[NAPI_GRO_CB(skb)->encap_mark] = hlen;
482+
481483
type = vhdr->h_vlan_encapsulated_proto;
482484

483485
ptype = gro_find_receive_by_type(type);

net/core/gro.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ static inline void skb_gro_reset_offset(struct sk_buff *skb, u32 nhoff)
371371
const skb_frag_t *frag0;
372372
unsigned int headlen;
373373

374+
NAPI_GRO_CB(skb)->network_offset = 0;
374375
NAPI_GRO_CB(skb)->data_offset = 0;
375376
headlen = skb_headlen(skb);
376377
NAPI_GRO_CB(skb)->frag0 = skb->data;

net/ipv4/af_inet.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,7 @@ struct sk_buff *inet_gro_receive(struct list_head *head, struct sk_buff *skb)
15721572
/* The above will be needed by the transport layer if there is one
15731573
* immediately following this IP hdr.
15741574
*/
1575+
NAPI_GRO_CB(skb)->inner_network_offset = off;
15751576

15761577
/* Note : No need to call skb_gro_postpull_rcsum() here,
15771578
* as we already checked checksum over ipv4 header was 0

net/ipv4/udp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,8 @@ static inline struct sock *__udp4_lib_lookup_skb(struct sk_buff *skb,
532532
struct sock *udp4_lib_lookup_skb(const struct sk_buff *skb,
533533
__be16 sport, __be16 dport)
534534
{
535-
const struct iphdr *iph = ip_hdr(skb);
535+
const u16 offset = NAPI_GRO_CB(skb)->network_offsets[skb->encapsulation];
536+
const struct iphdr *iph = (struct iphdr *)(skb->data + offset);
536537
struct net *net = dev_net(skb->dev);
537538
int iif, sdif;
538539

net/ipv4/udp_offload.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ static struct sk_buff *udp_gro_receive_segment(struct list_head *head,
471471
struct sk_buff *p;
472472
unsigned int ulen;
473473
int ret = 0;
474+
int flush;
474475

475476
/* requires non zero csum, for symmetry with GSO */
476477
if (!uh->check) {
@@ -504,13 +505,22 @@ static struct sk_buff *udp_gro_receive_segment(struct list_head *head,
504505
return p;
505506
}
506507

508+
flush = NAPI_GRO_CB(p)->flush;
509+
510+
if (NAPI_GRO_CB(p)->flush_id != 1 ||
511+
NAPI_GRO_CB(p)->count != 1 ||
512+
!NAPI_GRO_CB(p)->is_atomic)
513+
flush |= NAPI_GRO_CB(p)->flush_id;
514+
else
515+
NAPI_GRO_CB(p)->is_atomic = false;
516+
507517
/* Terminate the flow on len mismatch or if it grow "too much".
508518
* Under small packet flood GRO count could elsewhere grow a lot
509519
* leading to excessive truesize values.
510520
* On len mismatch merge the first packet shorter than gso_size,
511521
* otherwise complete the GRO packet.
512522
*/
513-
if (ulen > ntohs(uh2->len)) {
523+
if (ulen > ntohs(uh2->len) || flush) {
514524
pp = p;
515525
} else {
516526
if (NAPI_GRO_CB(skb)->is_flist) {
@@ -718,7 +728,8 @@ EXPORT_SYMBOL(udp_gro_complete);
718728

719729
INDIRECT_CALLABLE_SCOPE int udp4_gro_complete(struct sk_buff *skb, int nhoff)
720730
{
721-
const struct iphdr *iph = ip_hdr(skb);
731+
const u16 offset = NAPI_GRO_CB(skb)->network_offsets[skb->encapsulation];
732+
const struct iphdr *iph = (struct iphdr *)(skb->data + offset);
722733
struct udphdr *uh = (struct udphdr *)(skb->data + nhoff);
723734

724735
/* do fraglist only if there is no outer UDP encap (or we already processed it) */

net/ipv6/ip6_offload.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ INDIRECT_CALLABLE_SCOPE struct sk_buff *ipv6_gro_receive(struct list_head *head,
237237
goto out;
238238

239239
skb_set_network_header(skb, off);
240+
NAPI_GRO_CB(skb)->inner_network_offset = off;
240241

241242
flush += ntohs(iph->payload_len) != skb->len - hlen;
242243

net/ipv6/udp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ static struct sock *__udp6_lib_lookup_skb(struct sk_buff *skb,
272272
struct sock *udp6_lib_lookup_skb(const struct sk_buff *skb,
273273
__be16 sport, __be16 dport)
274274
{
275-
const struct ipv6hdr *iph = ipv6_hdr(skb);
275+
const u16 offset = NAPI_GRO_CB(skb)->network_offsets[skb->encapsulation];
276+
const struct ipv6hdr *iph = (struct ipv6hdr *)(skb->data + offset);
276277
struct net *net = dev_net(skb->dev);
277278
int iif, sdif;
278279

net/ipv6/udp_offload.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ struct sk_buff *udp6_gro_receive(struct list_head *head, struct sk_buff *skb)
164164

165165
INDIRECT_CALLABLE_SCOPE int udp6_gro_complete(struct sk_buff *skb, int nhoff)
166166
{
167-
const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
167+
const u16 offset = NAPI_GRO_CB(skb)->network_offsets[skb->encapsulation];
168+
const struct ipv6hdr *ipv6h = (struct ipv6hdr *)(skb->data + offset);
168169
struct udphdr *uh = (struct udphdr *)(skb->data + nhoff);
169170

170171
/* do fraglist only if there is no outer UDP encap (or we already processed it) */

0 commit comments

Comments
 (0)