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
996 return -EOPNOTSUPP;996 return -EOPNOTSUPP;
997 }997 }
998 998
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
999 /* Do not allow an externally learned entry to take over an entry added1005 /* Do not allow an externally learned entry to take over an entry added
1000 * by the user.1006 * by the user.
1001 */1007 */
@@ -1257,6 +1263,11 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], · 255 unmodified lines
1257 if (err)1263 if (err)
1258 return err;1264 return err;
1259 1265
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
1260 if (vxlan->default_dst.remote_ip.sa.sa_family != ip.sa.sa_family)1271 if (vxlan->default_dst.remote_ip.sa.sa_family != ip.sa.sa_family)
1261 return -EAFNOSUPPORT;1272 return -EAFNOSUPPORT;
1262 1273
tools/testing/selftests/net/fib_nexthops.sh+28−0
@@ -533,6 +533,20 @@ ipv6_fdb_grp_fcnal() · 532 unmodified lines
533 run_cmd "$BRIDGE fdb add 02:02:00:00:00:14 dev vx10 nhid 61 self"533 run_cmd "$BRIDGE fdb add 02:02:00:00:00:14 dev vx10 nhid 61 self"
534 log_test $? 255 "Fdb mac add with nexthop"534 log_test $? 255 "Fdb mac add with nexthop"
535 535
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
536 run_cmd "$IP -6 ro add 2001:db8:101::1/128 nhid 66"550 run_cmd "$IP -6 ro add 2001:db8:101::1/128 nhid 66"
537 log_test $? 2 "Route add with fdb nexthop"551 log_test $? 2 "Route add with fdb nexthop"
538 552
@@ -669,6 +683,20 @@ ipv4_fdb_grp_fcnal() · 130 unmodified lines
669 run_cmd "$BRIDGE fdb add 02:02:00:00:00:14 dev vx10 nhid 12 self"683 run_cmd "$BRIDGE fdb add 02:02:00:00:00:14 dev vx10 nhid 12 self"
670 log_test $? 255 "Fdb mac add with nexthop"684 log_test $? 255 "Fdb mac add with nexthop"
671 685
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
672 run_cmd "$IP ro add 172.16.0.0/22 nhid 16"700 run_cmd "$IP ro add 172.16.0.0/22 nhid 16"
673 log_test $? 2 "Route add with fdb nexthop"701 log_test $? 2 "Route add with fdb nexthop"
674 702