Archive-only list for patches
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 6.12 01/21] ublk: sanity check add_dev input for underflow
@ 2025-06-30 20:45 Sasha Levin
  2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 02/21] atm: idt77252: Add missing `dma_map_error()` Sasha Levin
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: Sasha Levin @ 2025-06-30 20:45 UTC (permalink / raw)
  To: patches, stable
  Cc: Ronnie Sahlberg, Ming Lei, Jens Axboe, Sasha Levin, linux-block

From: Ronnie Sahlberg <rsahlberg@whamcloud.com>

[ Upstream commit 969127bf0783a4ac0c8a27e633a9e8ea1738583f ]

Add additional checks that queue depth and number of queues are
non-zero.

Signed-off-by: Ronnie Sahlberg <rsahlberg@whamcloud.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20250626022046.235018-1-ronniesahlberg@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

**YES**

This commit should be backported to stable kernel trees for the
following reasons:

**1. Fixes a Critical Input Validation Bug**
The commit addresses a serious bug where userspace could pass zero
values for `queue_depth` or `nr_hw_queues`, leading to:
- Memory allocation failures (`kcalloc(0, ubq_size, GFP_KERNEL)` in
  `ublk_init_queues()`)
- Non-functional block devices with zero queues
- Potential kernel crashes or undefined behavior

**2. Minimal and Contained Fix**
The change is extremely minimal - just adding two checks to an existing
validation:
```diff
- if (info.queue_depth > UBLK_MAX_QUEUE_DEPTH || info.nr_hw_queues >
  UBLK_MAX_NR_QUEUES)
+       if (info.queue_depth > UBLK_MAX_QUEUE_DEPTH || !info.queue_depth
||
+           info.nr_hw_queues > UBLK_MAX_NR_QUEUES ||
!info.nr_hw_queues)
```

**3. Prevents Security/Stability Issues**
Based on the kernel source analysis:
- `ublk_init_queues()` uses these values directly for memory allocation
- Multiple loops iterate based on `nr_hw_queues` - zero would skip all
  initialization
- The block layer's `blk_mq_alloc_tag_set()` expects non-zero values

**4. Similar to Previously Backported Commits**
This is very similar to "block: ublk: extending queue_size to fix
overflow" (Similar Commit #2), which was marked YES for backporting.
Both fix input validation issues that could cause memory/stability
problems.

**5. Clear Bug Fix Following Stable Rules**
- Fixes a real bug (not theoretical)
- No new features or architectural changes
- Minimal risk - simply rejects invalid input
- Confined to the ublk subsystem
- Prevents userspace from creating broken/dangerous kernel state

The commit prevents userspace from triggering undefined behavior in the
kernel by passing invalid parameters, which is exactly the type of bug
fix that belongs in stable kernels.

 drivers/block/ublk_drv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 746ef36e58df2..3b1a5cdd63116 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -2457,7 +2457,8 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd)
 	if (copy_from_user(&info, argp, sizeof(info)))
 		return -EFAULT;
 
-	if (info.queue_depth > UBLK_MAX_QUEUE_DEPTH || info.nr_hw_queues > UBLK_MAX_NR_QUEUES)
+	if (info.queue_depth > UBLK_MAX_QUEUE_DEPTH || !info.queue_depth ||
+	    info.nr_hw_queues > UBLK_MAX_NR_QUEUES || !info.nr_hw_queues)
 		return -EINVAL;
 
 	if (capable(CAP_SYS_ADMIN))
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2025-06-30 21:00 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-30 20:45 [PATCH AUTOSEL 6.12 01/21] ublk: sanity check add_dev input for underflow Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 02/21] atm: idt77252: Add missing `dma_map_error()` Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 03/21] um: vector: Reduce stack usage in vector_eth_configure() Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 04/21] ASoC: SOF: Intel: hda: Use devm_kstrdup() to avoid memleak Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 05/21] Revert "PCI/ACPI: Fix allocated memory release on error in pci_acpi_scan_root()" Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 06/21] ALSA: hda/realtek: Add mic-mute LED setup for ASUS UM5606 Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 07/21] io_uring: make fallocate be hashed work Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 08/21] ASoC: amd: yc: add quirk for Acer Nitro ANV15-41 internal mic Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 09/21] ALSA: hda/realtek - Enable mute LED on HP Pavilion Laptop 15-eg100 Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 10/21] ALSA: hda/realtek: Add quirks for some Clevo laptops Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 11/21] net: usb: qmi_wwan: add SIMCom 8230C composition Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 12/21] driver: bluetooth: hci_qca:fix unable to load the BT driver Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 13/21] HID: lenovo: Add support for ThinkPad X1 Tablet Thin Keyboard Gen2 Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 14/21] net: mana: Record doorbell physical address in PF mode Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 15/21] btrfs: fix assertion when building free space tree Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 16/21] vt: add missing notification when switching back to text mode Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 17/21] bpf: Adjust free target to avoid global starvation of LRU map Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 18/21] riscv: vdso: Exclude .rodata from the PT_DYNAMIC segment Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 19/21] HID: Add IGNORE quirk for SMARTLINKTECHNOLOGY Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 20/21] HID: quirks: Add quirk for 2 Chicony Electronics HP 5MP Cameras Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 21/21] HID: nintendo: avoid bluetooth suspend/resume stalls Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox