Skip to contentSkip to conversation

net: tun: avoid disabling NAPI twice

PATCH Applied Jakub Kicinski 3 participants 4 messages Jun 29, 2022 – Jun 30, 2022

Subsystems (4)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/2 net: tun: avoid disabling NAPI twice

Eric reports that syzbot made short work out of my speculative fix. Indeed when queue gets detached its tfile->tun remains, so we would try to stop NAPI twice with a detach(), close() sequence.

Alternative fix would be to move tun_napi_disable() to tun_detach_all() and let the NAPI run after the queue has been detached.

Fixes a8fc8cb5692a ("net: tun: stop NAPI when detaching queues")

---
Cc: Petar Penkov <[email protected]>
---
CC: [email protected]

---
 drivers/net/tun.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/tun.c +2 -1
index e2eb35887394..259b2b84b2b3 100644
@@ -640,7 +640,8 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
 	tun = rtnl_dereference(tfile->tun);
 
 	if (tun && clean) {
-		tun_napi_disable(tfile);
+		if (!tfile->detached)
+			tun_napi_disable(tfile);
 		tun_napi_del(tfile);
 	}
 
Signature · 1 line
2.36.1
author maintainer
#1 lore raw

PATCH 2/2 selftest: tun: add test for NAPI dismantle

Being lazy does not pay, add the test for various
ordering of tun queue close / detach / destroy.

---
CC: [email protected]
CC: [email protected]

---
 tools/testing/selftests/net/Makefile |   2 +-
 tools/testing/selftests/net/tun.c    | 162 +++++++++++++++++++++++++++
 2 files changed, 163 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/net/tun.c
tools/testing/selftests/net/Makefile +1 -1
index 7ea54af55490..ddad703ace34 100644
@@ -54,7 +54,7 @@ TEST_GEN_FILES += ipsec
 TEST_GEN_FILES += ioam6_parser
 TEST_GEN_FILES += gro
 TEST_GEN_PROGS = reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
-TEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict tls
+TEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict tls tun
 TEST_GEN_FILES += toeplitz
 TEST_GEN_FILES += cmsg_sender
 TEST_GEN_FILES += stress_reuseport_listen
tools/testing/selftests/net/tun.c new file +162 -0

162 lines not on this page · raw message

Signature · 1 line
2.36.1
Reviewed-by on v1 1/2
#2 lore raw
In reply to Jakub Kicinski
Quoted 11 lines · Jakub Kicinski

Eric reports that syzbot made short work out of my speculative fix. Indeed when queue gets detached its tfile->tun remains, so we would try to stop NAPI twice with a detach(), close() sequence.

Alternative fix would be to move tun_napi_disable() to tun_detach_all() and let the NAPI run after the queue has been detached.

Fixes a8fc8cb5692a ("net: tun: stop NAPI when detaching queues")
Quoted 28 lines

---
Cc: Petar Penkov <[email protected]>
---
CC: [email protected]

---
 drivers/net/tun.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/tun.c +2 -2
index e2eb35887394..259b2b84b2b3 100644
@@ -640,7 +640,8 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
        tun = rtnl_dereference(tfile->tun);
 
        if (tun && clean) {
-               tun_napi_disable(tfile);
+               if (!tfile->detached)
+                       tun_napi_disable(tfile);
                tun_napi_del(tfile);
        }
 
--

2.36.1

#3 lore raw
In reply to Jakub Kicinski
This series was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Wed, 29 Jun 2022 11:19:10 -0700 you wrote:

Eric reports that syzbot made short work out of my speculative fix. Indeed when queue gets detached its tfile->tun remains, so we would try to stop NAPI twice with a detach(), close() sequence.

Alternative fix would be to move tun_napi_disable() to tun_detach_all() and let the NAPI run after the queue has been detached.

[...]

Here is the summary with links:
- [net,1/2] net: tun: avoid disabling NAPI twice

    https://git.kernel.org/netdev/net/c/ff1fa2081d17
  - [net,2/2] selftest: tun: add test for NAPI dismantle
    https://git.kernel.org/netdev/net/c/839b92fede7b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html