Skip to content

Commit

Permalink
net: tun: stop NAPI when detaching queues
Browse files Browse the repository at this point in the history
commit a8fc8cb upstream.

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: 9431709 ("tun: enable NAPI for TUN/TAP driver")
Acked-by: Petar Penkov <ppenkov@aviatrix.com>
Link: https://lore.kernel.org/r/20220623042105.2274812-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
kuba-moo authored and gregkh committed Jul 7, 2022
1 parent bec1be0 commit c70ca16
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,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)
{
if (tfile->napi_enabled)
Expand Down Expand Up @@ -659,8 +665,10 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
if (clean) {
RCU_INIT_POINTER(tfile->tun, NULL);
sock_put(&tfile->sk);
} else
} else {
tun_disable_queue(tun, tfile);
tun_napi_disable(tfile);
}

synchronize_net();
tun_flow_delete_by_queue(tun, tun->numqueues + 1);
Expand Down Expand Up @@ -814,6 +822,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file,

if (tfile->detached) {
tun_enable_queue(tfile);
tun_napi_enable(tfile);
} else {
sock_hold(&tfile->sk);
tun_napi_init(tun, tfile, napi, napi_frags);
Expand Down

0 comments on commit c70ca16

Please sign in to comment.