Skip to content

Commit ae0605f

Browse files
atenartNipaLocal
authored andcommitted
net: vxlan: prevent NULL deref in vxlan_xmit_one
Neither sock4 nor sock6 pointers are guaranteed to be non-NULL in vxlan_xmit_one, e.g. if the iface is brought down. This can lead to the following NULL dereference: BUG: kernel NULL pointer dereference, address: 0000000000000010 Oops: Oops: 0000 [#1] SMP NOPTI RIP: 0010:vxlan_xmit_one+0xbb3/0x1580 Call Trace: vxlan_xmit+0x429/0x610 dev_hard_start_xmit+0x55/0xa0 __dev_queue_xmit+0x6d0/0x7f0 ip_finish_output2+0x24b/0x590 ip_output+0x63/0x110 Mentioned commits changed the code path in vxlan_xmit_one and as a side effect the sock4/6 pointer validity checks in vxlan(6)_get_route were lost. Fix this by adding back checks. Since both commits being fixed were released in the same version (v6.7) and are strongly related, bundle the fixes in a single commit. Reported-by: Liang Li <liali@redhat.com> Fixes: 6f19b2c ("vxlan: use generic function for tunnel IPv4 route lookup") Fixes: 2aceb89 ("vxlan: use generic function for tunnel IPv6 route lookup") Cc: Beniamino Galvani <b.galvani@gmail.com> Signed-off-by: Antoine Tenart <atenart@kernel.org> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Tested-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: NipaLocal <nipa@local>
1 parent d434741 commit ae0605f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

drivers/net/vxlan/vxlan_core.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,7 +2349,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
23492349
int addr_family;
23502350
__u8 tos, ttl;
23512351
int ifindex;
2352-
int err;
2352+
int err = 0;
23532353
u32 flags = vxlan->cfg.flags;
23542354
bool use_cache;
23552355
bool udp_sum = false;
@@ -2454,12 +2454,18 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
24542454

24552455
rcu_read_lock();
24562456
if (addr_family == AF_INET) {
2457-
struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock);
2457+
struct vxlan_sock *sock4;
24582458
u16 ipcb_flags = 0;
24592459
struct rtable *rt;
24602460
__be16 df = 0;
24612461
__be32 saddr;
24622462

2463+
sock4 = rcu_dereference(vxlan->vn4_sock);
2464+
if (unlikely(!sock4)) {
2465+
reason = SKB_DROP_REASON_DEV_READY;
2466+
goto tx_error;
2467+
}
2468+
24632469
if (!ifindex)
24642470
ifindex = sock4->sock->sk->sk_bound_dev_if;
24652471

@@ -2534,10 +2540,16 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
25342540
ipcb_flags);
25352541
#if IS_ENABLED(CONFIG_IPV6)
25362542
} else {
2537-
struct vxlan_sock *sock6 = rcu_dereference(vxlan->vn6_sock);
2543+
struct vxlan_sock *sock6;
25382544
struct in6_addr saddr;
25392545
u16 ip6cb_flags = 0;
25402546

2547+
sock6 = rcu_dereference(vxlan->vn6_sock);
2548+
if (unlikely(!sock6)) {
2549+
reason = SKB_DROP_REASON_DEV_READY;
2550+
goto tx_error;
2551+
}
2552+
25412553
if (!ifindex)
25422554
ifindex = sock6->sock->sk->sk_bound_dev_if;
25432555

0 commit comments

Comments
 (0)