Commit a8fc8cb5 authored by Jakub Kicinski's avatar Jakub Kicinski

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.

Fixes: 94317099 ("tun: enable NAPI for TUN/TAP driver")
Acked-by: default avatarPetar Penkov <ppenkov@aviatrix.com>
Link: https://lore.kernel.org/r/20220623042105.2274812-1-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent cb8092d7
...@@ -273,6 +273,12 @@ static void tun_napi_init(struct tun_struct *tun, struct tun_file *tfile, ...@@ -273,6 +273,12 @@ static void tun_napi_init(struct tun_struct *tun, struct tun_file *tfile,
} }
} }
static void tun_napi_enable(struct tun_file *tfile)
{
if (tfile->napi_enabled)
napi_enable(&tfile->napi);
}
static void tun_napi_disable(struct tun_file *tfile) static void tun_napi_disable(struct tun_file *tfile)
{ {
if (tfile->napi_enabled) if (tfile->napi_enabled)
...@@ -653,8 +659,10 @@ static void __tun_detach(struct tun_file *tfile, bool clean) ...@@ -653,8 +659,10 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
if (clean) { if (clean) {
RCU_INIT_POINTER(tfile->tun, NULL); RCU_INIT_POINTER(tfile->tun, NULL);
sock_put(&tfile->sk); sock_put(&tfile->sk);
} else } else {
tun_disable_queue(tun, tfile); tun_disable_queue(tun, tfile);
tun_napi_disable(tfile);
}
synchronize_net(); synchronize_net();
tun_flow_delete_by_queue(tun, tun->numqueues + 1); tun_flow_delete_by_queue(tun, tun->numqueues + 1);
...@@ -808,6 +816,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file, ...@@ -808,6 +816,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file,
if (tfile->detached) { if (tfile->detached) {
tun_enable_queue(tfile); tun_enable_queue(tfile);
tun_napi_enable(tfile);
} else { } else {
sock_hold(&tfile->sk); sock_hold(&tfile->sk);
tun_napi_init(tun, tfile, napi, napi_frags); tun_napi_init(tun, tfile, napi, napi_frags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment