Skip to content

Commit d24ffec

Browse files
jasowangdavem330
authored andcommitted
tuntap: fix use after free during release
After commit 2ee5c10 ("tun: fix use after free for ptr_ring") we need clean up tx ring during release(). But unfortunately, it tries to do the cleanup blindly after socket were destroyed which will lead another use-after-free. Fix this by doing the cleanup before dropping the last reference of the socket in __tun_detach(). Reported-by: Andrei Vagin <[email protected]> Acked-by: Andrei Vagin <[email protected]> Fixes: 2ee5c10 ("tun: fix use after free for ptr_ring") Signed-off-by: Jason Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 390e8d1 commit d24ffec

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/net/tun.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
729729
}
730730
if (tun)
731731
xdp_rxq_info_unreg(&tfile->xdp_rxq);
732+
ptr_ring_cleanup(&tfile->tx_ring, tun_ptr_free);
732733
sock_put(&tfile->sk);
733734
}
734735
}
@@ -3245,7 +3246,6 @@ static int tun_chr_close(struct inode *inode, struct file *file)
32453246
struct tun_file *tfile = file->private_data;
32463247

32473248
tun_detach(tfile, true);
3248-
ptr_ring_cleanup(&tfile->tx_ring, tun_ptr_free);
32493249

32503250
return 0;
32513251
}

0 commit comments

Comments
 (0)