🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by Wenbo Sun Fri, 20 Nov 2026 03:24
[PATCH net v3] ipvlan: update port flags only after ipvlan_set_port_mode() succeeds
#19584
Author: Wenbo Sun
Date: Fri, 20 Nov 2026 03:24
83 lines
12461 bytes
In ipvlan_link_new(), port->flags is updated before calling
ipvlan_set_port_mode(). If ipvlan_set_port_mode() fails (for example,
when switching to L3S mode without CONFIG_IPVLAN_L3S), error unwinding
calls unregister_netdevice(dev) via unlink_netdev.

While unregister_netdevice(dev) destroys the port when creating the
first ipvlan device on a lower interface, struct ipvl_port is shared
across all ipvlan interfaces on the same lower device (tracked via
port->count). If another ipvlan interface already exists,
unregister_netdevice(dev) only drops the extra reference and leaves the
shared port alive with the updated port->flags, unintentionally altering
the flags of existing ipvlan interfaces.

Defer updating port->flags until after ipvlan_set_port_mode() succeeds
so that a failure inside ipvlan_link_new() does not modify port->flags,
matching ipvlan_nl_changelink(). Note that failures occurring in
rtnl_newlink_create() after ops->newlink() returns 0 (such as
do_set_master()) roll back via ops->dellink() (which shares the normal
RTM_DELLINK path and does not revert shared port->mode or port->flags)
and are outside the scope of ipvlan_link_new().

This issue was identified with the assistance of an LLM-based code
review tool, confirmed in a User-Mode Linux (UML) environment by
creating a second ipvlan interface that fails in ipvlan_set_port_mode(),
and verified in UML that the existing interface's port flags remain
unchanged upon failure inside ipvlan_link_new().

Fixes: a190d04db937 ("ipvlan: introduce 'private' attribute for all existing modes.")
Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
Signed-off-by: Wenbo Sun <sunwenbo@cmss.chinamobile.com>
---
v3:
  - Clarify in the commit message that deferring the port->flags update
    prevents failures inside ipvlan_link_new() from modifying
    port->flags (matching ipvlan_nl_changelink()), while noting that
    post-newlink failures in rtnl_newlink_create() (such as
    do_set_master()) unwind via ops->dellink() and remain outside the
    scope of ipvlan_link_new() (Simon Horman, Sashiko review).
  - Add Hangbin Liu's Reviewed-by tag (no code changes from v2).
v2: https://lore.kernel.org/netdev/20261112064821.85624-1-sunwenbo@cmss.chinamobile.com/
  - Clarify in the commit message that when creating a second or
    subsequent ipvlan interface on an already-active port,
    unregister_netdevice() only drops the extra reference rather than
    destroying the shared port (Hangbin Liu).
  - Soften and clarify the wording in the commit message.
v1: https://lore.kernel.org/netdev/20261111064655.233265-1-sunwenbo@cmss.chinamobile.com/

 drivers/net/ipvlan/ipvlan_main.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c
