linux-brain/drivers/block
Sun Ke 1c4962df93 nbd: Fix NULL pointer in flush_workqueue
[ Upstream commit 79ebe9110fa458d58f1fceb078e2068d7ad37390 ]

Open /dev/nbdX first, the config_refs will be 1 and
the pointers in nbd_device are still null. Disconnect
/dev/nbdX, then reference a null recv_workq. The
protection by config_refs in nbd_genl_disconnect is useless.

[  656.366194] BUG: kernel NULL pointer dereference, address: 0000000000000020
[  656.368943] #PF: supervisor write access in kernel mode
[  656.369844] #PF: error_code(0x0002) - not-present page
[  656.370717] PGD 10cc87067 P4D 10cc87067 PUD 1074b4067 PMD 0
[  656.371693] Oops: 0002 [#1] SMP
[  656.372242] CPU: 5 PID: 7977 Comm: nbd-client Not tainted 5.11.0-rc5-00040-g76c057c84d28 #1
[  656.373661] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20190727_073836-buildvm-ppc64le-16.ppc.fedoraproject.org-3.fc31 04/01/2014
[  656.375904] RIP: 0010:mutex_lock+0x29/0x60
[  656.376627] Code: 00 0f 1f 44 00 00 55 48 89 fd 48 83 05 6f d7 fe 08 01 e8 7a c3 ff ff 48 83 05 6a d7 fe 08 01 31 c0 65 48 8b 14 25 00 6d 01 00 <f0> 48 0f b1 55 d
[  656.378934] RSP: 0018:ffffc900005eb9b0 EFLAGS: 00010246
[  656.379350] RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
[  656.379915] RDX: ffff888104cf2600 RSI: ffffffffaae8f452 RDI: 0000000000000020
[  656.380473] RBP: 0000000000000020 R08: 0000000000000000 R09: ffff88813bd6b318
[  656.381039] R10: 00000000000000c7 R11: fefefefefefefeff R12: ffff888102710b40
[  656.381599] R13: ffffc900005eb9e0 R14: ffffffffb2930680 R15: ffff88810770ef00
[  656.382166] FS:  00007fdf117ebb40(0000) GS:ffff88813bd40000(0000) knlGS:0000000000000000
[  656.382806] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  656.383261] CR2: 0000000000000020 CR3: 0000000100c84000 CR4: 00000000000006e0
[  656.383819] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[  656.384370] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[  656.384927] Call Trace:
[  656.385111]  flush_workqueue+0x92/0x6c0
[  656.385395]  nbd_disconnect_and_put+0x81/0xd0
[  656.385716]  nbd_genl_disconnect+0x125/0x2a0
[  656.386034]  genl_family_rcv_msg_doit.isra.0+0x102/0x1b0
[  656.386422]  genl_rcv_msg+0xfc/0x2b0
[  656.386685]  ? nbd_ioctl+0x490/0x490
[  656.386954]  ? genl_family_rcv_msg_doit.isra.0+0x1b0/0x1b0
[  656.387354]  netlink_rcv_skb+0x62/0x180
[  656.387638]  genl_rcv+0x34/0x60
[  656.387874]  netlink_unicast+0x26d/0x590
[  656.388162]  netlink_sendmsg+0x398/0x6c0
[  656.388451]  ? netlink_rcv_skb+0x180/0x180
[  656.388750]  ____sys_sendmsg+0x1da/0x320
[  656.389038]  ? ____sys_recvmsg+0x130/0x220
[  656.389334]  ___sys_sendmsg+0x8e/0xf0
[  656.389605]  ? ___sys_recvmsg+0xa2/0xf0
[  656.389889]  ? handle_mm_fault+0x1671/0x21d0
[  656.390201]  __sys_sendmsg+0x6d/0xe0
[  656.390464]  __x64_sys_sendmsg+0x23/0x30
[  656.390751]  do_syscall_64+0x45/0x70
[  656.391017]  entry_SYSCALL_64_after_hwframe+0x44/0xa9

