Skip to content

badblocks: fix rounding bug and validate input range

Ramesh Adhikari linux-block stable 3 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest posting 2/22 patches 0 repliesNew
  2. v7 posting 1/22 patches 4 repliesSuperseded
  3. v62 patches 2 repliesSuperseded

Patches in v7 posting 2/2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2badblocks: fix in-place round_up/round_down usage bugblock/badblocks.c+6 -60 replies
2/2badblocks: validate sector range and shift before roundingblock/badblocks.c include/linux/badblocks.h+38 -80 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchColy Li
1/2R-b
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v7 thread

Cover letter [PATCH v7 0/2] badblocks: fix rounding bug and validate input range

Two related fixes to block/badblocks.c:

Patch 1/2 fixes the actual reported bug: round_up()/round_down() don't modify their argument in place, they return the rounded value, and the callers in _badblocks_set()/_badblocks_clear()/badblocks_check() were discarding that return value. Depending on caller alignment this could leave sectors unrounded or, in the reported case, stall the CPU with a non-advancing cursor when reached via the nvdimm ioctl path. It also fixes a 32-bit build breakage reported by kernel test robot, since the old rounddown()/roundup() macros pull in 64-bit division helpers not linked on 32-bit builds. Unchanged since v6.

Patch 2/2 hardens the same three functions against the input-range and shift edge cases the round_up/round_down fix exposed: s + sectors overflow, and rounding itself wrapping past ULLONG_MAX. Revised in v7 per Coly's review of v6 -- see the changelog in that patch for details. The remaining open item, bounding bb->shift where it's populated from the on-disk MD superblock in drivers/md/md.c, is being sent separately since it's a different file and a different root cause (missing input validation, not a rounding bug).

Both patches carry Coly Li's Reviewed-by.

Ramesh Adhikari (2):
badblocks: fix in-place round_up/round_down usage bug
badblocks: validate sector range and shift before rounding

 block/badblocks.c         | 52 ++++++++++++++++++++++++++++++++++++++++-------
 include/linux/badblocks.h |  6 +++++-
 2 files changed, 44 insertions(+), 14 deletions(-)

--
2.43.0