<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/drivers/net/tun.c, branch v6.1.87</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.1.87</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.1.87'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2024-03-06T14:45:06+00:00</updated>
<entry>
<title>tun: Fix xdp_rxq_info's queue_index when detaching</title>
<updated>2024-03-06T14:45:06+00:00</updated>
<author>
<name>Yunjian Wang</name>
<email>wangyunjian@huawei.com</email>
</author>
<published>2024-02-20T03:12:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=29360fd3288f3978ccde2f8f7eba22282c4a08a3'/>
<id>urn:sha1:29360fd3288f3978ccde2f8f7eba22282c4a08a3</id>
<content type='text'>
[ Upstream commit 2a770cdc4382b457ca3d43d03f0f0064f905a0d0 ]

When a queue(tfile) is detached, we only update tfile's queue_index,
but do not update xdp_rxq_info's queue_index. This patch fixes it.

Fixes: 8bf5c4ee1889 ("tun: setup xdp_rxq_info")
Signed-off-by: Yunjian Wang &lt;wangyunjian@huawei.com&gt;
Link: https://lore.kernel.org/r/1708398727-46308-1-git-send-email-wangyunjian@huawei.com
Signed-off-by: Jakub Kicinski &lt;kuba@kernel.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>tun: add missing rx stats accounting in tun_xdp_act</title>
<updated>2024-02-01T00:17:04+00:00</updated>
<author>
<name>Yunjian Wang</name>
<email>wangyunjian@huawei.com</email>
</author>
<published>2024-01-19T10:22:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=7a581f597a7887da70558a66eaca0373c77d0e68'/>
<id>urn:sha1:7a581f597a7887da70558a66eaca0373c77d0e68</id>
<content type='text'>
[ Upstream commit f1084c427f55d573fcd5688d9ba7b31b78019716 ]

The TUN can be used as vhost-net backend, and it is necessary to
count the packets transmitted from TUN to vhost-net/virtio-net.
However, there are some places in the receive path that were not
taken into account when using XDP. It would be beneficial to also
include new accounting for successfully received bytes using
dev_sw_netstats_rx_add.

Fixes: 761876c857cb ("tap: XDP support")
Signed-off-by: Yunjian Wang &lt;wangyunjian@huawei.com&gt;
Reviewed-by: Willem de Bruijn &lt;willemb@google.com&gt;
Acked-by: Jason Wang &lt;jasowang@redhat.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>tun: fix missing dropped counter in tun_xdp_act</title>
<updated>2024-02-01T00:17:04+00:00</updated>
<author>
<name>Yunjian Wang</name>
<email>wangyunjian@huawei.com</email>
</author>
<published>2024-01-19T10:22:35+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=41e7decdad0427016fe7179e2e5db484ffa9cd3c'/>
<id>urn:sha1:41e7decdad0427016fe7179e2e5db484ffa9cd3c</id>
<content type='text'>
[ Upstream commit 5744ba05e7c4bff8fec133dd0f9e51ddffba92f5 ]

The commit 8ae1aff0b331 ("tuntap: split out XDP logic") includes
dropped counter for XDP_DROP, XDP_ABORTED, and invalid XDP actions.
Unfortunately, that commit missed the dropped counter when error
occurs during XDP_TX and XDP_REDIRECT actions. This patch fixes
this issue.

Fixes: 8ae1aff0b331 ("tuntap: split out XDP logic")
Signed-off-by: Yunjian Wang &lt;wangyunjian@huawei.com&gt;
Reviewed-by: Willem de Bruijn &lt;willemb@google.com&gt;
Acked-by: Jason Wang &lt;jasowang@redhat.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>tun: prevent negative ifindex</title>
<updated>2023-10-25T10:03:06+00:00</updated>
<author>
<name>Eric Dumazet</name>
<email>edumazet@google.com</email>
</author>
<published>2023-10-16T18:08:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=9570bee67850785adfd9f2b928b3c479d97f3cef'/>
<id>urn:sha1:9570bee67850785adfd9f2b928b3c479d97f3cef</id>
<content type='text'>
commit cbfbfe3aee718dc4c3c837f5d2463170ee59d78c upstream.