To fix it, just add if (nbd->recv_workq) to nbd_disconnect_and_put().

Fixes: e9e006f5fc ("nbd: fix max number of supported devs")
Signed-off-by: Sun Ke <sunke32@huawei.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Link: https://lore.kernel.org/r/20210512114331.1233964-2-sunke32@huawei.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-05-19 10:08:30 +02:00
..
aoe block: aoe: Fix kernel crash due to atomic sleep when exiting 2019-08-08 07:29:02 -06:00
drbd block: drbd: remove a stray unlock in __drbd_send_protocol() 2019-11-08 06:55:22 -07:00
mtip32xx block: mtip32xx: Remove call to memset after dma_alloc_coherent 2019-06-29 09:42:50 -06:00
paride paride/pcd: need to check if cd->disk is null in pcd_detect 2019-09-04 07:04:37 -06:00
rsxx block: rsxx: fix error return code of rsxx_pci_probe() 2021-03-17 17:03:56 +01:00
xen-blkback xen-blkback: fix compatibility bug with single page rings 2021-05-14 09:44:23 +02:00
zram zram: fix return value on writeback_store 2021-03-17 17:03:57 +01:00
Kconfig block: rsxx: select CONFIG_CRC32 2021-01-17 14:05:36 +01:00
Makefile drivers/block: Remove DAC960 driver 2018-10-17 09:42:30 -06:00
amiflop.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
ataflop.c ataflop: Mark expected switch fall-through 2019-07-29 15:24:58 -06:00
brd.c brd: check and limit max_part par 2020-02-24 08:37:02 +01:00
cryptoloop.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 30 2019-05-24 17:27:10 +02:00
floppy.c floppy: reintroduce O_NDELAY fix 2021-03-04 10:26:47 +01:00
loop.c block: loop: set discard granularity and alignment for block device backed loop 2020-09-03 11:27:01 +02:00
loop.h block/loop: Use global lock for ioctl() operation. 2018-11-08 06:30:11 -07:00
nbd.c nbd: Fix NULL pointer in flush_workqueue 2021-05-19 10:08:30 +02:00
null_blk.h null_blk: format pr_* logs with pr_fmt 2019-09-16 08:38:29 -06:00
null_blk_main.c null_blk: fix passing of REQ_FUA flag in null_handle_rq 2020-09-03 11:26:55 +02:00
null_blk_zoned.c drivers/block/null_blk/main: Fix a double free in null_init. 2021-05-14 09:44:26 +02:00
pktcdvd.c pktcdvd: remove warning on attempting to register non-passthrough dev 2019-09-22 10:01:05 -06:00
ps3disk.c ps3disk: use the default segment boundary 2020-06-24 17:50:15 +02:00
ps3vram.c block/ps3vram: Use %llu to format sector_t after LBDAF removal 2019-06-13 03:17:50 -06:00
rbd.c rbd: require global CAP_SYS_ADMIN for mapping and unmapping 2020-09-17 13:47:53 +02:00
rbd_types.h rbd: support for object-map and fast-diff 2019-07-08 14:01:45 +02:00
skd_main.c Linux 5.2-rc6 2019-07-01 08:16:08 -06:00
skd_s1120.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 497 2019-06-19 17:09:53 +02:00
sunvdc.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
swim.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
swim3.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
swim_asm.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
sx8.c sx8: use a per-host tag_set 2018-11-09 08:14:14 -07:00
umem.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 349 2019-06-05 17:37:08 +02:00
umem.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 348 2019-06-05 17:37:08 +02:00
virtio_blk.c block: virtio_blk: fix handling single range discard request 2020-09-03 11:26:54 +02:00
xen-blkfront.c xen-blkfront: allow discard-* nodes to be optional 2021-02-03 23:25:58 +01:00
xsysace.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
z2ram.c powerpc updates for 4.20 2018-10-26 14:36:21 -07:00