Skip to content

Commit 2d18e54

Browse files
Qinglang Miaohtejun
authored andcommitted
cgroup: Fix memory leak when parsing multiple source parameters
A memory leak is found in cgroup1_parse_param() when multiple source parameters overwrite fc->source in the fs_context struct without free. unreferenced object 0xffff888100d930e0 (size 16): comm "mount", pid 520, jiffies 4303326831 (age 152.783s) hex dump (first 16 bytes): 74 65 73 74 6c 65 61 6b 00 00 00 00 00 00 00 00 testleak........ backtrace: [<000000003e5023ec>] kmemdup_nul+0x2d/0xa0 [<00000000377dbdaa>] vfs_parse_fs_string+0xc0/0x150 [<00000000cb2b4882>] generic_parse_monolithic+0x15a/0x1d0 [<000000000f750198>] path_mount+0xee1/0x1820 [<0000000004756de2>] do_mount+0xea/0x100 [<0000000094cafb0a>] __x64_sys_mount+0x14b/0x1f0 Fix this bug by permitting a single source parameter and rejecting with an error all subsequent ones. Fixes: 8d2451f ("cgroup1: switch to option-by-option parsing") Reported-by: Hulk Robot <[email protected]> Signed-off-by: Qinglang Miao <[email protected]> Reviewed-by: Zefan Li <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 5a7b5f3 commit 2d18e54

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

kernel/cgroup/cgroup-v1.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,8 @@ int cgroup1_parse_param(struct fs_context *fc, struct fs_parameter *param)
908908
opt = fs_parse(fc, cgroup1_fs_parameters, param, &result);
909909
if (opt == -ENOPARAM) {
910910
if (strcmp(param->key, "source") == 0) {
911+
if (fc->source)
912+
return invalf(fc, "Multiple sources not supported");
911913
fc->source = param->string;
912914
param->string = NULL;
913915
return 0;

0 commit comments

Comments
 (0)