Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3523916rwb; Sun, 9 Oct 2022 06:37:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM69pP7fMtda71OB26kkUPqcXau52XmbjCsyXLRcw+xzkinpbt85+IQTTRg8D8pClkITEjrU X-Received: by 2002:a17:903:1105:b0:178:ae31:aad with SMTP id n5-20020a170903110500b00178ae310aadmr14246466plh.3.1665322636781; Sun, 09 Oct 2022 06:37:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665322636; cv=none; d=google.com; s=arc-20160816; b=lFAbiNu5obCY76NohBpZSUsK6UGTckQYeAlVU6zi5VsTYrrPI1IMXk6OGQSsjNQe9u Ds0tlShDLwzMvATxsW9GlrQ3b1wK6iRv2T6Cta/AnHfaNKdHs7G6Pb3cF0bgQKzBKa9G XLFgH5bUjx6jaR/KRTvOtwHJu6i6Lu3YP1GLuwAJyaNdMw5eOj1EDAoyApdWbRLEQCco nhs3dZxgo+HAj172ipXIBivpyBb9F5zrz0Eu9PiAQlbmWGMguYmQcK5g2/Xv2N0kp55l RIeBDn9p49seh4TetOD8oOhPVHF/uwQBoajO8sIC55aB5S2UmUNewkxIoIKiWQnEXgRu hpkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=f+FQCiT/iR7Nz0lv9+R0ZXCG7IkvP8TO0v3crB7qFfs=; b=FKiDF7OKGwerPqfGcFxRT/JdQm0fNIqtxszinlQavOM8VGBoBFiI8O4g0YR1FFjb5H +jlIC2M3XBsU1y6jMdxAaxJdRRbP3FuaNH4nXxf0ZUW+sJK4tj7pCqaZc6wSs93ARVLK IuIIkCUEvXZjr51wWC909gkMi7NZtQRNWnMvmENB/5WeXGxp6AMiXYrasFarzE9eWCZ3 +zYvr7uFaDyXJ6Pr9HD0MCqFzhcLXwFDgbclGQ/nq2VQZGKL9yGuZRGVftpgReuIvEOe +FBJ0ERUJo8dgrUjHGBZhEX5iWRgzFDPkNRySbGHxFhhn5rfqgHY85AxG7s14wiTcl9R Y21w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f11-20020a65400b000000b0043891d59cb7si9391514pgp.833.2022.10.09.06.37.03; Sun, 09 Oct 2022 06:37:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229657AbiJINKl (ORCPT + 99 others); Sun, 9 Oct 2022 09:10:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229886AbiJINKj (ORCPT ); Sun, 9 Oct 2022 09:10:39 -0400 Received: from cae.in-ulm.de (cae.in-ulm.de [217.10.14.231]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E9B1B19024 for ; Sun, 9 Oct 2022 06:10:37 -0700 (PDT) Received: by cae.in-ulm.de (Postfix, from userid 1000) id A7DCE14026A; Sun, 9 Oct 2022 15:10:36 +0200 (CEST) Date: Sun, 9 Oct 2022 15:10:36 +0200 From: "Christian A. Ehrhardt" To: Christian Brauner Cc: Tejun Heo , syzbot , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, Yosry Ahmed Subject: [PATCH] cgroup: Fix crash with CLONE_INTO_CGROUP and v1 cgroups Message-ID: References: <000000000000385cbf05ea3f1862@google.com> <00000000000028a44005ea40352b@google.com> <20221009084039.cw6meqbvy4362lsa@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221009084039.cw6meqbvy4362lsa@wittgenstein> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since commit f3a2aebdd6, Version 1 cgroups no longer cause an error when used with CLONE_INTO_CGROUP. However, the permission checks performed during clone assume a Version 2 cgroup. Restore the error check for V1 cgroups in the clone() path. Reported-by: syzbot+534ee3d24c37c411f37f@syzkaller.appspotmail.com Link: https://lore.kernel.org/lkml/000000000000385cbf05ea3f1862@google.com/ Fixes: f3a2aebdd6 ("cgroup: enable cgroup_get_from_file() on cgroup1") Signed-off-by: Christian A. Ehrhardt --- kernel/cgroup/cgroup.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index b6e3110b3ea7..f7fc3afa88c1 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -6244,6 +6244,11 @@ static int cgroup_css_set_fork(struct kernel_clone_args *kargs) goto err; } + if (!cgroup_on_dfl(dst_cgrp)) { + ret = -EBADF; + goto err; + } + if (cgroup_is_dead(dst_cgrp)) { ret = -ENODEV; goto err; -- 2.34.1