netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2] net: fix NULL pointer dereference in l3mdev_l3_rcv
@ 2025-03-21  9:03 Wang Liang
  2025-03-23 19:35 ` Simon Horman
  2025-03-25 15:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Wang Liang @ 2025-03-21  9:03 UTC (permalink / raw)
  To: andrew+netdev, davem, edumazet, kuba, pabeni, dsahern, horms,
	gnault, daniel, fw
  Cc: yuehaibing, zhangchangzhong, wangliang74, netdev, linux-kernel

When delete l3s ipvlan:

    ip link del link eth0 ipvlan1 type ipvlan mode l3s

This may cause a null pointer dereference:

    Call trace:
     ip_rcv_finish+0x48/0xd0
     ip_rcv+0x5c/0x100
     __netif_receive_skb_one_core+0x64/0xb0
     __netif_receive_skb+0x20/0x80
     process_backlog+0xb4/0x204
     napi_poll+0xe8/0x294
     net_rx_action+0xd8/0x22c
     __do_softirq+0x12c/0x354

This is because l3mdev_l3_rcv() visit dev->l3mdev_ops after
ipvlan_l3s_unregister() assign the dev->l3mdev_ops to NULL. The process
like this:

    (CPU1)                     | (CPU2)
    l3mdev_l3_rcv()            |
      check dev->priv_flags:   |
        master = skb->dev;     |
                               |
                               | ipvlan_l3s_unregister()
                               |   set dev->priv_flags
                               |   dev->l3mdev_ops = NULL;
                               |
      visit master->l3mdev_ops |

To avoid this by do not set dev->l3mdev_ops when unregister l3s ipvlan.

Suggested-by: David Ahern <dsahern@kernel.org>
Fixes: c675e06a98a4 ("ipvlan: decouple l3s mode dependencies from other modes")
Signed-off-by: Wang Liang <wangliang74@huawei.com>
---
 drivers/net/ipvlan/ipvlan_l3s.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/ipvlan/ipvlan_l3s.c b/drivers/net/ipvlan/ipvlan_l3s.c
index b4ef386bdb1b..7c017fe35522 100644
--- a/drivers/net/ipvlan/ipvlan_l3s.c
+++ b/drivers/net/ipvlan/ipvlan_l3s.c
@@ -226,5 +226,4 @@ void ipvlan_l3s_unregister(struct ipvl_port *port)
 
 	dev->priv_flags &= ~IFF_L3MDEV_RX_HANDLER;
 	ipvlan_unregister_nf_hook(read_pnet(&port->pnet));
-	dev->l3mdev_ops = NULL;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net v2] net: fix NULL pointer dereference in l3mdev_l3_rcv
  2025-03-21  9:03 [PATCH net v2] net: fix NULL pointer dereference in l3mdev_l3_rcv Wang Liang
@ 2025-03-23 19:35 ` Simon Horman
  2025-03-25 15:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2025-03-23 19:35 UTC (permalink / raw)
  To: Wang Liang
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, dsahern, gnault,
	daniel, fw, yuehaibing, zhangchangzhong, netdev, linux-kernel

On Fri, Mar 21, 2025 at 05:03:53PM +0800, Wang Liang wrote:
> When delete l3s ipvlan:
> 
>     ip link del link eth0 ipvlan1 type ipvlan mode l3s
> 
> This may cause a null pointer dereference:
> 
>     Call trace:
>      ip_rcv_finish+0x48/0xd0
>      ip_rcv+0x5c/0x100
>      __netif_receive_skb_one_core+0x64/0xb0
>      __netif_receive_skb+0x20/0x80
>      process_backlog+0xb4/0x204
>      napi_poll+0xe8/0x294
>      net_rx_action+0xd8/0x22c
>      __do_softirq+0x12c/0x354
> 
> This is because l3mdev_l3_rcv() visit dev->l3mdev_ops after
> ipvlan_l3s_unregister() assign the dev->l3mdev_ops to NULL. The process
> like this:
> 
>     (CPU1)                     | (CPU2)
>     l3mdev_l3_rcv()            |
>       check dev->priv_flags:   |
>         master = skb->dev;     |
>                                |
>                                | ipvlan_l3s_unregister()
>                                |   set dev->priv_flags
>                                |   dev->l3mdev_ops = NULL;
>                                |
>       visit master->l3mdev_ops |
> 
> To avoid this by do not set dev->l3mdev_ops when unregister l3s ipvlan.
> 
> Suggested-by: David Ahern <dsahern@kernel.org>
> Fixes: c675e06a98a4 ("ipvlan: decouple l3s mode dependencies from other modes")
> Signed-off-by: Wang Liang <wangliang74@huawei.com>

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net v2] net: fix NULL pointer dereference in l3mdev_l3_rcv
  2025-03-21  9:03 [PATCH net v2] net: fix NULL pointer dereference in l3mdev_l3_rcv Wang Liang
  2025-03-23 19:35 ` Simon Horman
@ 2025-03-25 15:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-03-25 15:30 UTC (permalink / raw)
  To: Wang Liang
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, dsahern, horms,
	gnault, daniel, fw, yuehaibing, zhangchangzhong, netdev,
	linux-kernel

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 21 Mar 2025 17:03:53 +0800 you wrote:
> When delete l3s ipvlan:
> 
>     ip link del link eth0 ipvlan1 type ipvlan mode l3s
> 
> This may cause a null pointer dereference:
> 
>     Call trace:
>      ip_rcv_finish+0x48/0xd0
>      ip_rcv+0x5c/0x100
>      __netif_receive_skb_one_core+0x64/0xb0
>      __netif_receive_skb+0x20/0x80
>      process_backlog+0xb4/0x204
>      napi_poll+0xe8/0x294
>      net_rx_action+0xd8/0x22c
>      __do_softirq+0x12c/0x354
> 
> [...]

Here is the summary with links:
  - [net,v2] net: fix NULL pointer dereference in l3mdev_l3_rcv
    https://git.kernel.org/netdev/net/c/0032c99e83b9

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-25 15:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-21  9:03 [PATCH net v2] net: fix NULL pointer dereference in l3mdev_l3_rcv Wang Liang
2025-03-23 19:35 ` Simon Horman
2025-03-25 15:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).