History

net: tun: stop NAPI when detaching queues

While looking at a syzbot report I noticed the NAPI only gets disabled before it's deleted. I think that user can detach the queue before destroying the device and the NAPI will never be stopped.

Jakub Kicinski committed 4 years ago

Commit a8fc8cb1 parent cb8092d1 file · +10 −1Browse files

Unified · Split

drivers/net/tun.c+10−1
@@ -273,6 +273,12 @@ static void tun_napi_init(struct tun_struct *tun, struct tun_file *tfile, · 272 unmodified lines
273273 }
274274 }
275275
276+static void tun_napi_enable(struct tun_file *tfile)
277+{
278+ if (tfile->napi_enabled)
279+ napi_enable(&tfile->napi);
280+}
281+
276282 static void tun_napi_disable(struct tun_file *tfile)
277283 {
278284 if (tfile->napi_enabled)
@@ -653,8 +659,10 @@ static void __tun_detach(struct tun_file *tfile, bool clean) · 374 unmodified lines
653659 if (clean) {
654660 RCU_INIT_POINTER(tfile->tun, NULL);
655661 sock_put(&tfile->sk);
656− } else
662+ } else {
657663 tun_disable_queue(tun, tfile);
664+ tun_napi_disable(tfile);
665+ }
658666
659667 synchronize_net();
660668 tun_flow_delete_by_queue(tun, tun->numqueues + 1);
@@ -808,6 +816,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file, · 147 unmodified lines
808816
809817 if (tfile->detached) {
810818 tun_enable_queue(tfile);
819+ tun_napi_enable(tfile);
811820 } else {
812821 sock_hold(&tfile->sk);
813822 tun_napi_init(tun, tfile, napi, napi_frags);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t