Skip to content

Commit 787d7ac

Browse files
strssndktndavem330
authored andcommitted
udp: restrict offloads to one namespace
udp tunnel offloads tend to aggregate datagrams based on inner headers. gro engine gets notified by tunnel implementations about possible offloads. The match is solely based on the port number. Imagine a tunnel bound to port 53, the offloading will look into all DNS packets and tries to aggregate them based on the inner data found within. This could lead to data corruption and malformed DNS packets. While this patch minimizes the problem and helps an administrator to find the issue by querying ip tunnel/fou, a better way would be to match on the specific destination ip address so if a user space socket is bound to the same address it will conflict. Cc: Tom Herbert <tom@herbertland.com> Cc: Eric Dumazet <edumazet@google.com> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 07b9b37 commit 787d7ac

5 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎drivers/net/geneve.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ static void geneve_notify_add_rx_port(struct geneve_sock *gs)
376376
int err;
377377

378378
if (sa_family == AF_INET) {
379-
err = udp_add_offload(&gs->udp_offloads);
379+
err = udp_add_offload(sock_net(sk), &gs->udp_offloads);
380380
if (err)
381381
pr_warn("geneve: udp_add_offload failed with status %d\n",
382382
err);

‎drivers/net/vxlan.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ static void vxlan_notify_add_rx_port(struct vxlan_sock *vs)
621621
int err;
622622

623623
if (sa_family == AF_INET) {
624-
err = udp_add_offload(&vs->udp_offloads);
624+
err = udp_add_offload(net, &vs->udp_offloads);
625625
if (err)
626626
pr_warn("vxlan: udp_add_offload failed with status %d\n", err);
627627
}

‎include/net/protocol.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ int inet_del_offload(const struct net_offload *prot, unsigned char num);
107107
void inet_register_protosw(struct inet_protosw *p);
108108
void inet_unregister_protosw(struct inet_protosw *p);
109109

110-
int udp_add_offload(struct udp_offload *prot);
110+
int udp_add_offload(struct net *net, struct udp_offload *prot);
111111
void udp_del_offload(struct udp_offload *prot);
112112

113113
#if IS_ENABLED(CONFIG_IPV6)

‎net/ipv4/fou.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ static int fou_create(struct net *net, struct fou_cfg *cfg,
498498
sk->sk_allocation = GFP_ATOMIC;
499499

500500
if (cfg->udp_config.family == AF_INET) {
501-
err = udp_add_offload(&fou->udp_offloads);
501+
err = udp_add_offload(net, &fou->udp_offloads);
502502
if (err)
503503
goto error;
504504
}

‎net/ipv4/udp_offload.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static struct udp_offload_priv __rcu *udp_offload_base __read_mostly;
2121

2222
struct udp_offload_priv {
2323
struct udp_offload *offload;
24+
possible_net_t net;
2425
struct rcu_head rcu;
2526
struct udp_offload_priv __rcu *next;
2627
};
@@ -241,13 +242,14 @@ static struct sk_buff *udp4_ufo_fragment(struct sk_buff *skb,
241242
return segs;
242243
}
243244

244-
int udp_add_offload(struct udp_offload *uo)
245+
int udp_add_offload(struct net *net, struct udp_offload *uo)
245246
{
246247
struct udp_offload_priv *new_offload = kzalloc(sizeof(*new_offload), GFP_ATOMIC);
247248

248249
if (!new_offload)
249250
return -ENOMEM;
250251

252+
write_pnet(&new_offload->net, net);
251253
new_offload->offload = uo;
252254

253255
spin_lock(&udp_offload_lock);
@@ -311,7 +313,8 @@ struct sk_buff **udp_gro_receive(struct sk_buff **head, struct sk_buff *skb,
311313
rcu_read_lock();
312314
uo_priv = rcu_dereference(udp_offload_base);
313315
for (; uo_priv != NULL; uo_priv = rcu_dereference(uo_priv->next)) {
314-
if (uo_priv->offload->port == uh->dest &&
316+
if (net_eq(read_pnet(&uo_priv->net), dev_net(skb->dev)) &&
317+
uo_priv->offload->port == uh->dest &&
315318
uo_priv->offload->callbacks.gro_receive)
316319
goto unflush;
317320
}
@@ -389,7 +392,8 @@ int udp_gro_complete(struct sk_buff *skb, int nhoff)
389392

390393
uo_priv = rcu_dereference(udp_offload_base);
391394
for (; uo_priv != NULL; uo_priv = rcu_dereference(uo_priv->next)) {
392-
if (uo_priv->offload->port == uh->dest &&
395+
if (net_eq(read_pnet(&uo_priv->net), dev_net(skb->dev)) &&
396+
uo_priv->offload->port == uh->dest &&
393397
uo_priv->offload->callbacks.gro_complete)
394398
break;
395399
}

0 commit comments

Comments
 (0)