vxlan: reject adding a remote to a nexthop fdb entry
Subsystems (3)
PATCH v2 1/1 vxlan: reject adding a remote to a nexthop fdb entry
FDB entries backed by a nexthop group must not carry a remote destination list. vxlan_fdb_update_existing() currently appends a remote via vxlan_fdb_append() on an NLM_F_APPEND request with a multicast or zero MAC even when the entry is backed by a nexthop, breaking that invariant through three different callers:
- "bridge fdb append" with a dst on a nexthop entry;
- "ip link set dev vx0 type vxlan remote <ip>" (vxlan_changelink());
- "bridge vni add/change ... group <mcast>" on a vnifilter device (vxlan_update_default_fdb_entry()).
All three reach the append block with nhid == 0 and a PERMANENT state, so they pass the earlier nexthop checks.
Reject the combination at the top of vxlan_fdb_update_existing(), next to the existing nexthop guards, so a refused request has no side effects: placing the check in the append block instead would return -EOPNOTSUPP only after the entry state and flags have been rewritten, skipping both the notification pass and the err_notify rollback.
Note the resulting behavior change for the two rtnetlink callers:
operations that previously succeeded while silently attaching an unused remote to a nexthop entry now fail with extack "Cannot add a remote to a nexthop fdb entry".
This issue was discovered by Tencent CodeBuddy Security.
---
v2: Move the check before the entry state/flags update, next to the
other nexthop guards, so a rejected request cannot leave the entry half-updated with notifications skipped (reported by sashiko, confirmed by Jakub); reword the extack message and document the behavior change for the vxlan_changelink() and vnifilter callers.
drivers/net/vxlan/vxlan_core.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/vxlan/vxlan_core.c +9 -0
@@ -1002,6 +1002,15 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan,return -EOPNOTSUPP ; } +if (rcu_access_pointer (f->nh) && + (flags &NLM_F_APPEND ) && + (is_multicast_ether_addr (f->key.eth_addr) || +is_zero_ether_addr (f->key.eth_addr))) { +NL_SET_ERR_MSG (extack, +"Cannot add a remote to a nexthop fdb entry" ); +return -EOPNOTSUPP ; + } +/* Do not allow an externally learned entry to take over an entry added * by the user. */
Signature · 1 line
2.43.7
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Quoted 26 lines · Henry Martin
FDB entries backed by a nexthop group must not carry a remote destination list.
vxlan_fdb_update_existing()currently appends a remote viavxlan_fdb_append()on anNLM_F_APPENDrequest with a multicast or zero MAC even when the entry is backed by a nexthop, breaking that invariant through three different callers:- "bridge fdb append" with a dst on a nexthop entry;
- "ip link set dev vx0 type vxlan remote <ip>" (vxlan_changelink());
- "bridge vni add/change ... group <mcast>" on a vnifilter device (vxlan_update_default_fdb_entry()).All three reach the append block with nhid == 0 and a PERMANENT state, so they pass the earlier nexthop checks.
Reject the combination at the top of
vxlan_fdb_update_existing(), next to the existing nexthop guards, so a refused request has no side effects: placing the check in the append block instead would return-EOPNOTSUPPonly after the entry state and flags have been rewritten, skipping both the notification pass and theerr_notifyrollback.Note the resulting behavior change for the two rtnetlink callers:
operations that previously succeeded while silently attaching an unused remote to a nexthop entry now fail with extack "Cannot add a remote to a nexthop fdb entry".
Quoted 5 lines
This issue was discovered by Tencent CodeBuddy Security.
Fixes 1274e1cc4226 ("vxlan: ecmp support for mac fdb entries")Signed-off-by Henry Martin <[email protected]>
I agree that it doesn't make sense to append a remote to an FDB entry that points to a nexthop, but what are the consequences of allowing it? Does this patch fix a crash / memory leak? If so, the commit message should describe it. Otherwise, this looks like net-next material (currently closed).
Also, please add a test case in fib_nexthops.sh, in a similar fashion to commit 98fc57d16744 ("vxlan: reject dynamic fdb entries that reference a nexthop id").
Thanks for the review.
No crash and no leak: the appended vxlan_rdst is freed with the entry, and vxlan_xmit() follows the nexthop whenever f->nh is set. What breaks is state consistency:
- vxlan_fdb_notify(), RTM_GETNEIGH dumps and the switchdev FDB programming all prefer the remote list over the nexthop, so user space is told traffic goes to the appended remote while the datapath follows the nexthop group.
- Once a stray remote is attached to an all-zeros nexthop entry, __vxlan_fdb_delete() destroys the whole entry when the matched remote is the only one on the list, so a dst-scoped "bridge fdb del ..." or "ip link set ... remote 0.0.0.0" tears down the nexthop entry, not just the stray remote. Same class of inconsistency as commit 98fc57d16744.
Test cases added to fib_nexthops.sh in both ipv4_fdb_grp_fcnal() and ipv6_fdb_grp_fcnal(), mirroring 98fc57d16744's style (rejected append and rejected non-unicast replace on a nexthop entry).
A sashiko pass on v2 also caught that the rejection would leave "bridge vni add" half-installed, so v4 is a 2-patch series: [1/2] the fdb guard with the above message and tests, [2/2] a pre-install rejection in vxlan_vni_add(). If the consequence description still reads as net-next-only to you, I will re-send there once it reopens.
pw-bot: cr
Regards,
Henry
Quoted 43 lines · Ido Schimmel <[email protected]> 于2026年10月21日周三 18:26写道:
Quoted 26 lines · Henry Martin
FDB entries backed by a nexthop group must not carry a remote destination list.
vxlan_fdb_update_existing()currently appends a remote viavxlan_fdb_append()on anNLM_F_APPENDrequest with a multicast or zero MAC even when the entry is backed by a nexthop, breaking that invariant through three different callers:- "bridge fdb append" with a dst on a nexthop entry;
- "ip link set dev vx0 type vxlan remote <ip>" (vxlan_changelink());
- "bridge vni add/change ... group <mcast>" on a vnifilter device (vxlan_update_default_fdb_entry()).All three reach the append block with nhid == 0 and a PERMANENT state, so they pass the earlier nexthop checks.
Reject the combination at the top of
vxlan_fdb_update_existing(), next to the existing nexthop guards, so a refused request has no side effects: placing the check in the append block instead would return-EOPNOTSUPPonly after the entry state and flags have been rewritten, skipping both the notification pass and theerr_notifyrollback.Note the resulting behavior change for the two rtnetlink callers:
operations that previously succeeded while silently attaching an unused remote to a nexthop entry now fail with extack "Cannot add a remote to a nexthop fdb entry".Quoted 5 lines
This issue was discovered by Tencent CodeBuddy Security.
Fixes 1274e1cc4226 ("vxlan: ecmp support for mac fdb entries")Signed-off-by Henry Martin <[email protected]>I agree that it doesn't make sense to append a remote to an FDB entry that points to a nexthop, but what are the consequences of allowing it? Does this patch fix a crash / memory leak? If so, the commit message should describe it. Otherwise, this looks like net-next material (currently closed).
Also, please add a test case in
fib_nexthops.sh, in a similar fashion to commit98fc57d16744("vxlan: reject dynamic fdb entries that reference a nexthop id").
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 (1) · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The new rejection makes a VNI add on a vnifilter device fail every time, and the failure leaves the VNI half-installed.
- [Low] The commit message understates the user-visible harm of the bug it fixes.
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but it is the same half-update the patch avoids for its own check.
--
vxlan: reject adding a remote to a nexthop fdb entry
This patch adds a check near the top of vxlan_fdb_update_existing(). The check rejects NLM_F_APPEND requests on multicast or all-zeros fdb entries that are backed by a nexthop. As a result, bridge fdb append, vxlan_changelink() and the vnifilter default fdb update path now fail with -EOPNOTSUPP instead of silently appending a remote.
Quoted 4 lines
Note the resulting behavior change for the two rtnetlink callers:
operations that previously succeeded while silently attaching an unused remote to a nexthop entry now fail with extack "Cannot add a remote to a nexthop fdb entry".
[Severity: Low]
Is "unused" accurate here? vxlan_xmit() ignores f->remotes when f->nh is set. However, __vxlan_fdb_delete() destroys the whole fdb entry when the matched rdst is the only one on f->remotes:
drivers/net/vxlan/vxlan_core.c:__vxlan_fdb_delete() {
...
if (rd && !list_is_singular(&f->remotes)) {
vxlan_fdb_dst_destroy(vxlan, f, rd, swdev_notify);
goto out;
}
vxlan_fdb_destroy(vxlan, f, true, swdev_notify);
...
}Say a stray remote B has been appended to a nexthop-backed all-zeros entry. Either of these then removes the whole nexthop entry, not just the stray remote:
ip link set vx0 type vxlan remote 0.0.0.0
(vxlan_changelink()->__vxlan_fdb_delete())
bridge fdb del 00:00:00:00:00:00 dev vx0 dst B
Without the stray remote, a dst-qualified delete finds no rdst and does nothing.
This is Cc: stable and makes previously successful rtnetlink operations fail. Could the commit message describe this concrete consequence?
Quoted 6 lines
drivers/net/vxlan/vxlan_core.c +0
-0@@ -1011,6 +1011,15 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan,return -EOPNOTSUPP ;
drivers/net/vxlan/vxlan_core.c static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan, · line 1021
Quoted 10 lines
drivers/net/vxlan/vxlan_core.c +8
-0} +if (rcu_access_pointer (f->nh) && + (flags &NLM_F_APPEND ) && + (is_multicast_ether_addr (f->key.eth_addr) || +is_zero_ether_addr (f->key.eth_addr))) { +NL_SET_ERR_MSG (extack, +"Cannot add a remote to a nexthop fdb entry" ); +return -EOPNOTSUPP ; + }
[Severity: Medium]
The commit message says the check goes here "so a refused request has no side effects". That holds inside vxlan_fdb_update_existing(). Does it also hold for the vnifilter caller the commit message lists?
vxlan_vni_add() in drivers/net/vxlan/vxlan_vnifilter.c installs the new VNI before it touches the default fdb entry:
drivers/net/vxlan/vxlan_vnifilter.c:vxlan_vni_add() {
...
err = rhashtable_lookup_insert_fast(&vg->vni_hash,
&vninode->vnode,
vxlan_vni_rht_params);
...
__vxlan_vni_add_list(vxlan, vg, vninode);
if (vxlan->dev->flags & IFF_UP)
vxlan_vs_add_del_vninode(vxlan, vninode, false);
err = vxlan_vni_update_group(vxlan, vninode, group, true, &changed,
extack);
vxlan_vnifilter_notify(vxlan, vninode, RTM_NEWTUNNEL);
return err;
}Suppose a nexthop-backed all-zeros fdb entry already exists for src_vni N. This chain now returns -EOPNOTSUPP:
vxlan_vni_add()
vxlan_vni_update_group()
vxlan_update_default_fdb_entry()
vxlan_fdb_update(all_zeros_mac, NLM_F_APPEND | NLM_F_CREATE)
vxlan_fdb_update_existing()
vxlan_vni_update_group() returns before it stores vninode->remote_ip and before vxlan_igmp_join(). vxlan_vni_add() still sends RTM_NEWTUNNEL, and nothing undoes the hash insert, the list add or the socket attach.
Would "bridge vni add vni N dev vx0" then report failure to user space while VNI N stays installed? The VNI would be attached to the socket and announced to listeners, but with no group stored and no multicast join. Before this patch the same request succeeded.
Such an entry can be created with:
bridge fdb add 00:00:00:00:00:00 dev vx0 nhid X src_vni N self permanent
This works because vxlan_fdb_parse() doesn't check that NDA_SRC_VNI is a configured VNI. The entry can also be left behind by adding VNI N, adding the nexthop entry, and then deleting VNI N.
The missing unwind in vxlan_vni_add() predates this patch. Before, it was only reachable on -ENOMEM or notify failures. This patch gives user space a deterministic way to reach it.
Would it make sense to check for the nexthop entry before the VNI is installed, or to roll back the insertion before notifying?
The trigger also looks wider than the "group <mcast>" in the commit message. When no group is given, vxlan_vni_update_group() falls back to cfg->remote_ip:
if (group && !vxlan_addr_any(group)) {
newrip = group;
} else {
if (!vxlan_addr_any(&cfg->remote_ip))
newrip = &cfg->remote_ip;
}vxlan_update_default_fdb_entry() accepts any non-any address. So a plain "bridge vni add vni N" on a device with a default remote would hit this too, and so would a unicast group.
drivers/net/vxlan/vxlan_core.c static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan, · line 1016
Quoted 4 lines
drivers/net/vxlan/vxlan_core.c +1
-0+/* Do not allow an externally learned entry to take over an entry added * by the user. */
[Severity: Medium]
This is a pre-existing issue that this patch didn't introduce. It is the same half-update the commit message says the new check avoids.
Take an NLM_F_REPLACE request on an existing zero or multicast MAC entry. The block below this comment overwrites f->state and f->flags and sets notify = 1:
if (!(fdb_flags & NTF_EXT_LEARNED) ||
!(f->flags & NTF_VXLAN_ADDED_BY_USER)) {
if (f->state != state) {
f->state = state;
notify = 1;
}
...
}The NLM_F_REPLACE branch then returns directly for the non-unicast MAC:
} else {
NL_SET_ERR_MSG(extack, "Cannot replace non-unicast fdb entries");
return -EOPNOTSUPP;
}That return skips the RTM_NEWNEIGH and switchdev notification. It also skips the err_notify rollback.
For example, take this command with a state or ndm flags that differ from the existing default entry:
bridge fdb replace 00:00:00:00:00:00 dev vx0 dst X self permanent
It would fail, but the entry's state and flags would already have changed, and neither listeners nor offload would be told.
Could the non-unicast REPLACE check also move up next to the other guards?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261020034531.1420194-1-bsdhenrymartin%40gmail.com