kernel-fxtec-pro1x/drivers/block
Josef Bacik 1f032ca298 nbd: handle racing with error'ed out commands
[ Upstream commit 7ce23e8e0a9cd38338fc8316ac5772666b565ca9 ]

We hit the following warning in production

print_req_error: I/O error, dev nbd0, sector 7213934408 flags 80700
------------[ cut here ]------------
refcount_t: underflow; use-after-free.
WARNING: CPU: 25 PID: 32407 at lib/refcount.c:190 refcount_sub_and_test_checked+0x53/0x60
Workqueue: knbd-recv recv_work [nbd]
RIP: 0010:refcount_sub_and_test_checked+0x53/0x60
Call Trace:
 blk_mq_free_request+0xb7/0xf0
 blk_mq_complete_request+0x62/0xf0
 recv_work+0x29/0xa1 [nbd]
 process_one_work+0x1f5/0x3f0
 worker_thread+0x2d/0x3d0
 ? rescuer_thread+0x340/0x340
 kthread+0x111/0x130
 ? kthread_create_on_node+0x60/0x60
 ret_from_fork+0x1f/0x30
---[ end trace b079c3c67f98bb7c ]---

This was preceded by us timing out everything and shutting down the
sockets for the device.  The problem is we had a request in the queue at
the same time, so we completed the request twice.  This can actually
happen in a lot of cases, we fail to get a ref on our config, we only
have one connection and just error out the command, etc.

Fix this by checking cmd->status in nbd_read_stat.  We only change this
under the cmd->lock, so we are safe to check this here and see if we've
already error'ed this command out, which would indicate that we've
completed it as well.

Reviewed-by: Mike Christie <mchristi@redhat.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-11-10 11:27:35 +01:00
..
aoe
drbd drbd: dynamically allocate shash descriptor 2019-08-16 10:12:48 +02:00
mtip32xx
paride
rsxx
xen-blkback xen/blkback: fix memory leaks 2019-09-06 10:21:57 +02:00
zram zram: fix race between backing_dev_show and backing_dev_store 2019-11-06 13:05:10 +01:00
amiflop.c
ataflop.c
brd.c
cryptoloop.c
DAC960.c
DAC960.h
floppy.c floppy: fix usercopy direction 2019-09-21 07:17:14 +02:00
Kconfig
loop.c loop: Add LOOP_SET_DIRECT_IO to compat ioctl 2019-10-05 13:09:39 +02:00
loop.h
Makefile
nbd.c nbd: handle racing with error'ed out commands 2019-11-10 11:27:35 +01:00
null_blk.h
null_blk_main.c block: null_blk: fix race condition for null_del_dev 2019-07-26 09:14:07 +02:00
null_blk_zoned.c
pktcdvd.c pktcdvd: remove warning on attempting to register non-passthrough dev 2019-10-07 18:57:15 +02:00
ps3disk.c
ps3vram.c
rbd.c
rbd_types.h
skd_main.c
skd_s1120.h
sunvdc.c
swim.c
swim3.c
swim_asm.S
sx8.c
umem.c
umem.h
virtio_blk.c
xen-blkfront.c
xsysace.c
z2ram.c