KASAN: use-after-free Read in v4l2_fh_open

57 views
Skip to first unread message

syzbot

unread,
Feb 15, 2021, 10:18:23 AM2/15/21
to linux-...@vger.kernel.org, linux...@vger.kernel.org, mch...@kernel.org, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 291009f6 Merge tag 'pm-5.11-rc8' of git://git.kernel.org/p..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=17260814d00000
kernel config: https://syzkaller.appspot.com/x/.config?x=6a218c95bd23063a
dashboard link: https://syzkaller.appspot.com/bug?extid=b2391895514ed9ef4a8e
compiler: Debian clang version 11.0.1-2
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14ec5814d00000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=17179dd4d00000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+b23918...@syzkaller.appspotmail.com

==================================================================
BUG: KASAN: use-after-free in v4l2_fh_init drivers/media/v4l2-core/v4l2-fh.c:25 [inline]
BUG: KASAN: use-after-free in v4l2_fh_open+0xc7/0x430 drivers/media/v4l2-core/v4l2-fh.c:63
Read of size 8 at addr ffff8880228b88b8 by task v4l_id/18349

CPU: 1 PID: 18349 Comm: v4l_id Not tainted 5.11.0-rc7-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:79 [inline]
dump_stack+0x137/0x1be lib/dump_stack.c:120
print_address_description+0x5f/0x3a0 mm/kasan/report.c:230
__kasan_report mm/kasan/report.c:396 [inline]
kasan_report+0x15e/0x200 mm/kasan/report.c:413
v4l2_fh_init drivers/media/v4l2-core/v4l2-fh.c:25 [inline]
v4l2_fh_open+0xc7/0x430 drivers/media/v4l2-core/v4l2-fh.c:63
em28xx_v4l2_open+0x15c/0xa60 drivers/media/usb/em28xx/em28xx-video.c:2163
v4l2_open+0x229/0x360 drivers/media/v4l2-core/v4l2-dev.c:423
chrdev_open+0x4a0/0x570 fs/char_dev.c:414
do_dentry_open+0x7cb/0x1010 fs/open.c:817
do_open fs/namei.c:3254 [inline]
path_openat+0x2791/0x37a0 fs/namei.c:3371
do_filp_open+0x191/0x3a0 fs/namei.c:3398
do_sys_openat2+0xba/0x380 fs/open.c:1172
do_sys_open fs/open.c:1188 [inline]
__do_sys_open fs/open.c:1196 [inline]
__se_sys_open fs/open.c:1192 [inline]
__x64_sys_open+0x1af/0x1e0 fs/open.c:1192
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7fdd62b00840
Code: 73 01 c3 48 8b 0d 68 77 20 00 f7 d8 64 89 01 48 83 c8 ff c3 66 0f 1f 44 00 00 83 3d 89 bb 20 00 00 75 10 b8 02 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 31 c3 48 83 ec 08 e8 1e f6 ff ff 48 89 04 24
RSP: 002b:00007ffe8bb255b8 EFLAGS: 00000246 ORIG_RAX: 0000000000000002
RAX: ffffffffffffffda RBX: 00007ffe8bb25728 RCX: 00007fdd62b00840
RDX: 00007fdd62aecea0 RSI: 0000000000000000 RDI: 00007ffe8bb26f1c
RBP: 0000000000000003 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000002 R11: 0000000000000246 R12: 000055f8a7dee8d0
R13: 00007ffe8bb25720 R14: 0000000000000000 R15: 0000000000000000

The buggy address belongs to the page:
page:00000000b7dd9778 refcount:0 mapcount:-128 mapping:0000000000000000 index:0x0 pfn:0x228b8
flags: 0xfff00000000000()
raw: 00fff00000000000 ffffea0000580108 ffff88813fffb910 0000000000000000
raw: 0000000000000000 0000000000000002 00000000ffffff7f 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff8880228b8780: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff8880228b8800: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>ffff8880228b8880: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
^
ffff8880228b8900: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff8880228b8980: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
==================================================================


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this issue, for details see:
https://goo.gl/tpsmEJ#testing-patches

Hillf Danton

unread,
May 5, 2021, 1:45:06 AM5/5/21
to syzbot, linux-...@vger.kernel.org, linux...@vger.kernel.org, mch...@kernel.org, Hillf Danton, syzkall...@googlegroups.com
On Mon, 15 Feb 2021 07:18:22
In bid to cut the race between the open and disconnect pathes, make
em28xx_v4l2 rcu safe. And on top of rcu, check existing disconnector
on the open side and bail out in case of losing the game.

