Blame SOURCES/CVE-2021-4154.patch

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