Skip to content

Commit 0ce3774

Browse files
committed
Merge tag 'block-7.2-20260724' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux
Pull block fixes from Jens Axboe: - Fix a ublk recovery hang, where END_USER_RECOVERY without a successful START_USER_RECOVERY could be satisfied by a stale completion latch - Fix a stack out-of-bounds read in the CDROMVOLCTRL ioctl - MAINTAINERS email address update for Roger Pau Monne * tag 'block-7.2-20260724' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux: MAINTAINERS: update my email address cdrom: fix stack out-of-bounds read in CDROMVOLCTRL ublk: wait on ublk_dev_ready() instead of ub->completion
2 parents 73387b8 + 093fbff commit 0ce3774

3 files changed

Lines changed: 32 additions & 18 deletions

File tree

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29400,7 +29400,7 @@ F: net/xdp/
2940029400
F: tools/testing/selftests/bpf/*xsk*
2940129401

2940229402
XEN BLOCK SUBSYSTEM
29403-
M: Roger Pau Monné <roger.pau@citrix.com>
29403+
M: Roger Pau Monné <roger@xenproject.org>
2940429404
L: xen-devel@lists.xenproject.org (moderated for non-subscribers)
2940529405
S: Supported
2940629406
F: drivers/block/xen*

drivers/block/ublk_drv.c

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
#include <linux/errno.h>
2020
#include <linux/major.h>
2121
#include <linux/wait.h>
22+
#include <linux/wait_bit.h>
2223
#include <linux/blkdev.h>
2324
#include <linux/init.h>
2425
#include <linux/swap.h>
2526
#include <linux/slab.h>
2627
#include <linux/compat.h>
2728
#include <linux/mutex.h>
2829
#include <linux/writeback.h>
29-
#include <linux/completion.h>
3030
#include <linux/highmem.h>
3131
#include <linux/sysfs.h>
3232
#include <linux/miscdevice.h>
@@ -327,7 +327,6 @@ struct ublk_device {
327327

328328
struct ublk_params params;
329329

330-
struct completion completion;
331330
u32 nr_queue_ready;
332331
bool unprivileged_daemons;
333332
struct mutex cancel_mutex;
@@ -3054,12 +3053,12 @@ static void ublk_mark_io_ready(struct ublk_device *ub, u16 q_id,
30543053
if (ublk_dev_ready(ub)) {
30553054
/*
30563055
* All queues ready - clear device-level canceling flag
3057-
* and complete the recovery/initialization.
3056+
* and wake ublk_dev_ready() waiters.
30583057
*/
30593058
mutex_lock(&ub->cancel_mutex);
30603059
ub->canceling = false;
30613060
mutex_unlock(&ub->cancel_mutex);
3062-
complete_all(&ub->completion);
3061+
wake_up_var(&ub->nr_queue_ready);
30633062
}
30643063
}
30653064

@@ -4273,7 +4272,6 @@ static int ublk_init_queues(struct ublk_device *ub)
42734272
goto fail;
42744273
}
42754274

4276-
init_completion(&ub->completion);
42774275
return 0;
42784276

42794277
fail:
@@ -4417,6 +4415,26 @@ static bool ublk_validate_user_pid(struct ublk_device *ub, pid_t ublksrv_pid)
44174415
return ub->ublksrv_tgid == ublksrv_pid;
44184416
}
44194417

4418+
/*
4419+
* Wait until all queues have fetched their I/O commands, and return with
4420+
* ub->mutex held and readiness guaranteed: then every queue's ->canceling
4421+
* is cleared. Ready may regress between wakeup and mutex_lock() (F_BATCH
4422+
* UNPREP, daemon death), so re-check it under the mutex and wait again.
4423+
*/
4424+
static int ublk_wait_dev_ready_and_lock(struct ublk_device *ub)
4425+
{
4426+
while (true) {
4427+
if (wait_var_event_interruptible(&ub->nr_queue_ready,
4428+
ublk_dev_ready(ub)))
4429+
return -EINTR;
4430+
4431+
mutex_lock(&ub->mutex);
4432+
if (ublk_dev_ready(ub))
4433+
return 0;
4434+
mutex_unlock(&ub->mutex);
4435+
}
4436+
}
4437+
44204438
static int ublk_ctrl_start_dev(struct ublk_device *ub,
44214439
const struct ublksrv_ctrl_cmd *header)
44224440
{
@@ -4499,15 +4517,10 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
44994517
};
45004518
}
45014519

4502-
if (wait_for_completion_interruptible(&ub->completion) != 0)
4520+
if (ublk_wait_dev_ready_and_lock(ub))
45034521
return -EINTR;
45044522

4505-
if (!ublk_validate_user_pid(ub, ublksrv_pid))
4506-
return -EINVAL;
4507-
4508-
mutex_lock(&ub->mutex);
4509-
/* device may become not ready in case of F_BATCH */
4510-
if (!ublk_dev_ready(ub)) {
4523+
if (!ublk_validate_user_pid(ub, ublksrv_pid)) {
45114524
ret = -EINVAL;
45124525
goto out_unlock;
45134526
}
@@ -5071,7 +5084,6 @@ static int ublk_ctrl_start_recovery(struct ublk_device *ub)
50715084
goto out_unlock;
50725085
}
50735086
pr_devel("%s: start recovery for dev id %d\n", __func__, ub->ub_number);
5074-
init_completion(&ub->completion);
50755087
ret = 0;
50765088
out_unlock:
50775089
mutex_unlock(&ub->mutex);
@@ -5087,16 +5099,17 @@ static int ublk_ctrl_end_recovery(struct ublk_device *ub,
50875099
pr_devel("%s: Waiting for all FETCH_REQs, dev id %d...\n", __func__,
50885100
header->dev_id);
50895101

5090-
if (wait_for_completion_interruptible(&ub->completion))
5102+
if (ublk_wait_dev_ready_and_lock(ub))
50915103
return -EINTR;
50925104

50935105
pr_devel("%s: All FETCH_REQs received, dev id %d\n", __func__,
50945106
header->dev_id);
50955107

5096-
if (!ublk_validate_user_pid(ub, ublksrv_pid))
5097-
return -EINVAL;
5108+
if (!ublk_validate_user_pid(ub, ublksrv_pid)) {
5109+
ret = -EINVAL;
5110+
goto out_unlock;
5111+
}
50985112

5099-
mutex_lock(&ub->mutex);
51005113
if (ublk_nosrv_should_stop_dev(ub))
51015114
goto out_unlock;
51025115

drivers/cdrom/cdrom.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3187,6 +3187,7 @@ static noinline int mmc_ioctl_cdrom_volume(struct cdrom_device_info *cdi,
31873187

31883188
/* set volume */
31893189
cgc->buffer = buffer + offset - 8;
3190+
cgc->buflen -= offset - 8;
31903191
memset(cgc->buffer, 0, 8);
31913192
return cdrom_mode_select(cdi, cgc);
31923193
}

0 commit comments

Comments
 (0)