mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] ncsi: Initialize vid in set_one_vid() to handle concurrent VLAN removal
@ 2026-11-19 17:10 Ian Rogers
  2026-11-25 12:31 ` Daniel Machon
  2026-11-25 16:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Ian Rogers @ 2026-11-19 17:10 UTC (permalink / raw)
  To: Samuel Mendoza-Jonas, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Paul Fertser, Simon Horman, netdev, linux-kernel, llvm,
	Elkin Cruz, Ian Rogers

set_one_vid() checks list_empty(&ndp->vlan_vids) before acquiring
nc->lock and rcu_read_lock(). If ncsi_vlan_rx_kill_vid() removes the
last VLAN entry in that window, list_for_each_entry_rcu() executes
zero iterations and leaves vid uninitialized on the stack. The
subsequent 'if (!vid)' check can then proceed and program stack
garbage into ncf->vids[index] and an NCSI_PKT_CMD_SVF command packet.

Initialize vid to 0 so that an empty RCU list cleanly hits 'if (!vid)'
and returns -1.

Found via Clang -Wconditional-uninitialized on an x86_64 allyesconfig
build. Verified by building net/ncsi/ncsi-manage.o with LLVM=1 W=1
(-Werror) and -Wconditional-uninitialized; not runtime-tested on NCSI
hardware.

Fixes: 062b3e1b6d4f ("net/ncsi: Refactor MAC, VLAN filters")
Signed-off-by: Ian Rogers <irogers@google.com>
---
 net/ncsi/ncsi-manage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
index 1d63958c4429..f7eca228c281 100644
--- a/net/ncsi/ncsi-manage.c
+++ b/net/ncsi/ncsi-manage.c
@@ -640,7 +640,7 @@ static int set_one_vid(struct ncsi_dev_priv *ndp, struct ncsi_channel *nc,
 	unsigned long flags;
 	int i, index;
 	void *bitmap;
-	u16 vid;
+	u16 vid = 0;
 
 	if (list_empty(&ndp->vlan_vids))
 		return -1;
-- 
2.56.1.708.g77570a6a1d-goog


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

* Re: [PATCH net] ncsi: Initialize vid in set_one_vid() to handle concurrent VLAN removal
  2026-11-19 17:10 [PATCH net] ncsi: Initialize vid in set_one_vid() to handle concurrent VLAN removal Ian Rogers
@ 2026-11-25 12:31 ` Daniel Machon
  2026-11-25 16:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Machon @ 2026-11-25 12:31 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Samuel Mendoza-Jonas, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Paul Fertser, Simon Horman, netdev,
	linux-kernel, llvm, Elkin Cruz

> set_one_vid() checks list_empty(&ndp->vlan_vids) before acquiring
> nc->lock and rcu_read_lock(). If ncsi_vlan_rx_kill_vid() removes the
> last VLAN entry in that window, list_for_each_entry_rcu() executes
> zero iterations and leaves vid uninitialized on the stack. The
> subsequent 'if (!vid)' check can then proceed and program stack
> garbage into ncf->vids[index] and an NCSI_PKT_CMD_SVF command packet.
> 
> Initialize vid to 0 so that an empty RCU list cleanly hits 'if (!vid)'
> and returns -1.
> 
> Found via Clang -Wconditional-uninitialized on an x86_64 allyesconfig
> build. Verified by building net/ncsi/ncsi-manage.o with LLVM=1 W=1
> (-Werror) and -Wconditional-uninitialized; not runtime-tested on NCSI
> hardware.
> 
> Fixes: 062b3e1b6d4f ("net/ncsi: Refactor MAC, VLAN filters")
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  net/ncsi/ncsi-manage.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
> index 1d63958c4429..f7eca228c281 100644
> --- a/net/ncsi/ncsi-manage.c
> +++ b/net/ncsi/ncsi-manage.c
> @@ -640,7 +640,7 @@ static int set_one_vid(struct ncsi_dev_priv *ndp, struct ncsi_channel *nc,
>  	unsigned long flags;
>  	int i, index;
>  	void *bitmap;
> -	u16 vid;
> +	u16 vid = 0;

I am not entirely sure, but can the list_empty check below be dropped as a
consequence of this change? Seems like the !vid check further down catches that
case now.

>  
>  	if (list_empty(&ndp->vlan_vids))
>  		return -1;
> -- 
> 2.56.1.708.g77570a6a1d-goog
> 

Either way:

Reviewed-by: Daniel Machon <daniel.machon@microchip.com>

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

* Re: [PATCH net] ncsi: Initialize vid in set_one_vid() to handle concurrent VLAN removal
  2026-11-19 17:10 [PATCH net] ncsi: Initialize vid in set_one_vid() to handle concurrent VLAN removal Ian Rogers
  2026-11-25 12:31 ` Daniel Machon
@ 2026-11-25 16:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-25 16:00 UTC (permalink / raw)
  To: Ian Rogers
  Cc: sam, davem, edumazet, kuba, pabeni, fercerpav, horms, netdev,
	linux-kernel, llvm, elkin

Hello:

This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Thu, 19 Nov 2026 09:10:09 -0800 you wrote:
> set_one_vid() checks list_empty(&ndp->vlan_vids) before acquiring
> nc->lock and rcu_read_lock(). If ncsi_vlan_rx_kill_vid() removes the
> last VLAN entry in that window, list_for_each_entry_rcu() executes
> zero iterations and leaves vid uninitialized on the stack. The
> subsequent 'if (!vid)' check can then proceed and program stack
> garbage into ncf->vids[index] and an NCSI_PKT_CMD_SVF command packet.
> 
> [...]

Here is the summary with links:
  - [net] ncsi: Initialize vid in set_one_vid() to handle concurrent VLAN removal
    https://git.kernel.org/netdev/net-next/c/e20f88c4f08b

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:[~2026-11-25 16:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 17:10 [PATCH net] ncsi: Initialize vid in set_one_vid() to handle concurrent VLAN removal Ian Rogers
2026-11-25 12:31 ` Daniel Machon
2026-11-25 16:00 ` 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

all inboxes | Powered by JetHome®