+++ x/drivers/media/usb/em28xx/em28xx.h
@@ -548,8 +548,13 @@ struct em28xx_eeprom {
#define EM28XX_RESOURCE_VIDEO 0x01
#define EM28XX_RESOURCE_VBI 0x02

+enum {
+ EM28XX_V4L2_STATE_DISCONNECTING,
+};
+
struct em28xx_v4l2 {
struct kref ref;
+ unsigned int state;
struct em28xx *dev;

struct v4l2_device v4l2_dev;
@@ -604,6 +609,7 @@ struct em28xx_v4l2 {
struct media_pad video_pad, vbi_pad;
struct media_entity *decoder;
#endif
+ struct rcu_head rcu;
};

struct em28xx_audio {
+++ x/drivers/media/usb/em28xx/em28xx-video.c
@@ -2113,6 +2113,13 @@ static int radio_s_tuner(struct file *fi
return 0;
}

+static void em28xx_v4l2_rcufn(struct rcu_head *r)
+{
+ struct em28xx_v4l2 *v4l2 = container_of(r, struct em28xx_v4l2, rcu);
+
+ kfree(v4l2);
+}
+
/*
* em28xx_free_v4l2() - Free struct em28xx_v4l2
*
@@ -2125,7 +2132,7 @@ static void em28xx_free_v4l2(struct kref
struct em28xx_v4l2 *v4l2 = container_of(ref, struct em28xx_v4l2, ref);

v4l2->dev->v4l2 = NULL;
- kfree(v4l2);
+ call_rcu(&v4l2->rcu, em28xx_v4l2_rcufn);
}

/*
@@ -2138,7 +2145,16 @@ static int em28xx_v4l2_open(struct file
struct em28xx *dev = video_drvdata(filp);
struct em28xx_v4l2 *v4l2 = dev->v4l2;
enum v4l2_buf_type fh_type = 0;
- int ret;
+ int ret = 0;
+
+ rcu_read_lock();
+ if (!v4l2 || test_bit(EM28XX_V4L2_STATE_DISCONNECTING, &v4l2->state))
+ ret = -ENODEV;
+ else
+ kref_get(&v4l2->ref);
+ rcu_read_unlock();
+ if (ret)
+ return ret;

switch (vdev->vfl_type) {
case VFL_TYPE_VIDEO:
@@ -2150,6 +2166,7 @@ static int em28xx_v4l2_open(struct file
case VFL_TYPE_RADIO:
break;
default:
+ kref_put(&v4l2->ref, em28xx_free_v4l2);
return -EINVAL;
}

@@ -2157,15 +2174,24 @@ static int em28xx_v4l2_open(struct file
video_device_node_name(vdev), v4l2_type_names[fh_type],
v4l2->users);

- if (mutex_lock_interruptible(&dev->lock))
+ if (mutex_lock_interruptible(&dev->lock)) {
+ kref_put(&v4l2->ref, em28xx_free_v4l2);
return -ERESTARTSYS;
+ }
+
+ if (test_bit(EM28XX_V4L2_STATE_DISCONNECTING, &v4l2->state)) {
+ ret = -ENODEV;
+ goto err;
+ }

ret = v4l2_fh_open(filp);
if (ret) {
dev_err(&dev->intf->dev,
"%s: v4l2_fh_open() returned error %d\n",
__func__, ret);
+err:
mutex_unlock(&dev->lock);
+ kref_put(&v4l2->ref, em28xx_free_v4l2);
return ret;
}

@@ -2188,7 +2214,6 @@ static int em28xx_v4l2_open(struct file
}

kref_get(&dev->ref);
- kref_get(&v4l2->ref);
v4l2->users++;

mutex_unlock(&dev->lock);
@@ -2218,6 +2243,8 @@ static int em28xx_v4l2_fini(struct em28x
if (!v4l2)
return 0;

+ set_bit(EM28XX_V4L2_STATE_DISCONNECTING, &v4l2->state);
+
dev_info(&dev->intf->dev, "Closing video extension\n");

mutex_lock(&dev->lock);

syzbot

unread,
May 7, 2021, 2:39:13 PM5/7/21
to igormt...@gmail.com, syzkall...@googlegroups.com
Hello,

syzbot tried to test the proposed patch but the build/boot failed:

WARNING in __nf_unregister_net_hook

------------[ cut here ]------------
hook not found, pf 3 num 0
WARNING: CPU: 1 PID: 308 at net/netfilter/core.c:480 __nf_unregister_net_hook+0x4ee/0x640 net/netfilter/core.c:480
Modules linked in:
CPU: 1 PID: 308 Comm: kworker/u4:6 Not tainted 5.12.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: netns cleanup_net
RIP: 0010:__nf_unregister_net_hook+0x4ee/0x640 net/netfilter/core.c:480
Code: c6 05 f9 0e 34 05 01 43 8a 04 2e 84 c0 0f 85 3a 01 00 00 48 8b 04 24 8b 10 48 c7 c7 00 65 d6 8a 44 89 e6 31 c0 e8 e2 96 78 f9 <0f> 0b e9 08 ff ff ff 48 8b 0c 24 80 e1 07 80 c1 03 38 c1 0f 8c 3d
RSP: 0018:ffffc90001e1fbd8 EFLAGS: 00010246
RAX: 130bfab82e863e00 RBX: ffff888019f77380 RCX: 130bfab82e863e00
RDX: 0000000000000000 RSI: 0000000080000000 RDI: 0000000000000000
RBP: ffff888031778f20 R08: ffffffff81603612 R09: ffffed10173e3f24
R10: ffffed10173e3f24 R11: 0000000000000000 R12: 0000000000000003
R13: dffffc0000000000 R14: 1ffff110288ca843 R15: ffff888031778000
FS: 0000000000000000(0000) GS:ffff8880b9f00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007ff54d933000 CR3: 000000002cf06000 CR4: 00000000001506e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
nf_unregister_net_hook net/netfilter/core.c:498 [inline]
nf_unregister_net_hooks+0xe7/0x150 net/netfilter/core.c:576
ops_pre_exit_list net/core/net_namespace.c:165 [inline]
cleanup_net+0x5b8/0xbd0 net/core/net_namespace.c:583
process_one_work+0x789/0xfd0 kernel/workqueue.c:2275
worker_thread+0xac1/0x1300 kernel/workqueue.c:2421
kthread+0x39a/0x3c0 kernel/kthread.c:313
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294


Starting getty on tty2-tty6 if dbus and logind are not available...
[ [0;32m OK [0m] Started Daily apt download activities.
[ [0;32m OK [0m] Started Daily apt upgrade and clean activities.
[ [0;32m OK [0m] Reached target Timers.
[ [0;32m OK [0m] Started Permit User Sessions.
[ [0;32m OK [0m] Started Getty on tty1.
[ [0;32m OK [0m] Started System Logging Service.
[ [0;32m OK [0m] Found device /dev/ttyS0.
[ [0;32m OK [0m] Started OpenBSD Secure Shell server.
[ [0;32m OK [0m] Started getty on tty2-tty6 if dbus and logind are not available.
[ [0;32m OK [0m] Listening on Load/Save RF Kill Switch Status /dev/rfkill Watch.
[ [0;32m OK [0m] Started Getty on tty6.
[ [0;32m OK [0m] Started Getty on tty5.
[ [0;32m OK [0m] Started Getty on tty4.
[ [0;32m OK [0m] Started Getty on tty3.
[ [0;32m OK [0m] Started Serial Getty on ttyS0.
[ [0;32m OK [0m] Started Getty on tty2.
[ [0;32m OK [0m] Reached target Login Prompts.
[ [0;32m OK [0m] Reached target Multi-User System.
[ [0;32m OK [0m] Reached target Graphical Interface.
Starting Update UTMP about System Runlevel Changes...

Debian GNU/Linux 9 syzkaller ttyS0

Warning: Permanently added '10.128.15.197' (ECDSA) to the list of known hosts.
2021/05/07 18:38:31 fuzzer started
2021/05/07 18:38:32 connecting to host at 10.128.0.169:34847
2021/05/07 18:38:32 checking machine...
2021/05/07 18:38:32 checking revisions...
2021/05/07 18:38:32 testing simple program...
syzkaller login: [ 48.084197][ T8423] chnl_net:caif_netlink_parms(): no params data found
[ 48.136898][ T8423] bridge0: port 1(bridge_slave_0) entered blocking state
[ 48.146030][ T8423] bridge0: port 1(bridge_slave_0) entered disabled state
[ 48.154429][ T8423] device bridge_slave_0 entered promiscuous mode
[ 48.164531][ T8423] bridge0: port 2(bridge_slave_1) entered blocking state
[ 48.171995][ T8423] bridge0: port 2(bridge_slave_1) entered disabled state
[ 48.180535][ T8423] device bridge_slave_1 entered promiscuous mode
[ 48.199837][ T8423] bond0: (slave bond_slave_0): Enslaving as an active interface with an up link
[ 48.211072][ T8423] bond0: (slave bond_slave_1): Enslaving as an active interface with an up link
[ 48.232417][ T8423] team0: Port device team_slave_0 added
[ 48.240144][ T8423] team0: Port device team_slave_1 added
[ 48.256477][ T8423] batman_adv: batadv0: Adding interface: batadv_slave_0
[ 48.263564][ T8423] batman_adv: batadv0: The MTU of interface batadv_slave_0 is too small (1500) to handle the transport of batman-adv packets. Packets going over this interface will be fragmented on layer2 which could impact the performance. Setting the MTU to 1560 would solve the problem.
[ 48.290582][ T8423] batman_adv: batadv0: Not using interface batadv_slave_0 (retrying later): interface not active
[ 48.303282][ T8423] batman_adv: batadv0: Adding interface: batadv_slave_1
[ 48.310853][ T8423] batman_adv: batadv0: The MTU of interface batadv_slave_1 is too small (1500) to handle the transport of batman-adv packets. Packets going over this interface will be fragmented on layer2 which could impact the performance. Setting the MTU to 1560 would solve the problem.
[ 48.337551][ T8423] batman_adv: batadv0: Not using interface batadv_slave_1 (retrying later): interface not active
[ 48.358108][ T8423] device hsr_slave_0 entered promiscuous mode
[ 48.365130][ T8423] device hsr_slave_1 entered promiscuous mode
[ 48.461403][ T8423] netdevsim netdevsim0 netdevsim0: renamed from eth0
[ 48.472157][ T8423] netdevsim netdevsim0 netdevsim1: renamed from eth1
[ 48.481902][ T8423] netdevsim netdevsim0 netdevsim2: renamed from eth2
[ 48.491682][ T8423] netdevsim netdevsim0 netdevsim3: renamed from eth3
[ 48.513843][ T8423] bridge0: port 2(bridge_slave_1) entered blocking state
[ 48.521167][ T8423] bridge0: port 2(bridge_slave_1) entered forwarding state
[ 48.529075][ T8423] bridge0: port 1(bridge_slave_0) entered blocking state
[ 48.536205][ T8423] bridge0: port 1(bridge_slave_0) entered forwarding state
[ 48.574673][ T8423] 8021q: adding VLAN 0 to HW filter on device bond0
[ 48.589187][ T7] IPv6: ADDRCONF(NETDEV_CHANGE): veth0: link becomes ready
[ 48.600962][ T7] bridge0: port 1(bridge_slave_0) entered disabled state
[ 48.611033][ T7] bridge0: port 2(bridge_slave_1) entered disabled state
[ 48.619485][ T7] IPv6: ADDRCONF(NETDEV_CHANGE): bond0: link becomes ready
[ 48.632671][ T8423] 8021q: adding VLAN 0 to HW filter on device team0
[ 48.645863][ T8643] IPv6: ADDRCONF(NETDEV_CHANGE): bridge_slave_0: link becomes ready
[ 48.654318][ T8643] bridge0: port 1(bridge_slave_0) entered blocking state
[ 48.661714][ T8643] bridge0: port 1(bridge_slave_0) entered forwarding state
[ 48.673625][ T3817] IPv6: ADDRCONF(NETDEV_CHANGE): bridge_slave_1: link becomes ready
[ 48.682706][ T3817] bridge0: port 2(bridge_slave_1) entered blocking state
[ 48.690791][ T3817] bridge0: port 2(bridge_slave_1) entered forwarding state
[ 48.709734][ T8643] IPv6: ADDRCONF(NETDEV_CHANGE): team_slave_0: link becomes ready
[ 48.719081][ T8643] IPv6: ADDRCONF(NETDEV_CHANGE): team0: link becomes ready
[ 48.738901][ T8645] IPv6: ADDRCONF(NETDEV_CHANGE): team_slave_1: link becomes ready
[ 48.748380][ T8645] IPv6: ADDRCONF(NETDEV_CHANGE): hsr_slave_0: link becomes ready
[ 48.757725][ T8645] IPv6: ADDRCONF(NETDEV_CHANGE): hsr_slave_1: link becomes ready
[ 48.770079][ T8423] IPv6: ADDRCONF(NETDEV_CHANGE): hsr0: link becomes ready
[ 48.788936][ T8645] IPv6: ADDRCONF(NETDEV_CHANGE): vxcan0: link becomes ready
[ 48.797102][ T8645] IPv6: ADDRCONF(NETDEV_CHANGE): vxcan1: link becomes ready
[ 48.809172][ T8423] 8021q: adding VLAN 0 to HW filter on device batadv0
[ 48.828456][ T8643] IPv6: ADDRCONF(NETDEV_CHANGE): veth0_virt_wifi: link becomes ready
[ 48.847902][ T7] IPv6: ADDRCONF(NETDEV_CHANGE): veth0_vlan: link becomes ready
[ 48.857230][ T7] IPv6: ADDRCONF(NETDEV_CHANGE): vlan0: link becomes ready
[ 48.865311][ T7] IPv6: ADDRCONF(NETDEV_CHANGE): vlan1: link becomes ready
[ 48.875561][ T8423] device veth0_vlan entered promiscuous mode
[ 48.890122][ T8423] device veth1_vlan entered promiscuous mode
[ 48.910037][ T8643] IPv6: ADDRCONF(NETDEV_CHANGE): macvlan0: link becomes ready
[ 48.918903][ T8643] IPv6: ADDRCONF(NETDEV_CHANGE): macvlan1: link becomes ready
[ 48.928105][ T8643] IPv6: ADDRCONF(NETDEV_CHANGE): veth0_macvtap: link becomes ready
[ 48.938637][ T8423] device veth0_macvtap entered promiscuous mode
[ 48.950031][ T8423] device veth1_macvtap entered promiscuous mode
[ 48.966930][ T8423] batman_adv: batadv0: Interface activated: batadv_slave_0
[ 48.975858][ T8643] IPv6: ADDRCONF(NETDEV_CHANGE): veth0_to_batadv: link becomes ready
[ 48.986869][ T8643] IPv6: ADDRCONF(NETDEV_CHANGE): macvtap0: link becomes ready
[ 49.000097][ T8423] batman_adv: batadv0: Interface activated: batadv_slave_1
[ 49.008592][ T8645] IPv6: ADDRCONF(NETDEV_CHANGE): veth1_to_batadv: link becomes ready
[ 49.021568][ T8423] netdevsim netdevsim0 netdevsim0: set [1, 0] type 2 family 0 port 6081 - 0
[ 49.032064][ T8423] netdevsim netdevsim0 netdevsim1: set [1, 0] type 2 family 0 port 6081 - 0
[ 49.041676][ T8423] netdevsim netdevsim0 netdevsim2: set [1, 0] type 2 family 0 port 6081 - 0
[ 49.050582][ T8423] netdevsim netdevsim0 netdevsim3: set [1, 0] type 2 family 0 port 6081 - 0
[ 49.122452][ T308] wlan0: Created IBSS using preconfigured BSSID 50:50:50:50:50:50
[ 49.145962][ T308] wlan0: Creating new IBSS network, BSSID 50:50:50:50:50:50
[ 49.160414][ T3817] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
[ 49.180968][ T195] wlan1: Created IBSS using preconfigured BSSID 50:50:50:50:50:50
[ 49.191119][ T195] wlan1: Creating new IBSS network, BSSID 50:50:50:50:50:50
[ 49.201963][ T3817] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
2021/05/07 18:38:34 building call list...
executing program
[ 49.711972][ T308] ------------[ cut here ]------------
[ 49.726205][ T308] hook not found, pf 3 num 0
[ 49.726588][ T308] WARNING: CPU: 1 PID: 308 at net/netfilter/core.c:480 __nf_unregister_net_hook+0x4ee/0x640
[ 49.743943][ T308] Modules linked in:
[ 49.750278][ T308] CPU: 1 PID: 308 Comm: kworker/u4:6 Not tainted 5.12.0-syzkaller #0
[ 49.760075][ T308] Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
[ 49.775341][ T308] Workqueue: netns cleanup_net
[ 49.780300][ T308] RIP: 0010:__nf_unregister_net_hook+0x4ee/0x640
[ 49.788520][ T308] Code: c6 05 f9 0e 34 05 01 43 8a 04 2e 84 c0 0f 85 3a 01 00 00 48 8b 04 24 8b 10 48 c7 c7 00 65 d6 8a 44 89 e6 31 c0 e8 e2 96 78 f9 <0f> 0b e9 08 ff ff ff 48 8b 0c 24 80 e1 07 80 c1 03 38 c1 0f 8c 3d
[ 49.812270][ T308] RSP: 0018:ffffc90001e1fbd8 EFLAGS: 00010246
[ 49.819816][ T308] RAX: 130bfab82e863e00 RBX: ffff888019f77380 RCX: 130bfab82e863e00
[ 49.830460][ T308] RDX: 0000000000000000 RSI: 0000000080000000 RDI: 0000000000000000
[ 49.839600][ T308] RBP: ffff888031778f20 R08: ffffffff81603612 R09: ffffed10173e3f24
[ 49.850563][ T308] R10: ffffed10173e3f24 R11: 0000000000000000 R12: 0000000000000003
[ 49.859886][ T308] R13: dffffc0000000000 R14: 1ffff110288ca843 R15: ffff888031778000
[ 49.870323][ T308] FS: 0000000000000000(0000) GS:ffff8880b9f00000(0000) knlGS:0000000000000000
[ 49.880514][ T308] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 49.890783][ T308] CR2: 00007ff54d933000 CR3: 000000002cf06000 CR4: 00000000001506e0
[ 49.900506][ T308] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 49.911534][ T308] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 49.920735][ T308] Call Trace:
[ 49.924052][ T308] nf_unregister_net_hooks+0xe7/0x150
[ 49.932431][ T308] cleanup_net+0x5b8/0xbd0
[ 49.938216][ T308] process_one_work+0x789/0xfd0
[ 49.943476][ T308] worker_thread+0xac1/0x1300
[ 49.951172][ T308] ? __kthread_parkme+0x148/0x190
[ 49.957231][ T308] ? rcu_lock_release+0x20/0x20
[ 49.962155][ T308] kthread+0x39a/0x3c0
[ 49.970197][ T308] ? rcu_lock_release+0x20/0x20
[ 49.976315][ T308] ? kthread_blkcg+0xd0/0xd0
[ 49.981047][ T308] ret_from_fork+0x1f/0x30
[ 49.988729][ T308] Kernel panic - not syncing: panic_on_warn set ...
[ 49.995440][ T308] CPU: 1 PID: 308 Comm: kworker/u4:6 Not tainted 5.12.0-syzkaller #0
[ 50.003547][ T308] Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
[ 50.013708][ T308] Workqueue: netns cleanup_net
[ 50.018905][ T308] Call Trace:
[ 50.022202][ T308] dump_stack+0x125/0x19e
[ 50.026560][ T308] panic+0x291/0x800
[ 50.030472][ T308] ? __warn+0x13e/0x270
[ 50.034649][ T308] __warn+0x26a/0x270
[ 50.038648][ T308] ? __nf_unregister_net_hook+0x4ee/0x640
[ 50.044384][ T308] ? __nf_unregister_net_hook+0x4ee/0x640
[ 50.050144][ T308] report_bug+0x1b1/0x2e0
[ 50.054503][ T308] handle_bug+0x3d/0x70
[ 50.058669][ T308] exc_invalid_op+0x16/0x40
[ 50.063168][ T308] asm_exc_invalid_op+0x12/0x20
[ 50.068023][ T308] RIP: 0010:__nf_unregister_net_hook+0x4ee/0x640
[ 50.074359][ T308] Code: c6 05 f9 0e 34 05 01 43 8a 04 2e 84 c0 0f 85 3a 01 00 00 48 8b 04 24 8b 10 48 c7 c7 00 65 d6 8a 44 89 e6 31 c0 e8 e2 96 78 f9 <0f> 0b e9 08 ff ff ff 48 8b 0c 24 80 e1 07 80 c1 03 38 c1 0f 8c 3d
[ 50.094079][ T308] RSP: 0018:ffffc90001e1fbd8 EFLAGS: 00010246
[ 50.100677][ T308] RAX: 130bfab82e863e00 RBX: ffff888019f77380 RCX: 130bfab82e863e00
[ 50.108750][ T308] RDX: 0000000000000000 RSI: 0000000080000000 RDI: 0000000000000000
[ 50.116785][ T308] RBP: ffff888031778f20 R08: ffffffff81603612 R09: ffffed10173e3f24
[ 50.124765][ T308] R10: ffffed10173e3f24 R11: 0000000000000000 R12: 0000000000000003
[ 50.132835][ T308] R13: dffffc0000000000 R14: 1ffff110288ca843 R15: ffff888031778000
[ 50.140841][ T308] ? wake_up_klogd+0xb2/0xf0
[ 50.145452][ T308] ? __nf_unregister_net_hook+0x4ee/0x640
[ 50.151195][ T308] nf_unregister_net_hooks+0xe7/0x150
[ 50.156580][ T308] cleanup_net+0x5b8/0xbd0
[ 50.161033][ T308] process_one_work+0x789/0xfd0
[ 50.165918][ T308] worker_thread+0xac1/0x1300
[ 50.170773][ T308] ? __kthread_parkme+0x148/0x190
[ 50.175815][ T308] ? rcu_lock_release+0x20/0x20
[ 50.180771][ T308] kthread+0x39a/0x3c0
[ 50.184858][ T308] ? rcu_lock_release+0x20/0x20
[ 50.189712][ T308] ? kthread_blkcg+0xd0/0xd0
[ 50.194309][ T308] ret_from_fork+0x1f/0x30
[ 50.200540][ T308] Kernel Offset: disabled
[ 50.205082][ T308] Rebooting in 86400 seconds..



Tested on:

commit: c19d6e08 media: em28xx: Fix possible memory leak of em28xx..
git tree: https://github.com/Igortorrente/linux.git v4l2-open-use-after-free
kernel config: https://syzkaller.appspot.com/x/.config?x=1ed04b161feefc8f

Hillf Danton

unread,
Mar 2, 2024, 5:56:27 AMMar 2
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Mon, 15 Feb 2021 07:18:22 -0800
> syzbot found the following issue on:
>
> HEAD commit: 291009f6 Merge tag 'pm-5.11-rc8' of git://git.kernel.org/p..
> git tree: upstream
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=17179dd4d00000

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

--- x/drivers/media/usb/em28xx/em28xx-video.c
+++ y/drivers/media/usb/em28xx/em28xx-video.c
@@ -2152,6 +2152,10 @@ static int em28xx_v4l2_open(struct file
if (mutex_lock_interruptible(&dev->lock))
return -ERESTARTSYS;

+ if (!dev->v4l2) {
+ mutex_unlock(&dev->lock);
+ return -ENODEV;
+ }
ret = v4l2_fh_open(filp);
if (ret) {
dev_err(&dev->intf->dev,
@@ -2161,6 +2165,7 @@ static int em28xx_v4l2_open(struct file
return ret;
}

+ v4l2 = dev->v4l2;
if (v4l2->users == 0) {
em28xx_set_mode(dev, EM28XX_ANALOG_MODE);

--

syzbot

unread,
Mar 2, 2024, 8:02:05 AMMar 2
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Read in v4l2_open

==================================================================
BUG: KASAN: slab-use-after-free in v4l2_open+0x342/0x360 drivers/media/v4l2-core/v4l2-dev.c:432
Read of size 4 at addr ffff888024454800 by task v4l_id/5646

CPU: 1 PID: 5646 Comm: v4l_id Not tainted 6.8.0-rc6-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/25/2024
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x1b5/0x2a0 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:377 [inline]
print_report+0x163/0x510 mm/kasan/report.c:488
kasan_report+0xcd/0x100 mm/kasan/report.c:601
v4l2_open+0x342/0x360 drivers/media/v4l2-core/v4l2-dev.c:432
chrdev_open+0x50f/0x5d0 fs/char_dev.c:414
do_dentry_open+0x8fd/0x1590 fs/open.c:953
path_openat+0x280d/0x31d0 fs/namei.c:3645
do_filp_open+0x26d/0x500 fs/namei.c:3829
do_sys_openat2+0x12f/0x1c0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_openat fs/open.c:1435 [inline]
__se_sys_openat fs/open.c:1430 [inline]
__x64_sys_openat+0x247/0x290 fs/open.c:1430
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x85/0x160 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b
RIP: 0033:0x7f3dabb169a4
Code: 24 20 48 8d 44 24 30 48 89 44 24 28 64 8b 04 25 18 00 00 00 85 c0 75 2c 44 89 e2 48 89 ee bf 9c ff ff ff b8 01 01 00 00 0f 05 <48> 3d 00 f0 ff ff 76 60 48 8b 15 55 a4 0d 00 f7 d8 64 89 02 48 83
RSP: 002b:00007ffc466ecd40 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 00007ffc466ecf58 RCX: 00007f3dabb169a4
RDX: 0000000000000000 RSI: 00007ffc466edf1e RDI: 00000000ffffff9c
RBP: 00007ffc466edf1e R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffc466ecf70 R14: 0000555aa0ec0670 R15: 00007f3dac0aca80
</TASK>

Allocated by task 8:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x30/0x60 mm/kasan/common.c:68
poison_kmalloc_redzone mm/kasan/common.c:370 [inline]
__kasan_kmalloc+0x98/0xb0 mm/kasan/common.c:387
kasan_kmalloc include/linux/kasan.h:211 [inline]
kmalloc_trace+0x1e6/0x400 mm/slub.c:4012
kmalloc include/linux/slab.h:590 [inline]
kzalloc include/linux/slab.h:711 [inline]
em28xx_v4l2_init+0x107/0x2dc0 drivers/media/usb/em28xx/em28xx-video.c:2539
em28xx_init_extension+0x11f/0x1c0 drivers/media/usb/em28xx/em28xx-core.c:1116
process_scheduled_works+0x96f/0x1490 kernel/workqueue.c:2633
worker_thread+0xa5f/0xff0 kernel/workqueue.c:2787
kthread+0x2cd/0x360 kernel/kthread.c:388
ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:243

Freed by task 8:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x30/0x60 mm/kasan/common.c:68
kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:589
poison_slab_object+0xa6/0xe0 mm/kasan/common.c:240
__kasan_slab_free+0x37/0x60 mm/kasan/common.c:256
kasan_slab_free include/linux/kasan.h:184 [inline]
slab_free_hook mm/slub.c:2121 [inline]
slab_free mm/slub.c:4299 [inline]
kfree+0x14a/0x370 mm/slub.c:4409
em28xx_free_v4l2 drivers/media/usb/em28xx/em28xx-video.c:2120 [inline]
kref_put include/linux/kref.h:65 [inline]
em28xx_v4l2_init+0x1608/0x2dc0 drivers/media/usb/em28xx/em28xx-video.c:2908
em28xx_init_extension+0x11f/0x1c0 drivers/media/usb/em28xx/em28xx-core.c:1116
process_scheduled_works+0x96f/0x1490 kernel/workqueue.c:2633
worker_thread+0xa5f/0xff0 kernel/workqueue.c:2787
kthread+0x2cd/0x360 kernel/kthread.c:388
ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:243

The buggy address belongs to the object at ffff888024454000
which belongs to the cache kmalloc-8k of size 8192
The buggy address is located 2048 bytes inside of
freed 8192-byte region [ffff888024454000, ffff888024456000)

The buggy address belongs to the physical page:
page:ffffea0000911400 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x24450
head:ffffea0000911400 order:3 entire_mapcount:0 nr_pages_mapped:0 pincount:0
anon flags: 0xfff00000000840(slab|head|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 00fff00000000840 ffff888011442280 ffffea0001ede600 0000000000000005
raw: 0000000000000000 0000000080020002 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 4658, tgid 4658 (S41dhcpcd), ts 32416679882, free_ts 32403418572
prep_new_page mm/page_alloc.c:1540 [inline]
get_page_from_freelist+0x3355/0x34e0 mm/page_alloc.c:3311
__alloc_pages+0x255/0x670 mm/page_alloc.c:4567
alloc_slab_page+0x5f/0x150 include/linux/gfp.h:238
new_slab+0x84/0x2f0 mm/slub.c:2354
___slab_alloc+0xc77/0x1310 mm/slub.c:3540
kmalloc_trace+0x276/0x400 mm/slub.c:3625
kmalloc include/linux/slab.h:590 [inline]
kzalloc include/linux/slab.h:711 [inline]
tomoyo_print_bprm security/tomoyo/audit.c:26 [inline]
tomoyo_init_log+0x1228/0x2130 security/tomoyo/audit.c:264
tomoyo_supervisor+0x37a/0x1370 security/tomoyo/common.c:2089
tomoyo_audit_env_log security/tomoyo/environ.c:36 [inline]
tomoyo_env_perm+0x157/0x1f0 security/tomoyo/environ.c:63
tomoyo_find_next_domain+0x139a/0x1d40 security/tomoyo/domain.c:672
tomoyo_bprm_check_security+0x114/0x170 security/tomoyo/tomoyo.c:102
security_bprm_check+0x63/0xa0 security/security.c:1188
bprm_execve+0xa45/0x1840 fs/exec.c:1771
do_execveat_common+0x552/0x6f0 fs/exec.c:1984
do_execve fs/exec.c:2058 [inline]
__do_sys_execve fs/exec.c:2134 [inline]
__se_sys_execve fs/exec.c:2129 [inline]
__x64_sys_execve+0x92/0xa0 fs/exec.c:2129
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x85/0x160 arch/x86/entry/common.c:83
page last free pid 4657 tgid 4657 stack trace:
free_unref_page_prepare+0x94d/0xa60 include/linux/page_owner.h:24
free_unref_page+0x37/0x3f0 mm/page_alloc.c:2486
__put_partials+0xeb/0x130 mm/slub.c:2453
put_cpu_partial+0x169/0x240 mm/slub.c:2997
__slab_free+0x2c3/0x400 mm/slub.c:4166
qlist_free_all+0x5e/0xc0 mm/kasan/quarantine.c:163
kasan_quarantine_reduce+0x14b/0x160 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x23/0x70 mm/kasan/common.c:322
kasan_slab_alloc include/linux/kasan.h:201 [inline]
slab_post_alloc_hook mm/slub.c:3813 [inline]
slab_alloc_node mm/slub.c:3860 [inline]
__do_kmalloc_node mm/slub.c:3980 [inline]
__kmalloc+0x1dd/0x540 mm/slub.c:3994
kmalloc include/linux/slab.h:594 [inline]
tomoyo_realpath_from_path+0xcf/0x5e0 security/tomoyo/realpath.c:251
tomoyo_path_perm+0x24d/0x5b0 security/tomoyo/file.c:151
security_inode_getattr+0xd3/0x120 security/security.c:2238
vfs_fstatat+0xca/0x1b0 fs/stat.c:173
__se_sys_newfstatat fs/stat.c:468 [inline]
__x64_sys_newfstatat+0xff/0x170 fs/stat.c:462
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x85/0x160 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

Memory state around the buggy address:
ffff888024454700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888024454780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888024454800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888024454880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888024454900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


Tested on:

commit: 5ad3cb0e Merge tag 'for-v6.8-rc2' of git://git.kernel...
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
console output: https://syzkaller.appspot.com/x/log.txt?x=163afbac180000
kernel config: https://syzkaller.appspot.com/x/.config?x=fa01a41dc74de670
dashboard link: https://syzkaller.appspot.com/bug?extid=b2391895514ed9ef4a8e
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=15d84096180000

Hillf Danton

unread,
Mar 2, 2024, 6:07:18 PMMar 2
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Mon, 15 Feb 2021 07:18:22 -0800
> syzbot found the following issue on:
>
> HEAD commit: 291009f6 Merge tag 'pm-5.11-rc8' of git://git.kernel.org/p..
> git tree: upstream
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=17179dd4d00000

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

--- x/drivers/media/usb/em28xx/em28xx-video.c
+++ y/drivers/media/usb/em28xx/em28xx-video.c
@@ -2152,6 +2152,10 @@ static int em28xx_v4l2_open(struct file
if (mutex_lock_interruptible(&dev->lock))
return -ERESTARTSYS;

+ if (!dev->v4l2) {
+ mutex_unlock(&dev->lock);
+ return -ENODEV;
+ }
ret = v4l2_fh_open(filp);
if (ret) {
dev_err(&dev->intf->dev,
@@ -2161,6 +2165,7 @@ static int em28xx_v4l2_open(struct file
return ret;
}

+ v4l2 = dev->v4l2;
if (v4l2->users == 0) {
em28xx_set_mode(dev, EM28XX_ANALOG_MODE);

@@ -2899,6 +2904,7 @@ unregister_dev:
v4l2_ctrl_handler_free(&v4l2->ctrl_handler);
v4l2_device_unregister(&v4l2->v4l2_dev);
err:
+ video_unregister_device(&v4l2->vdev);
dev->v4l2 = NULL;
kref_put(&v4l2->ref, em28xx_free_v4l2);
mutex_unlock(&dev->lock);
--

syzbot

unread,
Mar 2, 2024, 6:39:03 PMMar 2
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Read in v4l2_open

==================================================================
BUG: KASAN: slab-use-after-free in v4l2_open+0x342/0x360 drivers/media/v4l2-core/v4l2-dev.c:432
Read of size 4 at addr ffff8880257b8800 by task v4l_id/5638

CPU: 1 PID: 5638 Comm: v4l_id Not tainted 6.8.0-rc6-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/25/2024
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x1b5/0x2a0 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:377 [inline]
print_report+0x163/0x510 mm/kasan/report.c:488
kasan_report+0xcd/0x100 mm/kasan/report.c:601
v4l2_open+0x342/0x360 drivers/media/v4l2-core/v4l2-dev.c:432
chrdev_open+0x50f/0x5d0 fs/char_dev.c:414
do_dentry_open+0x8fd/0x1590 fs/open.c:953
path_openat+0x280d/0x31d0 fs/namei.c:3645
do_filp_open+0x26d/0x500 fs/namei.c:3829
do_sys_openat2+0x12f/0x1c0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_openat fs/open.c:1435 [inline]
__se_sys_openat fs/open.c:1430 [inline]
__x64_sys_openat+0x247/0x290 fs/open.c:1430
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x85/0x160 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b
RIP: 0033:0x7fd0c998f9a4
Code: 24 20 48 8d 44 24 30 48 89 44 24 28 64 8b 04 25 18 00 00 00 85 c0 75 2c 44 89 e2 48 89 ee bf 9c ff ff ff b8 01 01 00 00 0f 05 <48> 3d 00 f0 ff ff 76 60 48 8b 15 55 a4 0d 00 f7 d8 64 89 02 48 83
RSP: 002b:00007ffe99c37580 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 00007ffe99c37798 RCX: 00007fd0c998f9a4
RDX: 0000000000000000 RSI: 00007ffe99c38f1e RDI: 00000000ffffff9c
RBP: 00007ffe99c38f1e R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffe99c377b0 R14: 000056109fa30670 R15: 00007fd0c9b4aa80
</TASK>

Allocated by task 5003:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x30/0x60 mm/kasan/common.c:68
poison_kmalloc_redzone mm/kasan/common.c:370 [inline]
__kasan_kmalloc+0x98/0xb0 mm/kasan/common.c:387
kasan_kmalloc include/linux/kasan.h:211 [inline]
kmalloc_trace+0x1e6/0x400 mm/slub.c:4012
kmalloc include/linux/slab.h:590 [inline]
kzalloc include/linux/slab.h:711 [inline]
em28xx_v4l2_init+0x107/0x2dd0 drivers/media/usb/em28xx/em28xx-video.c:2539
em28xx_init_extension+0x11f/0x1c0 drivers/media/usb/em28xx/em28xx-core.c:1116
process_scheduled_works+0x96f/0x1490 kernel/workqueue.c:2633
worker_thread+0xa5f/0xff0 kernel/workqueue.c:2787
kthread+0x2cd/0x360 kernel/kthread.c:388
ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:243

Freed by task 5003:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x30/0x60 mm/kasan/common.c:68
kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:589
poison_slab_object+0xa6/0xe0 mm/kasan/common.c:240
__kasan_slab_free+0x37/0x60 mm/kasan/common.c:256
kasan_slab_free include/linux/kasan.h:184 [inline]
slab_free_hook mm/slub.c:2121 [inline]
slab_free mm/slub.c:4299 [inline]
kfree+0x14a/0x370 mm/slub.c:4409
em28xx_free_v4l2 drivers/media/usb/em28xx/em28xx-video.c:2120 [inline]
kref_put include/linux/kref.h:65 [inline]
em28xx_v4l2_init+0x1618/0x2dd0 drivers/media/usb/em28xx/em28xx-video.c:2909
em28xx_init_extension+0x11f/0x1c0 drivers/media/usb/em28xx/em28xx-core.c:1116
process_scheduled_works+0x96f/0x1490 kernel/workqueue.c:2633
worker_thread+0xa5f/0xff0 kernel/workqueue.c:2787
kthread+0x2cd/0x360 kernel/kthread.c:388
ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:243

The buggy address belongs to the object at ffff8880257b8000
which belongs to the cache kmalloc-8k of size 8192
The buggy address is located 2048 bytes inside of
freed 8192-byte region [ffff8880257b8000, ffff8880257ba000)

The buggy address belongs to the physical page:
page:ffffea000095ee00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x257b8
head:ffffea000095ee00 order:3 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000840(slab|head|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 00fff00000000840 ffff888011442280 ffffea00007c9c00 0000000000000006
raw: 0000000000000000 0000000080020002 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd28c0(GFP_NOWAIT|__GFP_IO|__GFP_FS|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 4662, tgid 4662 (dhcpcd), ts 31219348806, free_ts 31206911230
prep_new_page mm/page_alloc.c:1540 [inline]
get_page_from_freelist+0x3355/0x34e0 mm/page_alloc.c:3311
__alloc_pages+0x255/0x670 mm/page_alloc.c:4567
alloc_slab_page+0x5f/0x150 include/linux/gfp.h:238
new_slab+0x84/0x2f0 mm/slub.c:2354
___slab_alloc+0xc77/0x1310 mm/slub.c:3540
__kmalloc_node_track_caller+0x2e9/0x570 mm/slub.c:3625
kmalloc_reserve+0xf3/0x260 net/core/skbuff.c:582
__alloc_skb+0x19f/0x3d0 net/core/skbuff.c:651
alloc_skb include/linux/skbuff.h:1296 [inline]
netlink_dump+0x204/0xc70 net/netlink/af_netlink.c:2231
netlink_recvmsg+0x671/0x10f0 net/netlink/af_netlink.c:1990
____sys_recvmsg+0x28b/0x570 net/socket.c:1046
__sys_recvmsg+0x280/0x360 net/socket.c:2845
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x85/0x160 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b
page last free pid 4662 tgid 4662 stack trace:
free_unref_page_prepare+0x94d/0xa60 include/linux/page_owner.h:24
free_unref_page+0x37/0x3f0 mm/page_alloc.c:2486
__put_partials+0xeb/0x130 mm/slub.c:2453
put_cpu_partial+0x169/0x240 mm/slub.c:2997
__slab_free+0x2c3/0x400 mm/slub.c:4166
qlist_free_all+0x5e/0xc0 mm/kasan/quarantine.c:163
kasan_quarantine_reduce+0x14b/0x160 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x23/0x70 mm/kasan/common.c:322
kasan_slab_alloc include/linux/kasan.h:201 [inline]
slab_post_alloc_hook mm/slub.c:3813 [inline]
slab_alloc_node mm/slub.c:3860 [inline]
__do_kmalloc_node mm/slub.c:3980 [inline]
__kmalloc+0x1dd/0x540 mm/slub.c:3994
kmalloc include/linux/slab.h:594 [inline]
tomoyo_add_entry security/tomoyo/common.c:2023 [inline]
tomoyo_supervisor+0xdf1/0x1370 security/tomoyo/common.c:2095
tomoyo_path_permission+0x243/0x360 security/tomoyo/file.c:168
tomoyo_path_perm+0x442/0x5b0 security/tomoyo/file.c:838
security_inode_getattr+0xd3/0x120 security/security.c:2238
vfs_fstatat+0xca/0x1b0 fs/stat.c:173
__se_sys_newfstatat fs/stat.c:468 [inline]
__x64_sys_newfstatat+0xff/0x170 fs/stat.c:462
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x85/0x160 arch/x86/entry/common.c:83

Memory state around the buggy address:
ffff8880257b8700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880257b8780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8880257b8800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8880257b8880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880257b8900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


Tested on:

commit: 04b8076d Merge tag 'firewire-fixes-6.8-rc7' of git://g..
console output: https://syzkaller.appspot.com/x/log.txt?x=10309dca180000
kernel config: https://syzkaller.appspot.com/x/.config?x=fa01a41dc74de670
dashboard link: https://syzkaller.appspot.com/bug?extid=b2391895514ed9ef4a8e
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=112b2732180000

Hillf Danton

unread,
Mar 2, 2024, 8:44:06 PMMar 2
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Mon, 15 Feb 2021 07:18:22 -0800
> syzbot found the following issue on:
>
> HEAD commit: 291009f6 Merge tag 'pm-5.11-rc8' of git://git.kernel.org/p..
> git tree: upstream
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=17179dd4d00000

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

--- x/drivers/media/usb/em28xx/em28xx-video.c
+++ y/drivers/media/usb/em28xx/em28xx-video.c
@@ -2152,6 +2152,10 @@ static int em28xx_v4l2_open(struct file
if (mutex_lock_interruptible(&dev->lock))
return -ERESTARTSYS;

+ if (!dev->v4l2) {
+ mutex_unlock(&dev->lock);
+ return -ENODEV;
+ }
ret = v4l2_fh_open(filp);
if (ret) {
dev_err(&dev->intf->dev,
@@ -2161,6 +2165,7 @@ static int em28xx_v4l2_open(struct file
return ret;
}

+ v4l2 = dev->v4l2;
if (v4l2->users == 0) {
em28xx_set_mode(dev, EM28XX_ANALOG_MODE);

@@ -2376,10 +2381,17 @@ static const struct v4l2_ioctl_ops video
#endif
};

+static void em28xx_video_device_release(struct video_device *vd)
+{
+ struct em28xx_v4l2 *v4l2 = container_of(vd, struct em28xx_v4l2, vdev);
+
+ kref_put(&v4l2->ref, em28xx_free_v4l2);
+}
+
static const struct video_device em28xx_video_template = {
.fops = &em28xx_v4l_fops,
.ioctl_ops = &video_ioctl_ops,
- .release = video_device_release_empty,
+ .release = em28xx_video_device_release,
.tvnorms = V4L2_STD_ALL,
};

@@ -2788,6 +2800,7 @@ static int em28xx_v4l2_init(struct em28x
"unable to register video device (error=%i).\n", ret);
goto unregister_dev;
}
+ kref_get(&v4l2->ref); /* put by video_unregister_device() */

/* Allocate and fill vbi video_device struct */
if (em28xx_vbi_supported(dev) == 1) {
--

syzbot

unread,
Mar 2, 2024, 9:55:05 PMMar 2
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+b23918...@syzkaller.appspotmail.com

Tested on:

commit: 04b8076d Merge tag 'firewire-fixes-6.8-rc7' of git://g..
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
console output: https://syzkaller.appspot.com/x/log.txt?x=12012abc180000
kernel config: https://syzkaller.appspot.com/x/.config?x=fa01a41dc74de670
dashboard link: https://syzkaller.appspot.com/bug?extid=b2391895514ed9ef4a8e
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=1709bcf2180000

Note: testing is done by a robot and is best-effort only.
Reply all
Reply to author
Forward
0 new messages