tun and tap store the opened file in a socket embedded in their own object, and never clear the pointer. A packet written to the fd keeps the socket alive, so the socket can outlive the file, and code that follows sk->sk_socket->file for a packet still in the stack after close() reads a freed struct file, a use-after-free. With tun, an unprivileged user can reach this from a user namespace and turn it into an arbitrary kernel memory read via nfnetlink_queue, which reports the uid and gid it reads through the freed file's f_cred. With tap a process needs to be able to access the /dev/tapN node to reach the bug. Patch 1 fixes tun and patch 2 fixes tap, both by clearing the pointer when the file is released. Both bugs were discovered during an LLM-based code review. Reproducers for both: github.com/AgusNicco/tun-tap-uaf Juan Agustin Niccolini (2): tun: clear the socket file pointer on release to fix a struct file UAF tap: clear the socket file pointer on release to fix a struct file UAF drivers/net/tap.c | 2 ++ drivers/net/tun.c | 1 + 2 files changed, 3 insertions(+) base-commit: 28a371228d4eb4857cc31eeb1a0d7d01e9c3ea2f
-- 2.53.0