bisecting fixing commit since 68d7a45eec101bc1550294c0e675a490c047b2e5 building syzkaller on 8e3c52b11d5d0843be47f41e00c5612ce29811b0 testing commit 68d7a45eec101bc1550294c0e675a490c047b2e5 with gcc (GCC) 8.1.0 kernel signature: 6d895a0ce85519d7eeaba38cd3ecae6e888524dd run #0: crashed: WARNING in kernfs_get run #1: crashed: WARNING in kernfs_get run #2: crashed: general protection fault in kernfs_add_one run #3: crashed: WARNING in kernfs_get run #4: crashed: WARNING in kernfs_get run #5: crashed: general protection fault in kernfs_add_one run #6: crashed: WARNING in kernfs_get run #7: crashed: WARNING in hci_unregister_dev run #8: crashed: WARNING in kernfs_get run #9: crashed: WARNING in kernfs_get testing current HEAD fbc5fe7a54d02e11972e3b2a5ddb6ffc88162c8f testing commit fbc5fe7a54d02e11972e3b2a5ddb6ffc88162c8f with gcc (GCC) 8.1.0 kernel signature: 0a4a1e1af1b74c8e5204f36388be9cb31c8ca682 all runs: OK # git bisect start fbc5fe7a54d02e11972e3b2a5ddb6ffc88162c8f 68d7a45eec101bc1550294c0e675a490c047b2e5 Bisecting: 1769 revisions left to test after this (roughly 11 steps) [2fe68d4d100b478012862058c14f62717a0f56d2] drbd: dynamically allocate shash descriptor testing commit 2fe68d4d100b478012862058c14f62717a0f56d2 with gcc (GCC) 8.1.0 kernel signature: 728743a3d177fabaf8c906aa4d40a80c3b3fb67b run #0: crashed: WARNING in kernfs_get run #1: crashed: WARNING in kernfs_get run #2: crashed: WARNING: refcount bug in hci_register_dev run #3: crashed: WARNING in kernfs_get run #4: crashed: WARNING in kernfs_get run #5: crashed: WARNING in kernfs_get run #6: crashed: WARNING in kernfs_get run #7: crashed: WARNING in kernfs_get run #8: crashed: WARNING in kernfs_get run #9: crashed: WARNING in kernfs_get # git bisect good 2fe68d4d100b478012862058c14f62717a0f56d2 Bisecting: 884 revisions left to test after this (roughly 10 steps) [f5ae861d9ad8c7834a255ceaee39fc9cb0e56163] kvm: apic: Flush TLB after APIC mode/address change if VPIDs are in use testing commit f5ae861d9ad8c7834a255ceaee39fc9cb0e56163 with gcc (GCC) 8.1.0 kernel signature: 9aa7038d2582957ae61070dcc43c9e2928714829 all runs: OK # git bisect bad f5ae861d9ad8c7834a255ceaee39fc9cb0e56163 Bisecting: 442 revisions left to test after this (roughly 9 steps) [b6a2d6c11272b3cf5d2d902bb9aaf7558560a5eb] nfc: enforce CAP_NET_RAW for raw sockets testing commit b6a2d6c11272b3cf5d2d902bb9aaf7558560a5eb with gcc (GCC) 8.1.0 kernel signature: c94805658773040da7c2417245e2b89ebe344602 all runs: OK # git bisect bad b6a2d6c11272b3cf5d2d902bb9aaf7558560a5eb Bisecting: 220 revisions left to test after this (roughly 8 steps) [3a647417696217c5861a81ccfe5d2e6791d696ac] x86/ptrace: fix up botched merge of spectrev1 fix testing commit 3a647417696217c5861a81ccfe5d2e6791d696ac with gcc (GCC) 8.1.0 kernel signature: 9ee85e74fa693b211d96b9112ca9ba94cf2aef0d run #0: crashed: WARNING in kernfs_get run #1: crashed: WARNING in kernfs_get run #2: crashed: WARNING in kernfs_get run #3: crashed: WARNING: refcount bug in hci_register_dev run #4: crashed: WARNING in kernfs_get run #5: crashed: WARNING in kernfs_get run #6: crashed: general protection fault in kernfs_add_one run #7: crashed: WARNING in kernfs_get run #8: crashed: general protection fault in kernfs_add_one run #9: crashed: WARNING in kernfs_get # git bisect good 3a647417696217c5861a81ccfe5d2e6791d696ac Bisecting: 110 revisions left to test after this (roughly 7 steps) [4e268e9c404a3565acfdc21af71e3bce5531b839] HID: wacom: generic: read HID_DG_CONTACTMAX from any feature report testing commit 4e268e9c404a3565acfdc21af71e3bce5531b839 with gcc (GCC) 8.1.0 kernel signature: 139ff7fa59b8e01c53e1b84a344699347805f06d all runs: OK # git bisect bad 4e268e9c404a3565acfdc21af71e3bce5531b839 Bisecting: 54 revisions left to test after this (roughly 6 steps) [28400323ea2e541b22666dfd62b6836bc97d629b] batman-adv: Only read OGM tvlv_len after buffer len check testing commit 28400323ea2e541b22666dfd62b6836bc97d629b with gcc (GCC) 8.1.0 kernel signature: 66cc31b8ad91152213564283845e1070a79f1fd2 run #0: crashed: general protection fault in kernfs_add_one run #1: crashed: WARNING in kernfs_get run #2: crashed: WARNING in kernfs_get run #3: crashed: WARNING: refcount bug in hci_register_dev run #4: crashed: WARNING in kernfs_get run #5: crashed: WARNING in kernfs_get run #6: crashed: general protection fault in kernfs_add_one run #7: crashed: WARNING in rfkill_unregister run #8: crashed: WARNING in kernfs_get run #9: crashed: WARNING in kernfs_get # git bisect good 28400323ea2e541b22666dfd62b6836bc97d629b Bisecting: 27 revisions left to test after this (roughly 5 steps) [a26cf23ddf7311edd0237a3c010bc11f068f3dce] gpio: fix line flag validation in lineevent_create testing commit a26cf23ddf7311edd0237a3c010bc11f068f3dce with gcc (GCC) 8.1.0 kernel signature: fb72bc24f1aefe1a5011c29f786554d69c553629 run #0: crashed: WARNING in kernfs_get run #1: crashed: WARNING: refcount bug in hci_register_dev run #2: crashed: general protection fault in kernfs_add_one run #3: crashed: general protection fault in kernfs_add_one run #4: crashed: WARNING in kernfs_get run #5: crashed: WARNING: refcount bug in hci_register_dev run #6: crashed: WARNING: refcount bug in hci_register_dev run #7: crashed: WARNING: refcount bug in hci_register_dev run #8: crashed: WARNING in kernfs_get run #9: crashed: WARNING: refcount bug in hci_register_dev # git bisect good a26cf23ddf7311edd0237a3c010bc11f068f3dce Bisecting: 13 revisions left to test after this (roughly 4 steps) [5432923a6b208b253d95d95cee72d0508c803421] driver core: Fix use-after-free and double free on glue directory testing commit 5432923a6b208b253d95d95cee72d0508c803421 with gcc (GCC) 8.1.0 kernel signature: 53c4c8ff4b7c8e7cc6dc2c09a45968d8a84dd37f all runs: OK # git bisect bad 5432923a6b208b253d95d95cee72d0508c803421 Bisecting: 6 revisions left to test after this (roughly 3 steps) [263c71d2d440ed6a9d36e822970c9b5cce98811b] MIPS: VDSO: Use same -m%-float cflag as the kernel proper testing commit 263c71d2d440ed6a9d36e822970c9b5cce98811b with gcc (GCC) 8.1.0 kernel signature: d0c755fe7bf4f108ab2c73879443ce90b80bb793 run #0: crashed: WARNING in kernfs_get run #1: crashed: WARNING in kernfs_get run #2: crashed: WARNING: refcount bug in hci_register_dev run #3: crashed: WARNING: refcount bug in hci_register_dev run #4: crashed: WARNING: refcount bug in hci_register_dev run #5: crashed: general protection fault in kernfs_add_one run #6: crashed: WARNING in kernfs_get run #7: crashed: WARNING: refcount bug in hci_register_dev run #8: crashed: WARNING in kernfs_get run #9: crashed: WARNING in kernfs_get # git bisect good 263c71d2d440ed6a9d36e822970c9b5cce98811b Bisecting: 3 revisions left to test after this (roughly 2 steps) [f15b4d221f45904bd70b66b82be9bde62808068d] clk: rockchip: Don't yell about bad mmc phases when getting testing commit f15b4d221f45904bd70b66b82be9bde62808068d with gcc (GCC) 8.1.0 kernel signature: 598339af31fba1b14642b87eddd6918e87545378 run #0: crashed: WARNING in kernfs_get run #1: crashed: WARNING in kernfs_get run #2: crashed: WARNING in kernfs_get run #3: crashed: WARNING in kernfs_get run #4: crashed: WARNING in kernfs_get run #5: crashed: general protection fault in kernfs_add_one run #6: crashed: WARNING in kernfs_get run #7: crashed: WARNING in kernfs_get run #8: crashed: WARNING: refcount bug in hci_register_dev run #9: crashed: WARNING in kernfs_get # git bisect good f15b4d221f45904bd70b66b82be9bde62808068d Bisecting: 1 revision left to test after this (roughly 1 step) [75183476fea19b831e5814e5144d3136f3ee09c4] PCI: Always allow probing with driver_override testing commit 75183476fea19b831e5814e5144d3136f3ee09c4 with gcc (GCC) 8.1.0 kernel signature: d7ee45685e8d684a8f6895ec0a5fb3116d3d58ef run #0: crashed: WARNING in kernfs_get run #1: crashed: WARNING in hci_unregister_dev run #2: crashed: general protection fault in kernfs_add_one run #3: crashed: WARNING in kernfs_get run #4: crashed: WARNING: refcount bug in hci_register_dev run #5: crashed: WARNING: refcount bug in hci_register_dev run #6: crashed: general protection fault in kernfs_add_one run #7: crashed: WARNING in kernfs_get run #8: crashed: general protection fault in kernfs_add_one run #9: crashed: WARNING: refcount bug in hci_register_dev # git bisect good 75183476fea19b831e5814e5144d3136f3ee09c4 Bisecting: 0 revisions left to test after this (roughly 0 steps) [0369bbfe7ad21c1aea7b6379542eae810c8da278] ubifs: Correctly use tnc_next() in search_dh_cookie() testing commit 0369bbfe7ad21c1aea7b6379542eae810c8da278 with gcc (GCC) 8.1.0 kernel signature: 81e1ec50f05fb0298b2382379dbee4aeade8ff35 run #0: crashed: WARNING: refcount bug in hci_register_dev run #1: crashed: WARNING in kernfs_get run #2: crashed: general protection fault in kernfs_add_one run #3: crashed: general protection fault in kernfs_add_one run #4: crashed: WARNING: refcount bug in kobj_kset_leave run #5: crashed: general protection fault in kernfs_add_one run #6: crashed: WARNING: refcount bug in hci_register_dev run #7: crashed: WARNING: refcount bug in hci_register_dev run #8: crashed: WARNING: refcount bug in hci_register_dev run #9: crashed: WARNING in kernfs_get # git bisect good 0369bbfe7ad21c1aea7b6379542eae810c8da278 5432923a6b208b253d95d95cee72d0508c803421 is the first bad commit commit 5432923a6b208b253d95d95cee72d0508c803421 Author: Muchun Song Date: Sat Jul 27 11:21:22 2019 +0800 driver core: Fix use-after-free and double free on glue directory commit ac43432cb1f5c2950408534987e57c2071e24d8f upstream. There is a race condition between removing glue directory and adding a new device under the glue dir. It can be reproduced in following test: CPU1: CPU2: device_add() get_device_parent() class_dir_create_and_add() kobject_add_internal() create_dir() // create glue_dir device_add() get_device_parent() kobject_get() // get glue_dir device_del() cleanup_glue_dir() kobject_del(glue_dir) kobject_add() kobject_add_internal() create_dir() // in glue_dir sysfs_create_dir_ns() kernfs_create_dir_ns(sd) sysfs_remove_dir() // glue_dir->sd=NULL sysfs_put() // free glue_dir->sd // sd is freed kernfs_new_node(sd) kernfs_get(glue_dir) kernfs_add_one() kernfs_put() Before CPU1 remove last child device under glue dir, if CPU2 add a new device under glue dir, the glue_dir kobject reference count will be increase to 2 via kobject_get() in get_device_parent(). And CPU2 has been called kernfs_create_dir_ns(), but not call kernfs_new_node(). Meanwhile, CPU1 call sysfs_remove_dir() and sysfs_put(). This result in glue_dir->sd is freed and it's reference count will be 0. Then CPU2 call kernfs_get(glue_dir) will trigger a warning in kernfs_get() and increase it's reference count to 1. Because glue_dir->sd is freed by CPU1, the next call kernfs_add_one() by CPU2 will fail(This is also use-after-free) and call kernfs_put() to decrease reference count. Because the reference count is decremented to 0, it will also call kmem_cache_free() to free the glue_dir->sd again. This will result in double free. In order to avoid this happening, we also should make sure that kernfs_node for glue_dir is released in CPU1 only when refcount for glue_dir kobj is 1 to fix this race. The following calltrace is captured in kernel 4.14 with the following patch applied: commit 726e41097920 ("drivers: core: Remove glue dirs from sysfs earlier") -------------------------------------------------------------------------- [ 3.633703] WARNING: CPU: 4 PID: 513 at .../fs/kernfs/dir.c:494 Here is WARN_ON(!atomic_read(&kn->count) in kernfs_get(). .... [ 3.633986] Call trace: [ 3.633991] kernfs_create_dir_ns+0xa8/0xb0 [ 3.633994] sysfs_create_dir_ns+0x54/0xe8 [ 3.634001] kobject_add_internal+0x22c/0x3f0 [ 3.634005] kobject_add+0xe4/0x118 [ 3.634011] device_add+0x200/0x870 [ 3.634017] _request_firmware+0x958/0xc38 [ 3.634020] request_firmware_into_buf+0x4c/0x70 .... [ 3.634064] kernel BUG at .../mm/slub.c:294! Here is BUG_ON(object == fp) in set_freepointer(). .... [ 3.634346] Call trace: [ 3.634351] kmem_cache_free+0x504/0x6b8 [ 3.634355] kernfs_put+0x14c/0x1d8 [ 3.634359] kernfs_create_dir_ns+0x88/0xb0 [ 3.634362] sysfs_create_dir_ns+0x54/0xe8 [ 3.634366] kobject_add_internal+0x22c/0x3f0 [ 3.634370] kobject_add+0xe4/0x118 [ 3.634374] device_add+0x200/0x870 [ 3.634378] _request_firmware+0x958/0xc38 [ 3.634381] request_firmware_into_buf+0x4c/0x70 -------------------------------------------------------------------------- Fixes: 726e41097920 ("drivers: core: Remove glue dirs from sysfs earlier") Signed-off-by: Muchun Song Reviewed-by: Mukesh Ojha Signed-off-by: Prateek Sood Link: https://lore.kernel.org/r/20190727032122.24639-1-smuchun@gmail.com Signed-off-by: Greg Kroah-Hartman drivers/base/core.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) kernel signature: 53c4c8ff4b7c8e7cc6dc2c09a45968d8a84dd37f previous signature: 81e1ec50f05fb0298b2382379dbee4aeade8ff35 revisions tested: 14, total time: 3h22m19.919674202s (build: 1h49m25.753026548s, test: 1h28m36.356723275s) first good commit: 5432923a6b208b253d95d95cee72d0508c803421 driver core: Fix use-after-free and double free on glue directory cc: ["gregkh@linuxfoundation.org" "mojha@codeaurora.org" "prsood@codeaurora.org" "smuchun@gmail.com"]