Skip to content

bitmap: fix three parsing bugs in bitmap_parse() and bitmap_parselist()

Shashank Mohan Jain lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest6 patches 1 replyIn review
  2. v16 patches 5 repliesSuperseded

Changes in v2 from the cover letter

- Resent with my full name, as asked by Yury.
- Stated the tool and model used above.
- No code changes.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6bitmap: bitmap_parse(): reject non-hex character before 8 digitslib/bitmap-str.c+6 -20 replies
2/6bitmap: test bitmap_parse() with an illegal character before 8 hex digitslib/test_bitmap.c+4 -00 replies
3/6bitmap: bitmap_parselist(): reject trailing characters after group sizelib/bitmap-str.c+8 -10 replies
4/6bitmap: test bitmap_parselist() with text after the group sizelib/test_bitmap.c+3 -00 replies
5/6bitmap: bitmap_parselist(): don't wrap around on a huge group sizelib/bitmap-str.c+5 -20 replies
6/6bitmap: test bitmap_parselist() with a group size close to UINT_MAXlib/test_bitmap.c+2 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/6] bitmap: fix three parsing bugs in bitmap_parse() and bitmap_parselist()

This series fixes three cases where the bitmap string parsers accept input they are documented to reject, or produce a different mask than the one requested. Each fix is followed by a patch adding the failing cases to lib/test_bitmap.c.

1-2: bitmap_parse() treats a non-hex character directly before a chunk
of exactly eight hex digits as a separator, so "x12345678" and "0x0000000f" are accepted while "0xf" is rejected. This is a regression from the bitmap_parse() rework; the old __bitmap_parse() rejected all of them.

3-4: bitmap_parselist() does not check for the end of the region after
the group size of a "range:used/group" region, so since N and all became valid region starts, "0-7:1/2N" or "0-7:1/2all" are silently parsed as two regions.

5-6: bitmap_parselist() walks a "range:used/group" region with an
unsigned int that wraps around when the group size is close to UINT_MAX, setting bits below the requested range. This needs an absurd group size and never writes out of bounds.

With the series applied, test_bitmap reports "all 391544 tests passed" (UML, x86_64). The three fixes are independent and can be applied in any order.

These patches were prepared with Claude Code (Anthropic), model Claude Opus 5.5 (claude-opus-5-5): the analysis, the Lean models used to find and check the bugs, the fixes and the tests. I reviewed them and take responsibility for them. The trailer only says "Assisted-by: LLM", as Documentation/process/coding-assistants.rst requires since commit 816d9992d9ed ("coding-assistants: simplify attribution").

Changes in v2:
- Resent with my full name, as asked by Yury.
- Stated the tool and model used above.
- No code changes.

v1: https://lore.kernel.org/r/[email protected]

smjain (6):
bitmap: bitmap_parse(): reject non-hex character before 8 digits
bitmap: test bitmap_parse() with an illegal character before 8 hex
digits
bitmap: bitmap_parselist(): reject trailing characters after group
size
bitmap: test bitmap_parselist() with text after the group size
bitmap: bitmap_parselist(): don't wrap around on a huge group size
bitmap: test bitmap_parselist() with a group size close to UINT_MAX

 lib/bitmap-str.c  | 24 +++++++++++++++++++-----
 lib/test_bitmap.c |  9 +++++++++
 2 files changed, 28 insertions(+), 5 deletions(-)
Signature · 1 line
2.43.0