Skip to content

btrfs: fix integer overflow in bd_btrfs_create_volume argument counter - #1218

Merged
vojtechtrefny merged 1 commit into
storaged-project:masterfrom
kwenqi:master-fix-btrfs-bug
Oct 23, 2026
Merged

vojtechtrefny merged 1 commit into
storaged-project:masterfrom
kwenqi:master-fix-btrfs-bug

Conversation

@kwenqi

@kwenqi kwenqi commented Oct 23, 2026 •

Copy link
Copy Markdown

bd_btrfs_create_volume() used guint8 for both num_args and next_arg when constructing the mkfs.btrfs argv array. When the number of input devices combined with optional parameters (label, data_level, md_level) exceeded 255, the 8-bit counter wrapped around to a much smaller value, causing g_new0() to allocate a buffer far too small for the actual number of arguments. The subsequent argv population then wrote past the allocated boundary, corrupting heap metadata and potentially leading to arbitrary code execution.

Fix it by widening num_args and next_arg from guint8 to guint, which provides a 32-bit range sufficient for any realistic argument count.

Summary by CodeRabbit

  • Maintenance
    • Updated internal handling for Btrfs volume creation. The way volumes are created and the behavior of the related command remain unchanged; no user-facing changes are expected.

bd_btrfs_create_volume() used guint8 for both num_args and next_arg
when constructing the mkfs.btrfs argv array. When the number of input
devices combined with optional parameters (label, data_level, md_level)
exceeded 255, the 8-bit counter wrapped around to a much smaller value,
causing g_new0() to allocate a buffer far too small for the actual
number of arguments. The subsequent argv population then wrote past the
allocated boundary, corrupting heap metadata and potentially leading to
arbitrary code execution.

Fix it by widening num_args and next_arg from guint8 to guint, which
provides a 32-bit range sufficient for any realistic argument count.

Signed-off-by: Kou Wenqi <kouwenqi@kylinos.cn>
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 035a8ae and 106cd7c.

📒 Files selected for processing: 1
  • src/plugins/btrfs.c

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

📝 Walkthrough

bd_btrfs_create_volume now uses guint for its local argument count and index. Argument construction and command execution are unchanged.

Changes: Btrfs volume arguments

Layer / File(s) Summary
Widen local argument types
src/plugins/btrfs.c
The argument count and index change from guint8 to guint. Argument construction and command execution remain unchanged.

Priority: ➖ Normal

Estimated code review effort: 1 (Trivial) | ~3 minutes

Merge Risk: ⚪ Minimal · up to 106cd

The reported argument-count failure above 255 is addressed, with no actionable merge-blocking risk remaining.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the btrfs fix and the function involved, bd_btrfs_create_volume. The PR changes the argument counter and index from guint8 to guint, which prevents wrap-around when devices and options…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the btrfs fix and the function involved, bd_btrfs_create_volume. The PR changes the argument counter and index from guint8 to guint, which prevents wrap-around when devices and options exceed 255. The title calls this an integer overflow in the argument counter. The changeset matches this description. The title does not mention the 255 limit or the buffer under-allocation, but it covers the main change.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@tbzatek tbzatek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable, thanks.

@vojtechtrefny

Copy link
Copy Markdown
Member

Jenkins, ok to test.

@vojtechtrefny
vojtechtrefny merged commit 6cef17e into storaged-project:master Oct 23, 2026
39 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants