All of lore.kernel.org
 help / color / mirror / Atom feed
From: Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@kernel.org>
To: anton.ivanov@cambridgegreys.com, johannes@sipsolutions.net,
	 richard@nod.at
Cc: linux-kernel@vger.kernel.org, linux-um@lists.infradead.org
Subject: [PATCH] um: vector: Don't clean up NAPI that was never set up
Date: Thu, 19 Nov 2026 22:39:33 +0000	[thread overview]
Message-ID: <20261119-uml-vector-napi-v1-1-b3751cf4fa60@gmail.com> (raw)

From: Suyuan Wang <stevewong@hust.edu.cn>

vector_net_open() calls vector_net_close() on any failure once
vp->fds is set, and vector_net_close() then runs napi_disable() and
netif_napi_del() unconditionally. But the NAPI context is only added
and enabled after build_transport_data() and the header buffer
allocations, so a failure in any of those disables a NAPI context that
was never added. napi_disable() locks n->dev, which is still NULL:

  ip link set vec0 up   (vec0:transport=gre,...,rx_key=1, no tx_key)
  Kernel panic - not syncing: Kernel mode fault at addr 0x910
   napi_disable+0x4e/0x9e
   vector_net_close+0x2b9/0x87d
   vector_net_open+0x105d/0x106f
   __dev_open+0x244/0x334

Record in vp->napi_enabled whether vector_net_open() got as far as
enabling NAPI, and only disable and delete it in vector_net_close()
when it did. NAPI is still enabled only after the queues and buffers
that vector_poll() uses are set up.

Found with a static analysis tool and checked by hand.

Fixes: b35507a4cfb2 ("um: Migrate vector drivers to NAPI")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Tested with UML (seccomp=on) on top of the um fixes branch: with a GRE
vector device missing tx_key, "ip link set vec0 up" panics without the
patch and fails cleanly with -EINVAL with it, also when repeated. A raw
vector device on the host's lo still goes up and down twice as before.
---
 arch/um/drivers/vector_kern.c | 9 +++++++--
 arch/um/drivers/vector_kern.h | 1 +
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/um/drivers/vector_kern.c b/arch/um/drivers/vector_kern.c
index 8008278ccee7..021f14780b45 100644
--- a/arch/um/drivers/vector_kern.c
+++ b/arch/um/drivers/vector_kern.c
@@ -1137,8 +1137,12 @@ static int vector_net_close(struct net_device *dev)
 		um_free_irq(vp->tx_irq, dev);
 		vp->tx_irq = 0;
 	}