After commit 956db0a13b47 ("net: warn about attempts to register
negative ifindex") syzbot is able to trigger the following splat.

Negative ifindex are not supported.

WARNING: CPU: 1 PID: 6003 at net/core/dev.c:9596 dev_index_reserve+0x104/0x210
Modules linked in:
CPU: 1 PID: 6003 Comm: syz-executor926 Not tainted 6.6.0-rc4-syzkaller-g19af4a4ed414 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/06/2023
pstate: 80400005 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : dev_index_reserve+0x104/0x210
lr : dev_index_reserve+0x100/0x210
sp : ffff800096a878e0
x29: ffff800096a87930 x28: ffff0000d04380d0 x27: ffff0000d04380f8
x26: ffff0000d04380f0 x25: 1ffff00012d50f20 x24: 1ffff00012d50f1c
x23: dfff800000000000 x22: ffff8000929c21c0 x21: 00000000ffffffea
x20: ffff0000d04380e0 x19: ffff800096a87900 x18: ffff800096a874c0
x17: ffff800084df5008 x16: ffff80008051f9c4 x15: 0000000000000001
x14: 1fffe0001a087198 x13: 0000000000000000 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000000 x9 : 0000000000000000
x8 : ffff0000d41c9bc0 x7 : 0000000000000000 x6 : 0000000000000000
x5 : ffff800091763d88 x4 : 0000000000000000 x3 : ffff800084e04748
x2 : 0000000000000001 x1 : 00000000fead71c7 x0 : 0000000000000000
Call trace:
dev_index_reserve+0x104/0x210
register_netdevice+0x598/0x1074 net/core/dev.c:10084
tun_set_iff+0x630/0xb0c drivers/net/tun.c:2850
__tun_chr_ioctl+0x788/0x2af8 drivers/net/tun.c:3118
tun_chr_ioctl+0x38/0x4c drivers/net/tun.c:3403
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:871 [inline]
__se_sys_ioctl fs/ioctl.c:857 [inline]
__arm64_sys_ioctl+0x14c/0x1c8 fs/ioctl.c:857
__invoke_syscall arch/arm64/kernel/syscall.c:37 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:51
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:136
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:155
el0_svc+0x58/0x16c arch/arm64/kernel/entry-common.c:678
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:595
irq event stamp: 11348
hardirqs last enabled at (11347): [&lt;ffff80008a716574&gt;] __raw_spin_unlock_irqrestore include/linux/spinlock_api_smp.h:151 [inline]
hardirqs last enabled at (11347): [&lt;ffff80008a716574&gt;] _raw_spin_unlock_irqrestore+0x38/0x98 kernel/locking/spinlock.c:194
hardirqs last disabled at (11348): [&lt;ffff80008a627820&gt;] el1_dbg+0x24/0x80 arch/arm64/kernel/entry-common.c:436
softirqs last enabled at (11138): [&lt;ffff8000887ca53c&gt;] spin_unlock_bh include/linux/spinlock.h:396 [inline]
softirqs last enabled at (11138): [&lt;ffff8000887ca53c&gt;] release_sock+0x15c/0x1b0 net/core/sock.c:3531
softirqs last disabled at (11136): [&lt;ffff8000887ca41c&gt;] spin_lock_bh include/linux/spinlock.h:356 [inline]
softirqs last disabled at (11136): [&lt;ffff8000887ca41c&gt;] release_sock+0x3c/0x1b0 net/core/sock.c:3518

Fixes: fb7589a16216 ("tun: Add ability to create tun device with given index")
Reported-by: syzbot &lt;syzkaller@googlegroups.com&gt;
Signed-off-by: Eric Dumazet &lt;edumazet@google.com&gt;
Reviewed-by: Willem de Bruijn &lt;willemb@google.com&gt;
Acked-by: Jason Wang &lt;jasowang@redhat.com&gt;
Link: https://lore.kernel.org/r/20231016180851.3560092-1-edumazet@google.com
Signed-off-by: Jakub Kicinski &lt;kuba@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>drivers: net: prevent tun_build_skb() to exceed the packet size limit</title>
<updated>2023-08-16T16:27:27+00:00</updated>
<author>
<name>Andrew Kanner</name>
<email>andrew.kanner@gmail.com</email>
</author>
<published>2023-08-03T18:59:48+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=eeb0e4c1dbdf21896a6d86b7b398e4f88bbdc6e7'/>
<id>urn:sha1:eeb0e4c1dbdf21896a6d86b7b398e4f88bbdc6e7</id>
<content type='text'>
commit 59eeb232940515590de513b997539ef495faca9a upstream.

Using the syzkaller repro with reduced packet size it was discovered
that XDP_PACKET_HEADROOM is not checked in tun_can_build_skb(),
although pad may be incremented in tun_build_skb(). This may end up
with exceeding the PAGE_SIZE limit in tun_build_skb().

Jason Wang &lt;jasowang@redhat.com&gt; proposed to count XDP_PACKET_HEADROOM
always (e.g. without rcu_access_pointer(tun-&gt;xdp_prog)) in
tun_can_build_skb() since there's a window during which XDP program
might be attached between tun_can_build_skb() and tun_build_skb().

Fixes: 7df13219d757 ("tun: reserve extra headroom only when XDP is set")
Link: https://syzkaller.appspot.com/bug?extid=f817490f5bd20541b90a
Signed-off-by: Andrew Kanner &lt;andrew.kanner@gmail.com&gt;
Link: https://lore.kernel.org/r/20230803185947.2379988-1-andrew.kanner@gmail.com
Signed-off-by: Jakub Kicinski &lt;kuba@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>net: tun_chr_open(): set sk_uid from current_fsuid()</title>
<updated>2023-08-11T10:08:20+00:00</updated>
<author>
<name>Laszlo Ersek</name>
<email>lersek@redhat.com</email>
</author>
<published>2023-07-31T16:42:36+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=b6846d7c408b33e4701f4f5ca28932e2a08e0a2e'/>
<id>urn:sha1:b6846d7c408b33e4701f4f5ca28932e2a08e0a2e</id>
<content type='text'>
commit 9bc3047374d5bec163e83e743709e23753376f0c upstream.

Commit a096ccca6e50 initializes the "sk_uid" field in the protocol socket
(struct sock) from the "/dev/net/tun" device node's owner UID. Per
original commit 86741ec25462 ("net: core: Add a UID field to struct
sock.", 2016-11-04), that's wrong: the idea is to cache the UID of the
userspace process that creates the socket. Commit 86741ec25462 mentions
socket() and accept(); with "tun", the action that creates the socket is
open("/dev/net/tun").

Therefore the device node's owner UID is irrelevant. In most cases,
"/dev/net/tun" will be owned by root, so in practice, commit a096ccca6e50
has no observable effect:

- before, "sk_uid" would be zero, due to undefined behavior
  (CVE-2023-1076),

- after, "sk_uid" would be zero, due to "/dev/net/tun" being owned by root.

What matters is the (fs)UID of the process performing the open(), so cache
that in "sk_uid".

Cc: Eric Dumazet &lt;edumazet@google.com&gt;
Cc: Lorenzo Colitti &lt;lorenzo@google.com&gt;
Cc: Paolo Abeni &lt;pabeni@redhat.com&gt;
Cc: Pietro Borrello &lt;borrello@diag.uniroma1.it&gt;
Cc: netdev@vger.kernel.org
Cc: stable@vger.kernel.org
Fixes: a096ccca6e50 ("tun: tun_chr_open(): correctly initialize socket uid")
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2173435
Signed-off-by: Laszlo Ersek &lt;lersek@redhat.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tun: Fix memory leak for detached NAPI queue.</title>
<updated>2023-05-24T16:32:47+00:00</updated>
<author>
<name>Kuniyuki Iwashima</name>
<email>kuniyu@amazon.com</email>
</author>
<published>2023-05-15T18:42:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=9cae243b9ae25adfe468cd47ceca591f6725b79c'/>
<id>urn:sha1:9cae243b9ae25adfe468cd47ceca591f6725b79c</id>
<content type='text'>
[ Upstream commit 82b2bc279467c875ec36f8ef820f00997c2a4e8e ]

syzkaller reported [0] memory leaks of sk and skb related to the TUN
device with no repro, but we can reproduce it easily with:

  struct ifreq ifr = {}
  int fd_tun, fd_tmp;
  char buf[4] = {};

  fd_tun = openat(AT_FDCWD, "/dev/net/tun", O_WRONLY, 0);
  ifr.ifr_flags = IFF_TUN | IFF_NAPI | IFF_MULTI_QUEUE;
  ioctl(fd_tun, TUNSETIFF, &amp;ifr);

  ifr.ifr_flags = IFF_DETACH_QUEUE;
  ioctl(fd_tun, TUNSETQUEUE, &amp;ifr);

  fd_tmp = socket(AF_PACKET, SOCK_PACKET, 0);
  ifr.ifr_flags = IFF_UP;
  ioctl(fd_tmp, SIOCSIFFLAGS, &amp;ifr);

  write(fd_tun, buf, sizeof(buf));
  close(fd_tun);

If we enable NAPI and multi-queue on a TUN device, we can put skb into
tfile-&gt;sk.sk_write_queue after the queue is detached.  We should prevent
it by checking tfile-&gt;detached before queuing skb.

Note this must be done under tfile-&gt;sk.sk_write_queue.lock because write()
and ioctl(IFF_DETACH_QUEUE) can run concurrently.  Otherwise, there would
be a small race window:

  write()                             ioctl(IFF_DETACH_QUEUE)
  `- tun_get_user                     `- __tun_detach
     |- if (tfile-&gt;detached)             |- tun_disable_queue
     |  `-&gt; false                        |  `- tfile-&gt;detached = tun
     |                                   `- tun_queue_purge
     |- spin_lock_bh(&amp;queue-&gt;lock)
     `- __skb_queue_tail(queue, skb)

Another solution is to call tun_queue_purge() when closing and
reattaching the detached queue, but it could paper over another
problems.  Also, we do the same kind of test for IFF_NAPI_FRAGS.

[0]:
unreferenced object 0xffff88801edbc800 (size 2048):
  comm "syz-executor.1", pid 33269, jiffies 4295743834 (age 18.756s)
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 00 07 40 00 00 00 00 00 00 00 00 00 00 00 00  ...@............
  backtrace:
    [&lt;000000008c16ea3d&gt;] __do_kmalloc_node mm/slab_common.c:965 [inline]
    [&lt;000000008c16ea3d&gt;] __kmalloc+0x4a/0x130 mm/slab_common.c:979
    [&lt;000000003addde56&gt;] kmalloc include/linux/slab.h:563 [inline]
    [&lt;000000003addde56&gt;] sk_prot_alloc+0xef/0x1b0 net/core/sock.c:2035
    [&lt;000000003e20621f&gt;] sk_alloc+0x36/0x2f0 net/core/sock.c:2088
    [&lt;0000000028e43843&gt;] tun_chr_open+0x3d/0x190 drivers/net/tun.c:3438
    [&lt;000000001b0f1f28&gt;] misc_open+0x1a6/0x1f0 drivers/char/misc.c:165
    [&lt;000000004376f706&gt;] chrdev_open+0x111/0x300 fs/char_dev.c:414
    [&lt;00000000614d379f&gt;] do_dentry_open+0x2f9/0x750 fs/open.c:920
    [&lt;000000008eb24774&gt;] do_open fs/namei.c:3636 [inline]
    [&lt;000000008eb24774&gt;] path_openat+0x143f/0x1a30 fs/namei.c:3791
    [&lt;00000000955077b5&gt;] do_filp_open+0xce/0x1c0 fs/namei.c:3818
    [&lt;00000000b78973b0&gt;] do_sys_openat2+0xf0/0x260 fs/open.c:1356
    [&lt;00000000057be699&gt;] do_sys_open fs/open.c:1372 [inline]
    [&lt;00000000057be699&gt;] __do_sys_openat fs/open.c:1388 [inline]
    [&lt;00000000057be699&gt;] __se_sys_openat fs/open.c:1383 [inline]
    [&lt;00000000057be699&gt;] __x64_sys_openat+0x83/0xf0 fs/open.c:1383
    [&lt;00000000a7d2182d&gt;] do_syscall_x64 arch/x86/entry/common.c:50 [inline]
    [&lt;00000000a7d2182d&gt;] do_syscall_64+0x3c/0x90 arch/x86/entry/common.c:80
    [&lt;000000004cc4e8c4&gt;] entry_SYSCALL_64_after_hwframe+0x72/0xdc

unreferenced object 0xffff88802f671700 (size 240):
  comm "syz-executor.1", pid 33269, jiffies 4295743854 (age 18.736s)
  hex dump (first 32 bytes):
    68 c9 db 1e 80 88 ff ff 68 c9 db 1e 80 88 ff ff  h.......h.......
    00 c0 7b 2f 80 88 ff ff 00 c8 db 1e 80 88 ff ff  ..{/............
  backtrace:
    [&lt;00000000e9d9fdb6&gt;] __alloc_skb+0x223/0x250 net/core/skbuff.c:644
    [&lt;000000002c3e4e0b&gt;] alloc_skb include/linux/skbuff.h:1288 [inline]
    [&lt;000000002c3e4e0b&gt;] alloc_skb_with_frags+0x6f/0x350 net/core/skbuff.c:6378
    [&lt;00000000825f98d7&gt;] sock_alloc_send_pskb+0x3ac/0x3e0 net/core/sock.c:2729
    [&lt;00000000e9eb3df3&gt;] tun_alloc_skb drivers/net/tun.c:1529 [inline]
    [&lt;00000000e9eb3df3&gt;] tun_get_user+0x5e1/0x1f90 drivers/net/tun.c:1841
    [&lt;0000000053096912&gt;] tun_chr_write_iter+0xac/0x120 drivers/net/tun.c:2035
    [&lt;00000000b9282ae0&gt;] call_write_iter include/linux/fs.h:1868 [inline]
    [&lt;00000000b9282ae0&gt;] new_sync_write fs/read_write.c:491 [inline]
    [&lt;00000000b9282ae0&gt;] vfs_write+0x40f/0x530 fs/read_write.c:584
    [&lt;00000000524566e4&gt;] ksys_write+0xa1/0x170 fs/read_write.c:637
    [&lt;00000000a7d2182d&gt;] do_syscall_x64 arch/x86/entry/common.c:50 [inline]
    [&lt;00000000a7d2182d&gt;] do_syscall_64+0x3c/0x90 arch/x86/entry/common.c:80
    [&lt;000000004cc4e8c4&gt;] entry_SYSCALL_64_after_hwframe+0x72/0xdc

Fixes: cde8b15f1aab ("tuntap: add ioctl to attach or detach a file form tuntap device")
Reported-by: syzkaller &lt;syzkaller@googlegroups.com&gt;
Signed-off-by: Kuniyuki Iwashima &lt;kuniyu@amazon.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>net: tun: rebuild error handling in tun_get_user</title>
<updated>2023-05-24T16:32:47+00:00</updated>
<author>
<name>Chuang Wang</name>
<email>nashuiliang@gmail.com</email>
</author>
<published>2022-11-10T07:31:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=e2d59768f851c1726d6d0df63a6ae4c5e39786a0'/>
<id>urn:sha1:e2d59768f851c1726d6d0df63a6ae4c5e39786a0</id>
<content type='text'>
[ Upstream commit ab00af85d2f886a8e4ace1342d9cc2b232eab6a8 ]

The error handling in tun_get_user is very scattered.
This patch unifies error handling, reduces duplication of code, and
makes the logic clearer.

Signed-off-by: Chuang Wang &lt;nashuiliang@gmail.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Stable-dep-of: 82b2bc279467 ("tun: Fix memory leak for detached NAPI queue.")
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>tun: tun_chr_open(): correctly initialize socket uid</title>
<updated>2023-03-10T08:33:01+00:00</updated>
<author>
<name>Pietro Borrello</name>
<email>borrello@diag.uniroma1.it</email>
</author>
<published>2023-02-04T17:39:21+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=b4ada752eaf1341f47bfa3d8ada377eca75a8d44'/>
<id>urn:sha1:b4ada752eaf1341f47bfa3d8ada377eca75a8d44</id>
<content type='text'>
[ Upstream commit a096ccca6e503a5c575717ff8a36ace27510ab0a ]

sock_init_data() assumes that the `struct socket` passed in input is
contained in a `struct socket_alloc` allocated with sock_alloc().
However, tun_chr_open() passes a `struct socket` embedded in a `struct
tun_file` allocated with sk_alloc().
This causes a type confusion when issuing a container_of() with
SOCK_INODE() in sock_init_data() which results in assigning a wrong
sk_uid to the `struct sock` in input.
On default configuration, the type confused field overlaps with the
high 4 bytes of `struct tun_struct __rcu *tun` of `struct tun_file`,
NULL at the time of call, which makes the uid of all tun sockets 0,
i.e., the root one.
Fix the assignment by using sock_init_data_uid().

Fixes: 86741ec25462 ("net: core: Add a UID field to struct sock.")
Signed-off-by: Pietro Borrello &lt;borrello@diag.uniroma1.it&gt;
Reviewed-by: Eric Dumazet &lt;edumazet@google.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>net: tun: Fix use-after-free in tun_detach()</title>
<updated>2022-11-29T11:14:15+00:00</updated>
<author>
<name>Shigeru Yoshida</name>
<email>syoshida@redhat.com</email>
</author>
<published>2022-11-24T17:51:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=5daadc86f27ea4d691e2131c04310d0418c6cd12'/>
<id>urn:sha1:5daadc86f27ea4d691e2131c04310d0418c6cd12</id>
<content type='text'>
syzbot reported use-after-free in tun_detach() [1].  This causes call
trace like below:

==================================================================
BUG: KASAN: use-after-free in notifier_call_chain+0x1ee/0x200 kernel/notifier.c:75
Read of size 8 at addr ffff88807324e2a8 by task syz-executor.0/3673

CPU: 0 PID: 3673 Comm: syz-executor.0 Not tainted 6.1.0-rc5-syzkaller-00044-gcc675d22e422 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022
Call Trace:
 &lt;TASK&gt;
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xd1/0x138 lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:284 [inline]
 print_report+0x15e/0x461 mm/kasan/report.c:395
 kasan_report+0xbf/0x1f0 mm/kasan/report.c:495
 notifier_call_chain+0x1ee/0x200 kernel/notifier.c:75
 call_netdevice_notifiers_info+0x86/0x130 net/core/dev.c:1942
 call_netdevice_notifiers_extack net/core/dev.c:1983 [inline]
 call_netdevice_notifiers net/core/dev.c:1997 [inline]
 netdev_wait_allrefs_any net/core/dev.c:10237 [inline]
 netdev_run_todo+0xbc6/0x1100 net/core/dev.c:10351
 tun_detach drivers/net/tun.c:704 [inline]
 tun_chr_close+0xe4/0x190 drivers/net/tun.c:3467
 __fput+0x27c/0xa90 fs/file_table.c:320
 task_work_run+0x16f/0x270 kernel/task_work.c:179
 exit_task_work include/linux/task_work.h:38 [inline]
 do_exit+0xb3d/0x2a30 kernel/exit.c:820
 do_group_exit+0xd4/0x2a0 kernel/exit.c:950
 get_signal+0x21b1/0x2440 kernel/signal.c:2858
 arch_do_signal_or_restart+0x86/0x2300 arch/x86/kernel/signal.c:869
 exit_to_user_mode_loop kernel/entry/common.c:168 [inline]
 exit_to_user_mode_prepare+0x15f/0x250 kernel/entry/common.c:203
 __syscall_exit_to_user_mode_work kernel/entry/common.c:285 [inline]
 syscall_exit_to_user_mode+0x1d/0x50 kernel/entry/common.c:296
 do_syscall_64+0x46/0xb0 arch/x86/entry/common.c:86
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

The cause of the issue is that sock_put() from __tun_detach() drops
last reference count for struct net, and then notifier_call_chain()
from netdev_state_change() accesses that struct net.

This patch fixes the issue by calling sock_put() from tun_detach()
after all necessary accesses for the struct net has done.

Fixes: 83c1f36f9880 ("tun: send netlink notification when the device is modified")
Reported-by: syzbot+106f9b687cd64ee70cd1@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?id=96eb7f1ce75ef933697f24eeab928c4a716edefe [1]
Signed-off-by: Shigeru Yoshida &lt;syoshida@redhat.com&gt;
Link: https://lore.kernel.org/r/20221124175134.1589053-1-syoshida@redhat.com
Signed-off-by: Paolo Abeni &lt;pabeni@redhat.com&gt;
</content>
</entry>
</feed>
