Commit 25966fc
ublk: fix NULL pointer dereference in ublk_ctrl_set_size()
ublk_ctrl_set_size() unconditionally dereferences ub->ub_disk via
set_capacity_and_notify() without checking if it is NULL.
ub->ub_disk is NULL before UBLK_CMD_START_DEV completes (it is only
assigned in ublk_ctrl_start_dev()) and after UBLK_CMD_STOP_DEV runs
(ublk_detach_disk() sets it to NULL). Since the UBLK_CMD_UPDATE_SIZE
handler performs no state validation, a user can trigger a NULL pointer
dereference by sending UPDATE_SIZE to a device that has been added but
not yet started, or one that has been stopped.
Fix this by checking ub->ub_disk under ub->mutex before dereferencing
it, and returning -ENODEV if the disk is not available.
Fixes: 98b9956 ("ublk: Add UBLK_U_CMD_UPDATE_SIZE")
Cc: [email protected]
Signed-off-by: Mehul Rao <[email protected]>
Reviewed-by: Ming Lei <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>1 parent ce8ee85 commit 25966fc
1 file changed
Lines changed: 9 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5003 | 5003 | | |
5004 | 5004 | | |
5005 | 5005 | | |
5006 | | - | |
| 5006 | + | |
5007 | 5007 | | |
5008 | 5008 | | |
5009 | 5009 | | |
| 5010 | + | |
5010 | 5011 | | |
5011 | 5012 | | |
| 5013 | + | |
| 5014 | + | |
| 5015 | + | |
| 5016 | + | |
5012 | 5017 | | |
5013 | 5018 | | |
| 5019 | + | |
5014 | 5020 | | |
| 5021 | + | |
5015 | 5022 | | |
5016 | 5023 | | |
5017 | 5024 | | |
| |||
5331 | 5338 | | |
5332 | 5339 | | |
5333 | 5340 | | |
5334 | | - | |
5335 | | - | |
| 5341 | + | |
5336 | 5342 | | |
5337 | 5343 | | |
5338 | 5344 | | |
| |||
0 commit comments