Blame SOURCES/CVE-2021-4154.patch

df284a
From 7d389a33490309d15530e3372c3045110b3031ab Mon Sep 17 00:00:00 2001
df284a
From: Artem Savkov <asavkov@redhat.com>
df284a
Date: Tue, 4 Jan 2022 10:40:56 +0100
df284a
Subject: [KPATCH CVE-2021-4154] cgroup: verify that source is a string
df284a
df284a
Kernels:
df284a
4.18.0-348.el8
df284a
4.18.0-348.2.1.el8_5
df284a
4.18.0-348.7.1.el8_5
df284a
df284a
Changes since last build:
df284a
arches: x86_64 ppc64le
df284a
cgroup-v1.o: changed function: cgroup1_parse_param
df284a
---------------------------
df284a
df284a
Kpatch-MR: https://gitlab.com/redhat/prdsc/rhel/src/kpatch/rhel-8/-/merge_requests/9
df284a
Approved-by: Yannick Cote (@ycote1)
df284a
Approved-by: Joe Lawrence (@joe.lawrence)
df284a
Kernels:
df284a
4.18.0-348.el8
df284a
4.18.0-348.2.1.el8_5
df284a
4.18.0-348.7.1.el8_5
df284a
4.18.0-348.12.2.el8_5
df284a
df284a
Modifications: none
df284a
Z-MR: https://gitlab.com/redhat/rhel/src/kernel/rhel-8/-/merge_requests/1865
df284a
CVE: CVE-2021-4154
df284a
df284a
commit e1ee4bc6e6d8fd36b493fca941b7d5b6e987ae3c
df284a
Author: Waiman Long <longman@redhat.com>
df284a
Date:   Tue Dec 21 09:47:25 2021 -0500
df284a
df284a
    cgroup: verify that source is a string
df284a
df284a
    Bugzilla: https://bugzilla.redhat.com/2034608
df284a
    Y-Commit: b6d2fff23b0eee0e82d128f23c4ebd99a30299c3
df284a
df284a
    O-Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2034609
df284a
df284a
    commit 3b0462726e7ef281c35a7a4ae33e93ee2bc9975b
df284a
    Author: Christian Brauner <christian.brauner@ubuntu.com>
df284a
    Date:   Wed, 14 Jul 2021 15:47:49 +0200
df284a
df284a
        cgroup: verify that source is a string
df284a
df284a
        The following sequence can be used to trigger a UAF:
df284a
df284a
            int fscontext_fd = fsopen("cgroup");
df284a
            int fd_null = open("/dev/null, O_RDONLY);
df284a
            int fsconfig(fscontext_fd, FSCONFIG_SET_FD, "source", fd_null);
df284a
            close_range(3, ~0U, 0);
df284a
df284a
        The cgroup v1 specific fs parser expects a string for the "source"
df284a
        parameter.  However, it is perfectly legitimate to e.g.  specify a file
df284a
        descriptor for the "source" parameter.  The fs parser doesn't know what
df284a
        a filesystem allows there.  So it's a bug to assume that "source" is
df284a
        always of type fs_value_is_string when it can reasonably also be
df284a
        fs_value_is_file.
df284a
df284a
        This assumption in the cgroup code causes a UAF because struct
df284a
        fs_parameter uses a union for the actual value.  Access to that union is
df284a
        guarded by the param->type member.  Since the cgroup paramter parser
df284a
        didn't check param->type but unconditionally moved param->string into
df284a
        fc->source a close on the fscontext_fd would trigger a UAF during
df284a
        put_fs_context() which frees fc->source thereby freeing the file stashed
df284a
        in param->file causing a UAF during a close of the fd_null.
df284a
df284a
        Fix this by verifying that param->type is actually a string and report
df284a
        an error if not.
df284a
df284a
        In follow up patches I'll add a new generic helper that can be used here
df284a
        and by other filesystems instead of this error-prone copy-pasta fix.
df284a
        But fixing it in here first makes backporting a it to stable a lot
df284a
        easier.
df284a
df284a
        Fixes: 8d2451f4994f ("cgroup1: switch to option-by-option parsing")
df284a
        Reported-by: syzbot+283ce5a46486d6acdbaf@syzkaller.appspotmail.com
df284a
        Cc: Christoph Hellwig <hch@lst.de>
df284a
        Cc: Alexander Viro <viro@zeniv.linux.org.uk>
df284a
        Cc: Dmitry Vyukov <dvyukov@google.com>
df284a
        Cc: <stable@kernel.org>
df284a
        Cc: syzkaller-bugs <syzkaller-bugs@googlegroups.com>
df284a
        Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
df284a
        Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
df284a
df284a
    Signed-off-by: Waiman Long <longman@redhat.com>
df284a
    Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
df284a
df284a
Signed-off-by: Artem Savkov <asavkov@redhat.com>
df284a
---
df284a
 kernel/cgroup/cgroup-v1.c | 2 ++
df284a
 1 file changed, 2 insertions(+)
df284a
df284a
diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c
df284a
index 852f1349f9d9..291754068ec6 100644
df284a
--- a/kernel/cgroup/cgroup-v1.c
df284a
+++ b/kernel/cgroup/cgroup-v1.c
df284a
@@ -907,6 +907,8 @@ int cgroup1_parse_param(struct fs_context *fc, struct fs_parameter *param)
df284a
 	opt = fs_parse(fc, cgroup1_fs_parameters, param, &result);
df284a
 	if (opt == -ENOPARAM) {
df284a
 		if (strcmp(param->key, "source") == 0) {
df284a
+			if (param->type != fs_value_is_string)
df284a
+				return invalf(fc, "Non-string source");
df284a
 			if (fc->source)
df284a
 				return invalf(fc, "Multiple sources not supported");
df284a
 			fc->source = param->string;
df284a
-- 
df284a
2.34.1
df284a
df284a