Skip to content

Commit 5188cd4

Browse files
bwhacksdavem330
authored andcommitted
drivers/net, ipv6: Select IPv6 fragment idents for virtio UFO packets
UFO is now disabled on all drivers that work with virtio net headers, but userland may try to send UFO/IPv6 packets anyway. Instead of sending with ID=0, we should select identifiers on their behalf (as we used to). Signed-off-by: Ben Hutchings <ben@decadent.org.uk> Fixes: 916e4cf ("ipv6: reuse ip6_frag_id from ip6_ufo_append_data") Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3d0ad09 commit 5188cd4

4 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎drivers/net/macvtap.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/idr.h>
1717
#include <linux/fs.h>
1818

19+
#include <net/ipv6.h>
1920
#include <net/net_namespace.h>
2021
#include <net/rtnetlink.h>
2122
#include <net/sock.h>
@@ -572,6 +573,8 @@ static int macvtap_skb_from_vnet_hdr(struct sk_buff *skb,
572573
pr_warn_once("macvtap: %s: using disabled UFO feature; please fix this program\n",
573574
current->comm);
574575
gso_type = SKB_GSO_UDP;
576+
if (skb->protocol == htons(ETH_P_IPV6))
577+
ipv6_proxy_select_ident(skb);
575578
break;
576579
default:
577580
return -EINVAL;

‎drivers/net/tun.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include <linux/nsproxy.h>
6666
#include <linux/virtio_net.h>
6767
#include <linux/rcupdate.h>
68+
#include <net/ipv6.h>
6869
#include <net/net_namespace.h>
6970
#include <net/netns/generic.h>
7071
#include <net/rtnetlink.h>
@@ -1139,6 +1140,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
11391140
break;
11401141
}
11411142

1143+
skb_reset_network_header(skb);
1144+
11421145
if (gso.gso_type != VIRTIO_NET_HDR_GSO_NONE) {
11431146
pr_debug("GSO!\n");
11441147
switch (gso.gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
@@ -1159,6 +1162,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
11591162
current->comm);
11601163
}
11611164
skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
1165+
if (skb->protocol == htons(ETH_P_IPV6))
1166+
ipv6_proxy_select_ident(skb);
11621167
break;
11631168
}
11641169
default:
@@ -1189,7 +1194,6 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
11891194
skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG;
11901195
}
11911196

1192-
skb_reset_network_header(skb);
11931197
skb_probe_transport_header(skb, 0);
11941198

11951199
rxhash = skb_get_hash(skb);

‎include/net/ipv6.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,8 @@ static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_add
671671
return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr));
672672
}
673673

674+
void ipv6_proxy_select_ident(struct sk_buff *skb);
675+
674676
int ip6_dst_hoplimit(struct dst_entry *dst);
675677

676678
static inline int ip6_sk_dst_hoplimit(struct ipv6_pinfo *np, struct flowi6 *fl6,

‎net/ipv6/output_core.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,45 @@
33
* not configured or static. These functions are needed by GSO/GRO implementation.
44
*/
55
#include <linux/export.h>
6+
#include <net/ip.h>
67
#include <net/ipv6.h>
78
#include <net/ip6_fib.h>
89
#include <net/addrconf.h>
910
#include <net/secure_seq.h>
1011

12+
/* This function exists only for tap drivers that must support broken
13+
* clients requesting UFO without specifying an IPv6 fragment ID.
14+
*
15+
* This is similar to ipv6_select_ident() but we use an independent hash
16+
* seed to limit information leakage.
17+
*
18+
* The network header must be set before calling this.
19+
*/
20+
void ipv6_proxy_select_ident(struct sk_buff *skb)
21+
{
22+
static u32 ip6_proxy_idents_hashrnd __read_mostly;
23+
struct in6_addr buf[2];
24+
struct in6_addr *addrs;
25+
u32 hash, id;
26+
27+
addrs = skb_header_pointer(skb,
28+
skb_network_offset(skb) +
29+
offsetof(struct ipv6hdr, saddr),
30+
sizeof(buf), buf);
31+
if (!addrs)
32+
return;
33+
34+
net_get_random_once(&ip6_proxy_idents_hashrnd,
35+
sizeof(ip6_proxy_idents_hashrnd));
36+
37+
hash = __ipv6_addr_jhash(&addrs[1], ip6_proxy_idents_hashrnd);
38+
hash = __ipv6_addr_jhash(&addrs[0], hash);
39+
40+
id = ip_idents_reserve(hash, 1);
41+
skb_shinfo(skb)->ip6_frag_id = htonl(id);
42+
}
43+
EXPORT_SYMBOL_GPL(ipv6_proxy_select_ident);
44+
1145
int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
1246
{
1347
u16 offset = sizeof(struct ipv6hdr);

0 commit comments

Comments
 (0)