Re: [PATCH net v2] ipvlan: update port flags only after ipvlan_set_port_mode() succeeds
From: Wenbo Sun
Date: Thu Nov 19 2026 - 22:24:40 EST
Hi Simon,
Thanks for flagging this. I analyzed `net/core/rtnetlink.c` and
`drivers/net/ipvlan/ipvlan_main.c` and reproduced all three scenarios in a
User-Mode Linux (UML) environment:
1. Root-Cause Analysis:
In `rtnl_newlink_create()`, after `ops->newlink()` (`ipvlan_link_new()`)
returns 0, `rtnl_configure_link()` (which clears
`dev->rtnl_link_initializing = false`) and `do_set_master()` (when
`IFLA_MASTER` is supplied) can still fail and jump to `out_unregister`,
which unwinds the newly created `net_device` via `ops->dellink()`
(`ipvlan_link_delete()`).
However, restoring `port->flags` (or `port->mode`) from
`ipvlan_link_delete()` as suggested in the AI review is not viable:
`rtnl_newlink_create()` invokes the exact same `ops->dellink()` callback as
a normal user `RTM_DELLINK` ("ip link del"). Because `dev->rtnl_link_initializing`
has already been cleared in `rtnl_configure_link()`, `ipvlan_link_delete()`
cannot distinguish a creation rollback from a normal link deletion, and
reverting shared port state on normal deletion would break ipvlan's
documented "latest update overrides" semantics across coexisting ipvlan
interfaces.
Note that `rtnl_changelink()` has the exact same rtnetlink transaction
boundary: `ops->changelink()` (`ipvlan_nl_changelink()`) updates
`port->mode` and `port->flags` before `do_setlink()` calls
`do_set_master()`, with no rollback callback if `do_set_master()` fails.
2. Local UML Reproduction Steps and Results:
Setup in UML (`CONFIG_IPVLAN=y`, `CONFIG_IPVLAN_L3S` unset):
ip link add veth0 type veth peer name veth0p
ip link set veth0 up && ip link set veth0p up
ip link add link veth0 name ipv1 type ipvlan mode l2 bridge
- Scenario 1 (Failure inside `ipvlan_link_new()` -> `ipvlan_set_port_mode()`,
fixed by this patch):
[S1 BEFORE] ipv1: ipvlan mode l2 bridge
$ ip link add link veth0 name ipv2 type ipvlan mode l3s private
RTNETLINK answers: Unknown error 524 (-ENOTSUPP)
[S1 AFTER] ipv1: ipvlan mode l2 bridge
With this patch, `port->flags` is untouched when `ipvlan_set_port_mode()`
fails inside `ipvlan_link_new()`.
- Scenario 2 (Post-newlink failure in `rtnl_newlink_create()` ->
`do_set_master()`):
[S2 BEFORE] ipv1: ipvlan mode l2 bridge
$ ip link add link veth0 name ipv2 master lo type ipvlan mode l3 private
RTNETLINK answers: Operation not supported (-EOPNOTSUPP)
[S2 AFTER] ipv1: ipvlan mode l3 private
Here `ipvlan_link_new()` succeeded and returned 0 (committing both
`port->mode = l3` and `port->flags = private`) before `do_set_master()`
failed in `rtnl_newlink_create()` and invoked `ops->dellink()`.
- Scenario 3 (Normal creation followed by normal `ip link del` via
`ops->dellink()`):
[S3 INIT] ipv1: ipvlan mode l2 bridge
$ ip link add link veth0 name ipv2 type ipvlan mode l2 vepa
[S3 AFTER ADD ipv2 (vepa)] ipv1: ipvlan mode l2 vepa
$ ip link del ipv2
[S3 AFTER DEL ipv2] ipv1: ipvlan mode l2 vepa
Normal `ip link del` calls the same `ops->dellink()` callback and must
preserve the updated `port->mode` and `port->flags`.
3. Action Taken (v3):
The v2 commit message overstated the guarantee by implying no failure paths
remained after `ipvlan_set_port_mode()` without qualifying that this
applies within `ipvlan_link_new()` itself. I will post a v3 that softens
and clarifies the commit message to explicitly scope the fix to
`ipvlan_link_new()` (matching `ipvlan_nl_changelink()`) and note that
post-`newlink` rollback in `rtnl_newlink_create()` via `ops->dellink()`
remains outside `ipvlan_link_new()`'s scope, just as for `port->mode`.
Thanks,
Wenbo
pw-bot: cr