All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/4] null_blk: validate configfs values before power-on
@ 2026-12-01 14:01 Yingjie Wang
  2026-12-01 14:02 ` [PATCH v4 1/4] block: move BLK_DEV_MAX_SECTORS to <linux/blkdev.h> Yingjie Wang
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Yingjie Wang @ 2026-12-01 14:01 UTC (permalink / raw)
  To: axboe@kernel.dk; +Cc: linux-block@vger.kernel.org, Damien Le Moal

This series fixes three bugs found while fuzzing null_blk's configfs
interface. Setting size or home_node to the values below and writing 1
to power triggers a crash:

  2/4  size=2^44 MiB with zoned=1 wraps the byte capacity to zero.
       The resulting zero zone count causes zone_nr_conv to underflow.
  3/4  size=2^40 MiB with zoned=1 and the default 256 MiB zone size
       requires 2^32 zones. Storing this count in nr_zones truncates
       it to zero, leading to the same failure.
  4/4  home_node=2147483647 is passed to kzalloc_node() without
       validation, causing an out-of-bounds access in SLUB.

Patch 1/4 moves BLK_DEV_MAX_SECTORS to <linux/blkdev.h> so that 2/4 can
check the configured size against it. The zone count overflow still
occurs with only patches 1/4 and 2/4 applied.

Testing used x86_64 with KASAN, CONFIG_NUMA=y, a two-node QEMU guest,
oops=panic panic_on_warn=1, and null_blk built as a module:
- The unpatched module crashes for all three cases above.
- With only 1/4 and 2/4 applied, the size=2^40 MiB zoned case still
  crashes.
- With the full series, writing 1 to power fails with EINVAL for all
  three cases and leaves power at 0. Correcting the value and retrying
  succeeds. Sizes of 2^43, 2^44 and 2^44 + 1 MiB and ULONG_MAX are
  rejected.
- Valid non-zoned devices were tested at 0, 1 and 2^43 - 1 MiB;
  valid zoned devices were tested at 256, 257 and 512 MiB. Tests also
  covered memory-backed read/write, zone reports and a conventional zone.
- home_node values NUMA_NO_NODE, 0 and 1 succeed. Values 2, 63, 64 and
  2147483647 are rejected on power-on.
- Each patch was build-tested with W=1 on i386 and x86_64, using GCC and
  clang 18.

Sparse NUMA node numbering and other architectures were not tested. The
reproducers are available on request.

BLK_DEV_MAX_SECTORS was added in v6.14 by commit 3d9a9e9a77c5 ("block:
limit disk max sectors to (LLONG_MAX >> 9)"), so 1/4 and 2/4 will not
apply to older stable kernels as is. There, the same limit can be
written as LLONG_MAX >> SECTOR_SHIFT.

---
Changes in v4:
- 1/4: Use SECTOR_SHIFT instead of 9 (Damien).
- 2/4, 3/4, 4/4: Add Reviewed-by from Damien. No code changes.
- Rerun the runtime tests on a kernel with the series applied.

v3: https://lore.kernel.org/linux-block/20261127125738.1654012-1-x-professor@outlook.com/

Changes in v3:
- New patch 1/4: move BLK_DEV_MAX_SECTORS to <linux/blkdev.h>.
- 2/4: Compute the size in sectors with check_mul_overflow() and compare
  it against BLK_DEV_MAX_SECTORS instead of using LLONG_MAX directly
  (Damien). This also avoids the clang
  -Wtautological-constant-out-of-range-compare warning on 32-bit that
  the kernel test robot reported:
  https://lore.kernel.org/oe-kbuild-all/20261127004636.Zw6bu9Dk-lkp@intel.com/
- 2/4: Explain in the commit message why checking only for the wrap is
  not enough.
- 3/4: Use unsigned long long instead of sector_t for the zone count
  (Damien).
- 4/4: No changes.

v2: https://lore.kernel.org/linux-block/20261126074748.1076774-1-x-professor@outlook.com/

Changes in v2:
- Add the missing Signed-off-by tags.
- State in each commit message that the bug was found by a fuzzer.
- No code changes.

v1: https://lore.kernel.org/linux-block/20261126063404.1051061-1-x-professor@outlook.com/

Yingjie Wang (4):
  block: move BLK_DEV_MAX_SECTORS to <linux/blkdev.h>
  null_blk: reject device size overflow
  null_blk: reject zone counts that overflow unsigned int
  null_blk: validate the configfs home_node attribute

 block/blk.h                    |  1 -
 drivers/block/null_blk/main.c  | 15 +++++++++++++++
 drivers/block/null_blk/zoned.c |  8 +++++++-
 include/linux/blkdev.h         |  6 ++++++
 4 files changed, 28 insertions(+), 2 deletions(-)


base-commit: 5a29cfaf51105039d156dd8a61d2783e8b653667
-- 
2.43.0


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

end of thread, other threads:[~2026-12-02  5:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 14:01 [PATCH v4 0/4] null_blk: validate configfs values before power-on Yingjie Wang
2026-12-01 14:02 ` [PATCH v4 1/4] block: move BLK_DEV_MAX_SECTORS to <linux/blkdev.h> Yingjie Wang
2026-12-02  5:51   ` Damien Le Moal
2026-12-01 14:02 ` [PATCH v4 2/4] null_blk: reject device size overflow Yingjie Wang
2026-12-01 14:02 ` [PATCH v4 3/4] null_blk: reject zone counts that overflow unsigned int Yingjie Wang
2026-12-01 14:02 ` [PATCH v4 4/4] null_blk: validate the configfs home_node attribute Yingjie Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.