Skip to content

Commit ab7dd30

Browse files
config: pass NULL when probing systemd default cgroup
ASan reported following global-buffer-overflow: READ of size 1 at 0x7f50dc6b3e9f thread T0 #0 0x... in cg_concat_path <src>/src/api.c:1769 #1 0x... in cg_build_path_locked <src>/src/api.c:1889 libcgroup#2 0x... in cg_build_path <src>/src/api.c:1910 libcgroup#3 0x.. in systemd_default_cgroup_exists <src>/src/config.c:2258 libcgroup#4 0x.. in cgroup_set_default_systemd_cgroup <src>/src/config.c:2306 libcgroup#5 0x... in main <src>/src/tools/cgdelete.c:193 libcgroup#6 0x... in __libc_start_call_main (/lib64/libc.so.6+0x2a60f) libcgroup#7 0x... in __libc_start_main_alias_2 (/lib64/libc.so.6+0x2a6bf) libcgroup#8 0x... in _start (/usr/local/bin/cgdelete+0x402384) 0x... sits one byte to the left of the empty string literal '.LC3' that systemd_default_cgroup_exists() handed to cg_build_path(). Passing an empty suffix made cg_concat_path() evaluate suf[-1] while it decided whether to append a trailing slash, triggering the ASan global-buffer-overflow. Fix by passing NULL, instead of "" (empty string) so cg_build_path() skips the suffix concatenation entirely. The resulting canonical paths are unchanged, but cgdelete (and any other caller) now runs without trampling the adjacent literal. Fixes: libcgroup#526 Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
1 parent 2c6bcc4 commit ab7dd30

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,12 +2264,12 @@ static bool systemd_default_cgroup_exists(void)
22642264
* check for empty cgroup v2, the most common usage in
22652265
* the hybrid case.
22662266
*/
2267-
if (cg_build_path("", path, NULL))
2267+
if (cg_build_path(NULL, path, NULL))
22682268
break;
22692269
case CGROUP_MODE_UNIFIED:
22702270
/* fallthrough */
22712271
case CGROUP_MODE_LEGACY:
2272-
cg_build_path("", path, "cpu");
2272+
cg_build_path(NULL, path, "cpu");
22732273
/* fallthrough */
22742274
case CGROUP_MODE_UNK:
22752275
break;

0 commit comments

Comments
 (0)