History

vxlan: reject dynamic fdb entries that reference a nexthop id

The commit cited in the Fixes tag allowed VXLAN FDB entries to point to FDB nexthops so that overlay traffic could be load balanced across multiple VTEPs. Such entries can only be configured from user space, cannot be learned and cannot roam. They only make sense with a user space control plane such as E-VPN where data plane learning is disabled. Despite that, the VXLAN driver does not currently prevent such entries from being configured with the "dynamic" flag. The per-nexthop FDB list is only protected by the per-device hash lock, which is not sufficient when two VXLAN devices point to the same FDB nexthop and therefore share the list. Aging runs in softirq context without RTNL, so an entry deleted by one device can race with an addition or deletion from the other, leading to list corruption: list_del corruption. next->prev should be ffff8881069d9548, but was dead000000000122. (next=ffff8881069d9448) WARNING: CPU: 0 PID: 90 at lib/list_debug.c:65 __list_del_entry_valid_or_report+0x1aa/0x210 ... vxlan_fdb_destroy+0x5b8/0xad0 vxlan_cleanup+0x328/0x450 call_timer_fn+0x2a/0x1c0 run_timer_softirq+0x18c/0x210 BUG: KASAN: slab-use-after-free in vxlan_fdb_destroy Fix this by rejecting the bogus configuration of dynamic FDB entries that point to FDB nexthops, both when created and when an existing entry is updated. As such, the per-nexthop FDB list is only ever mutated under the RTNL lock. Add test cases to make sure that this does not regress in the future.

Seungwon Bae committed 2 months ago

Commit 98fc57d1 parent 907a56a2 files · +39 −0Browse files

Unified · Split

2 files
  1. drivers/net/vxlan/vxlan_core.c +11 −0
  2. tools/testing/selftests/net/fib_nexthops.sh +28 −0
drivers/net/vxlan/vxlan_core.c+11−0
@@ -996,6 +996,12 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan, · 995 unmodified lines
996996 return -EOPNOTSUPP;
997997 }
998998
999+ if (rcu_access_pointer(f->nh) &&
1000+ !(state & (NUD_PERMANENT | NUD_NOARP))) {
1001+ NL_SET_ERR_MSG(extack, "Cannot make a nexthop fdb dynamic");
1002+ return -EOPNOTSUPP;
1003+ }
1004+
9991005 /* Do not allow an externally learned entry to take over an entry added
10001006 * by the user.
10011007 */
@@ -1257,6 +1263,11 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], · 255 unmodified lines
12571263 if (err)
12581264 return err;
12591265
1266+ if (nhid && !(ndm->ndm_state & (NUD_PERMANENT | NUD_NOARP))) {
1267+ NL_SET_ERR_MSG(extack, "A nexthop fdb cannot be dynamic");
1268+ return -EINVAL;
1269+ }
1270+
12601271 if (vxlan->default_dst.remote_ip.sa.sa_family != ip.sa.sa_family)
12611272 return -EAFNOSUPPORT;
12621273
tools/testing/selftests/net/fib_nexthops.sh+28−0
@@ -533,6 +533,20 @@ ipv6_fdb_grp_fcnal() · 532 unmodified lines
533533 run_cmd "$BRIDGE fdb add 02:02:00:00:00:14 dev vx10 nhid 61 self"
534534 log_test $? 255 "Fdb mac add with nexthop"
535535
536+ # fdb entries with a nexthop group cannot be aged out
537+ run_cmd "$BRIDGE fdb add 02:02:00:00:00:15 dev vx10 nhid 102 self static"
538+ log_test $? 0 "Fdb mac add with nexthop group and static state"
539+
540+ run_cmd "$BRIDGE fdb add 02:02:00:00:00:16 dev vx10 nhid 102 self dynamic"
541+ log_test $? 255 "Fdb mac add with nexthop group and dynamic state"
542+
543+ run_cmd "$BRIDGE fdb add 02:02:00:00:00:17 dev vx10 nhid 102 self"
544+ run_cmd "$BRIDGE fdb replace 02:02:00:00:00:17 dev vx10 dst 2001:db8:91::11 self dynamic"
545+ log_test $? 255 "Fdb mac replace with nexthop group and dynamic state"
546+
547+ run_cmd "$BRIDGE fdb append 02:02:00:00:00:17 dev vx10 dst 2001:db8:91::11 self dynamic"
548+ log_test $? 255 "Fdb mac append with nexthop group and dynamic state"
549+
536550 run_cmd "$IP -6 ro add 2001:db8:101::1/128 nhid 66"
537551 log_test $? 2 "Route add with fdb nexthop"
538552
@@ -669,6 +683,20 @@ ipv4_fdb_grp_fcnal() · 130 unmodified lines
669683 run_cmd "$BRIDGE fdb add 02:02:00:00:00:14 dev vx10 nhid 12 self"
670684 log_test $? 255 "Fdb mac add with nexthop"
671685
686+ # fdb entries with a nexthop group cannot be aged out
687+ run_cmd "$BRIDGE fdb add 02:02:00:00:00:15 dev vx10 nhid 102 self static"
688+ log_test $? 0 "Fdb mac add with nexthop group and static state"
689+
690+ run_cmd "$BRIDGE fdb add 02:02:00:00:00:16 dev vx10 nhid 102 self dynamic"
691+ log_test $? 255 "Fdb mac add with nexthop group and dynamic state"
692+
693+ run_cmd "$BRIDGE fdb add 02:02:00:00:00:17 dev vx10 nhid 102 self"
694+ run_cmd "$BRIDGE fdb replace 02:02:00:00:00:17 dev vx10 dst 10.0.0.3 self dynamic"
695+ log_test $? 255 "Fdb mac replace with nexthop group and dynamic state"
696+
697+ run_cmd "$BRIDGE fdb append 02:02:00:00:00:17 dev vx10 dst 10.0.0.3 self dynamic"
698+ log_test $? 255 "Fdb mac append with nexthop group and dynamic state"
699+
672700 run_cmd "$IP ro add 172.16.0.0/22 nhid 16"
673701 log_test $? 2 "Route add with fdb nexthop"
674702