Skip to content

Commit 3b04627

Browse files
Christian Braunertorvalds
authored andcommitted
cgroup: verify that source is a string
The following sequence can be used to trigger a UAF: int fscontext_fd = fsopen("cgroup"); int fd_null = open("/dev/null, O_RDONLY); int fsconfig(fscontext_fd, FSCONFIG_SET_FD, "source", fd_null); close_range(3, ~0U, 0); The cgroup v1 specific fs parser expects a string for the "source" parameter. However, it is perfectly legitimate to e.g. specify a file descriptor for the "source" parameter. The fs parser doesn't know what a filesystem allows there. So it's a bug to assume that "source" is always of type fs_value_is_string when it can reasonably also be fs_value_is_file. This assumption in the cgroup code causes a UAF because struct fs_parameter uses a union for the actual value. Access to that union is guarded by the param->type member. Since the cgroup paramter parser didn't check param->type but unconditionally moved param->string into fc->source a close on the fscontext_fd would trigger a UAF during put_fs_context() which frees fc->source thereby freeing the file stashed in param->file causing a UAF during a close of the fd_null. Fix this by verifying that param->type is actually a string and report an error if not. In follow up patches I'll add a new generic helper that can be used here and by other filesystems instead of this error-prone copy-pasta fix. But fixing it in here first makes backporting a it to stable a lot easier. Fixes: 8d2451f ("cgroup1: switch to option-by-option parsing") Reported-by: [email protected] Cc: Christoph Hellwig <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: <[email protected]> Cc: syzkaller-bugs <[email protected]> Signed-off-by: Christian Brauner <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 40226a3 commit 3b04627

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
@@ -912,6 +912,8 @@ int cgroup1_parse_param(struct fs_context *fc, struct fs_parameter *param)
912912
opt = fs_parse(fc, cgroup1_fs_parameters, param, &result);
913913
if (opt == -ENOPARAM) {
914914
if (strcmp(param->key, "source") == 0) {
915+
if (param->type != fs_value_is_string)
916+
return invalf(fc, "Non-string source");
915917
if (fc->source)
916918
return invalf(fc, "Multiple sources not supported");
917919
fc->source = param->string;

0 commit comments

Comments
 (0)