Commit 98c598a
nbd: pass nbd_sock to nbd_read_reply() instead of index
If a socket is processing ioctl 'NBD_SET_SOCK', config->socks might be
krealloc in nbd_add_socket(), and a garbage request is received now, a UAF
may occurs.
T1
nbd_ioctl
__nbd_ioctl
nbd_add_socket
blk_mq_freeze_queue
T2
recv_work
nbd_read_reply
sock_xmit
krealloc config->socks
def config->socks
Pass nbd_sock to nbd_read_reply(). And introduce a new function
sock_xmit_recv(), which differs from sock_xmit only in the way it get
socket.
==================================================================
BUG: KASAN: use-after-free in sock_xmit+0x525/0x550
Read of size 8 at addr ffff8880188ec428 by task kworker/u12:1/18779
Workqueue: knbd4-recv recv_work
Call Trace:
__dump_stack
dump_stack+0xbe/0xfd
print_address_description.constprop.0+0x19/0x170
__kasan_report.cold+0x6c/0x84
kasan_report+0x3a/0x50
sock_xmit+0x525/0x550
nbd_read_reply+0xfe/0x2c0
recv_work+0x1c2/0x750
process_one_work+0x6b6/0xf10
worker_thread+0xdd/0xd80
kthread+0x30a/0x410
ret_from_fork+0x22/0x30
Allocated by task 18784:
kasan_save_stack+0x1b/0x40
kasan_set_track
set_alloc_info
__kasan_kmalloc
__kasan_kmalloc.constprop.0+0xf0/0x130
slab_post_alloc_hook
slab_alloc_node
slab_alloc
__kmalloc_track_caller+0x157/0x550
__do_krealloc
krealloc+0x37/0xb0
nbd_add_socket
+0x2d3/0x880
__nbd_ioctl
nbd_ioctl+0x584/0x8e0
__blkdev_driver_ioctl
blkdev_ioctl+0x2a0/0x6e0
block_ioctl+0xee/0x130
vfs_ioctl
__do_sys_ioctl
__se_sys_ioctl+0x138/0x190
do_syscall_64+0x33/0x40
entry_SYSCALL_64_after_hwframe+0x61/0xc6
Freed by task 18784:
kasan_save_stack+0x1b/0x40
kasan_set_track+0x1c/0x30
kasan_set_free_info+0x20/0x40
__kasan_slab_free.part.0+0x13f/0x1b0
slab_free_hook
slab_free_freelist_hook
slab_free
kfree+0xcb/0x6c0
krealloc+0x56/0xb0
nbd_add_socket+0x2d3/0x880
__nbd_ioctl
nbd_ioctl+0x584/0x8e0
__blkdev_driver_ioctl
blkdev_ioctl+0x2a0/0x6e0
block_ioctl+0xee/0x130
vfs_ioctl
__do_sys_ioctl
__se_sys_ioctl+0x138/0x190
do_syscall_64+0x33/0x40
entry_SYSCALL_64_after_hwframe+0x61/0xc6
Signed-off-by: Li Nan <linan122@huawei.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20230911023308.3467802-1-linan666@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>1 parent db46cd1 commit 98c598a
1 file changed
Lines changed: 22 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
505 | 506 | | |
506 | 507 | | |
507 | 508 | | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
| 509 | + | |
| 510 | + | |
514 | 511 | | |
515 | | - | |
516 | | - | |
517 | 512 | | |
518 | 513 | | |
519 | 514 | | |
| |||
556 | 551 | | |
557 | 552 | | |
558 | 553 | | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
559 | 567 | | |
560 | 568 | | |
561 | 569 | | |
| |||
712 | 720 | | |
713 | 721 | | |
714 | 722 | | |
715 | | - | |
| 723 | + | |
716 | 724 | | |
717 | 725 | | |
718 | 726 | | |
| |||
721 | 729 | | |
722 | 730 | | |
723 | 731 | | |
724 | | - | |
| 732 | + | |
725 | 733 | | |
726 | 734 | | |
727 | 735 | | |
| |||
845 | 853 | | |
846 | 854 | | |
847 | 855 | | |
848 | | - | |
| 856 | + | |
849 | 857 | | |
850 | 858 | | |
851 | 859 | | |
852 | 860 | | |
853 | 861 | | |
854 | 862 | | |
855 | | - | |
| 863 | + | |
856 | 864 | | |
857 | 865 | | |
858 | 866 | | |
| |||
887 | 895 | | |
888 | 896 | | |
889 | 897 | | |
890 | | - | |
891 | 898 | | |
892 | 899 | | |
893 | 900 | | |
| |||
1231 | 1238 | | |
1232 | 1239 | | |
1233 | 1240 | | |
| 1241 | + | |
1234 | 1242 | | |
1235 | 1243 | | |
1236 | 1244 | | |
| |||
1413 | 1421 | | |
1414 | 1422 | | |
1415 | 1423 | | |
| 1424 | + | |
1416 | 1425 | | |
1417 | 1426 | | |
1418 | 1427 | | |
| |||
0 commit comments