index f29864db662a..5732b167c5b3 100644
--- a/drivers/net/ipvlan/ipvlan_main.c
+++ b/drivers/net/ipvlan/ipvlan_main.c
@@ -678,12 +678,6 @@ int ipvlan_link_new(struct net_device *dev, struct rtnl_newlink_params *params,
 	if (err)
 		goto remove_ida;
 
-	/* Flags are per port and latest update overrides. User has
-	 * to be consistent in setting it just like the mode attribute.
-	 */
-	if (data && data[IFLA_IPVLAN_FLAGS])
-		port->flags = nla_get_u16(data[IFLA_IPVLAN_FLAGS]);
-
 	if (data && data[IFLA_IPVLAN_MODE])
 		mode = nla_get_u16(data[IFLA_IPVLAN_MODE]);
 
@@ -691,6 +685,12 @@ int ipvlan_link_new(struct net_device *dev, struct rtnl_newlink_params *params,
 	if (err)
 		goto unlink_netdev;
 
+	/* Flags are per port and latest update overrides. User has
+	 * to be consistent in setting it just like the mode attribute.
+	 */
+	if (data && data[IFLA_IPVLAN_FLAGS])
+		port->flags = nla_get_u16(data[IFLA_IPVLAN_FLAGS]);
+
 	mutex_lock(&port->pnodes_lock);
 	list_add_tail_rcu(&ipvlan->pnode, &port->ipvlans);
 	mutex_unlock(&port->pnodes_lock);
-- 
2.33.0
Re: [PATCH net v3] ipvlan: update port flags only after ipvlan_set_port_mode() succeeds
#23923
Author: Simon Horman
Date: Sat, 28 Nov 2026 15:27
43 lines
10210 bytes
On Fri, Nov 20, 2026 at 11:24:38AM +0800, Wenbo Sun wrote:
> In ipvlan_link_new(), port->flags is updated before calling
> ipvlan_set_port_mode(). If ipvlan_set_port_mode() fails (for example,
> when switching to L3S mode without CONFIG_IPVLAN_L3S), error unwinding
> calls unregister_netdevice(dev) via unlink_netdev.
> 
> While unregister_netdevice(dev) destroys the port when creating the
> first ipvlan device on a lower interface, struct ipvl_port is shared
> across all ipvlan interfaces on the same lower device (tracked via
> port->count). If another ipvlan interface already exists,
> unregister_netdevice(dev) only drops the extra reference and leaves the
> shared port alive with the updated port->flags, unintentionally altering
> the flags of existing ipvlan interfaces.
> 
> Defer updating port->flags until after ipvlan_set_port_mode() succeeds
> so that a failure inside ipvlan_link_new() does not modify port->flags,
> matching ipvlan_nl_changelink(). Note that failures occurring in
> rtnl_newlink_create() after ops->newlink() returns 0 (such as
> do_set_master()) roll back via ops->dellink() (which shares the normal
> RTM_DELLINK path and does not revert shared port->mode or port->flags)
> and are outside the scope of ipvlan_link_new().
> 
> This issue was identified with the assistance of an LLM-based code
> review tool, confirmed in a User-Mode Linux (UML) environment by
> creating a second ipvlan interface that fails in ipvlan_set_port_mode(),
> and verified in UML that the existing interface's port flags remain
> unchanged upon failure inside ipvlan_link_new().
> 
> Fixes: a190d04db937 ("ipvlan: introduce 'private' attribute for all existing modes.")
> Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
> Signed-off-by: Wenbo Sun <sunwenbo@cmss.chinamobile.com>
> ---
> v3:
>   - Clarify in the commit message that deferring the port->flags update
>     prevents failures inside ipvlan_link_new() from modifying
>     port->flags (matching ipvlan_nl_changelink()), while noting that
>     post-newlink failures in rtnl_newlink_create() (such as
>     do_set_master()) unwind via ops->dellink() and remain outside the
>     scope of ipvlan_link_new() (Simon Horman, Sashiko review).
>   - Add Hangbin Liu's Reviewed-by tag (no code changes from v2).

Reviewed-by: Simon Horman <horms@kernel.org>
Re: [PATCH net v3] ipvlan: update port flags only after ipvlan_set_port_mode() succeeds
#24223
Author: patchwork-bot+netdevbpf
Date: Sun, 29 Nov 2026 18:00
30 lines
9162 bytes
Hello:

This patch was applied to netdev/net.git (main)
by Willem de Bruijn <willemb@google.com>:

On Fri, 20 Nov 2026 11:24:38 +0800 you wrote:
> In ipvlan_link_new(), port->flags is updated before calling
> ipvlan_set_port_mode(). If ipvlan_set_port_mode() fails (for example,
> when switching to L3S mode without CONFIG_IPVLAN_L3S), error unwinding
> calls unregister_netdevice(dev) via unlink_netdev.
> 
> While unregister_netdevice(dev) destroys the port when creating the
> first ipvlan device on a lower interface, struct ipvl_port is shared
> across all ipvlan interfaces on the same lower device (tracked via
> port->count). If another ipvlan interface already exists,
> unregister_netdevice(dev) only drops the extra reference and leaves the
> shared port alive with the updated port->flags, unintentionally altering
> the flags of existing ipvlan interfaces.
> 
> [...]

Here is the summary with links:
  - [net,v3] ipvlan: update port flags only after ipvlan_set_port_mode() succeeds
    https://git.kernel.org/netdev/net/c/2dc773eeace2

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads