Skip to content

cgroup: fix path buffer overflows for long cgroup names - #2085

Merged
axboe merged 1 commit into
axboe:masterfrom
linuxholic:codex/cgroup-path-overflows
Apr 30, 2026
Merged

axboe merged 1 commit into
axboe:masterfrom
linuxholic:codex/cgroup-path-overflows

Conversation

@linuxholic

Copy link
Copy Markdown
Contributor

This fixes the long-path buffer overflows reported in #2084.

Problem

cgroup.c uses fixed-size buffers when constructing:

  • the cgroup root path
  • the cgroup control file path

With sufficiently long cgroup= values, these buffers can overflow and fio aborts instead of failing cleanly.

Fix

  • replace the fixed 64-byte cgroup root buffer with dynamically sized allocation
  • replace the fixed 256-byte file path buffer with dynamically sized allocation
  • preserve existing cgroup= behavior and error handling semantics

Test

Added unit tests for:

  • long cgroup root paths
  • long cgroup control file paths

Validated in an Ubuntu container:

  • without the fix, cgroup/get-root-long-path aborts with *** buffer overflow detected ***
  • with the fix, the new cgroup tests pass

@linuxholic
linuxholic force-pushed the codex/cgroup-path-overflows branch from 5988940 to 3cb2e1b Compare April 29, 2026 12:01
@axboe

axboe commented Apr 29, 2026

Copy link
Copy Markdown
Owner

Fix looks good to me, but commit message is missing a Signed-off-by line at the end.

@axboe

axboe commented Apr 29, 2026

Copy link
Copy Markdown
Owner

And a some unittest build failures you will want to address.

cgroup path construction uses fixed-size buffers in a few places.

get_cgroup_root() allocates 64 bytes and then uses sprintf() to
construct the cgroup directory path. write_int_to_file() similarly
uses a fixed 256-byte stack buffer for the target file path. Long
cgroup paths can therefore overflow these buffers and cause fio to
abort.

Replace the fixed-size buffers with dynamically sized allocation based
on the actual path length. Keep the existing cgroup semantics and let
normal filesystem errors such as ENOENT or ENAMETOOLONG flow through
the existing error handling.

Add unit tests covering long cgroup root paths and long control file
paths. Without the fix, the long-path test aborts with a buffer
overflow. With the fix, both new tests pass.

Closes axboe#2084

Signed-off-by: yangpeng <yangpengxdu@gmail.com>
@linuxholic
linuxholic force-pushed the codex/cgroup-path-overflows branch from 3cb2e1b to 6292179 Compare April 30, 2026 02:34
@linuxholic

Copy link
Copy Markdown
Contributor Author

I force-pushed an update.

  • added the Signed-off-by line
  • fixed the unittest build failures caused by discarded const qualifiers in the new cgroup tests

I also revalidated the Linux build and the unit tests in an Ubuntu container.

@axboe
axboe merged commit 72156dc into axboe:master Apr 30, 2026
17 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.

2 participants

⌂ 换网址