-	napi_disable(&vp->napi);
-	netif_napi_del(&vp->napi);
+	/* vector_net_open() may fail before setting up NAPI */
+	if (vp->napi_enabled) {
+		napi_disable(&vp->napi);
+		netif_napi_del(&vp->napi);
+		vp->napi_enabled = false;
+	}
 	if (vp->fds->rx_fd > 0) {
 		if (vp->bpf)
 			uml_vector_detach_bpf(vp->fds->rx_fd, vp->bpf);
@@ -1260,6 +1264,7 @@ static int vector_net_open(struct net_device *dev)
 		netif_napi_add_weight(vp->dev, &vp->napi, vector_poll, NAPI_POLL_WEIGHT);
 
 	napi_enable(&vp->napi);
+	vp->napi_enabled = true;
 
 	/* READ IRQ */
 	err = um_request_irq(
diff --git a/arch/um/drivers/vector_kern.h b/arch/um/drivers/vector_kern.h
index 5f0ceb80779d..e1b697266fa7 100644
--- a/arch/um/drivers/vector_kern.h
+++ b/arch/um/drivers/vector_kern.h
@@ -118,6 +118,7 @@ struct vector_private {
 
 	bool rexmit_scheduled;
 	bool opened;
+	bool napi_enabled;
 	bool in_write_poll;
 	bool in_error;
 






WARNING: multiple messages have this Message-ID (diff)
From: Suyuan Wang <shyckless@gmail.com>
To: anton.ivanov@cambridgegreys.com, johannes@sipsolutions.net,
	 richard@nod.at
Cc: linux-kernel@vger.kernel.org, linux-um@lists.infradead.org
Subject: [PATCH] um: vector: Don't clean up NAPI that was never set up
Date: Thu, 19 Nov 2026 22:39:33 +0000	[thread overview]
Message-ID: <20261119-uml-vector-napi-v1-1-b3751cf4fa60@gmail.com> (raw)

From: Suyuan Wang <stevewong@hust.edu.cn>

vector_net_open() calls vector_net_close() on any failure once
vp->fds is set, and vector_net_close() then runs napi_disable() and
netif_napi_del() unconditionally. But the NAPI context is only added
and enabled after build_transport_data() and the header buffer
allocations, so a failure in any of those disables a NAPI context that
was never added. napi_disable() locks n->dev, which is still NULL:

  ip link set vec0 up   (vec0:transport=gre,...,rx_key=1, no tx_key)
  Kernel panic - not syncing: Kernel mode fault at addr 0x910
   napi_disable+0x4e/0x9e
   vector_net_close+0x2b9/0x87d
   vector_net_open+0x105d/0x106f
   __dev_open+0x244/0x334

Record in vp->napi_enabled whether vector_net_open() got as far as
enabling NAPI, and only disable and delete it in vector_net_close()
when it did. NAPI is still enabled only after the queues and buffers
that vector_poll() uses are set up.

Found with a static analysis tool and checked by hand.

Fixes: b35507a4cfb2 ("um: Migrate vector drivers to NAPI")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Tested with UML (seccomp=on) on top of the um fixes branch: with a GRE
vector device missing tx_key, "ip link set vec0 up" panics without the
patch and fails cleanly with -EINVAL with it, also when repeated. A raw
vector device on the host's lo still goes up and down twice as before.
---
 arch/um/drivers/vector_kern.c | 9 +++++++--
 arch/um/drivers/vector_kern.h | 1 +
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/um/drivers/vector_kern.c b/arch/um/drivers/vector_kern.c
index 8008278ccee7..021f14780b45 100644
--- a/arch/um/drivers/vector_kern.c
+++ b/arch/um/drivers/vector_kern.c
@@ -1137,8 +1137,12 @@ static int vector_net_close(struct net_device *dev)
 		um_free_irq(vp->tx_irq, dev);
 		vp->tx_irq = 0;
 	}
-	napi_disable(&vp->napi);
-	netif_napi_del(&vp->napi);
+	/* vector_net_open() may fail before setting up NAPI */
+	if (vp->napi_enabled) {
+		napi_disable(&vp->napi);
+		netif_napi_del(&vp->napi);
+		vp->napi_enabled = false;
+	}
 	if (vp->fds->rx_fd > 0) {
 		if (vp->bpf)
 			uml_vector_detach_bpf(vp->fds->rx_fd, vp->bpf);
@@ -1260,6 +1264,7 @@ static int vector_net_open(struct net_device *dev)
 		netif_napi_add_weight(vp->dev, &vp->napi, vector_poll, NAPI_POLL_WEIGHT);
 
 	napi_enable(&vp->napi);
+	vp->napi_enabled = true;
 
 	/* READ IRQ */
 	err = um_request_irq(
diff --git a/arch/um/drivers/vector_kern.h b/arch/um/drivers/vector_kern.h
index 5f0ceb80779d..e1b697266fa7 100644
--- a/arch/um/drivers/vector_kern.h
+++ b/arch/um/drivers/vector_kern.h
@@ -118,6 +118,7 @@ struct vector_private {
 
 	bool rexmit_scheduled;
 	bool opened;
+	bool napi_enabled;
 	bool in_write_poll;
 	bool in_error;
 




             reply	other threads:[~2026-11-19 22:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 22:39 Suyuan Wang via B4 Relay [this message]
2026-11-19 22:39 ` [PATCH] um: vector: Don't clean up NAPI that was never set up Suyuan Wang
2026-11-20  7:27 ` Anton Ivanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119-uml-vector-napi-v1-1-b3751cf4fa60@gmail.com \
    --to=devnull+shyckless.gmail.com@kernel.org \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=shyckless@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.