Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp684370pxb; Thu, 17 Feb 2022 12:22:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJypVpf39BVUYbFVOkW7uJ5b6iPC9ecivrHz4b01SsCCcDkpucDyEEIZmpcoLNPV5WGW8SPH X-Received: by 2002:a17:902:864b:b0:14c:d45e:a77b with SMTP id y11-20020a170902864b00b0014cd45ea77bmr4329326plt.143.1645129357671; Thu, 17 Feb 2022 12:22:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645129357; cv=none; d=google.com; s=arc-20160816; b=sC/hWYpmo48beZe57tXOqKpTupfUTZeck7yF7Wh4abngRFNFBwcziMaHL8mymREYka L8vUfUTsR1egcOSEbF6AEHHL2Uy670vmBgtpSqEKAiOsMPFfnPaiE3iCHRygHxSWOaRC 1WfNByOBY2mdC+LNv4kznSDzCLDnWSd0neRItfbgXNsofYzzaFP4Mrul/0NFyBHa9pSN GKVo3qhTc3SwrrpxxVUB7/QacIUuioVBBOjQZtJOxmdkUfK9hiFejMYqzRGmyWB2WrQG ilz86qyXgQptpLsKlaY3GAtnUdOq4UaDurh/pCEpBj+bpsMlCxhLrgVbBPfuhscYuKHF exIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=trkaAj42Qk58nzvh5xCn9D72uPJ0Goap4j9Xg6GQj54=; b=nY41bYq9e3D0qliMDoIFCacS4JnFHji+rF6rDldIrK2d7Fts9f2yCTAvkA2jBMvhIw f4YJHeEqZWsLNXiSgFC3zFV3NZAMQ51yded0e0qdoO2z30l0eCcVg58uctg3cGQ4Si+n hIK6GjC3XjGtcrMee4zxpjmO/poi82I6pd2D+2Le6VpI7jesH9BplM0iqJv041xIQ9B5 zkaxfaEyph5hBft2jOC/PY7JHSIqawipbCYdmKFMkMLV0DLP1ddVL0rhI2uTi2ZNUP2O L/+QZFhTC2VLNzYwPrsIkB5ew8kFI4ECZ7VUrQG2rV5414WGslvdfgQelzNb7g15Gfwc 5+yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=dIt60ilv; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j24si8988101pgg.128.2022.02.17.12.22.19; Thu, 17 Feb 2022 12:22:37 -0800 (PST) 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; dkim=pass header.i=@suse.com header.s=susede1 header.b=dIt60ilv; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242696AbiBQQL7 (ORCPT + 99 others); Thu, 17 Feb 2022 11:11:59 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:58812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233970AbiBQQL6 (ORCPT ); Thu, 17 Feb 2022 11:11:58 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2CC1BF48; Thu, 17 Feb 2022 08:11:40 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6334F219A2; Thu, 17 Feb 2022 16:11:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1645114299; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=trkaAj42Qk58nzvh5xCn9D72uPJ0Goap4j9Xg6GQj54=; b=dIt60ilvthbCzGmprCu9i0vdIACxkq2NIlLVQSHwrsUEUHqFlF7hbQprfIAEY7l2wMM/3W PYS5RX+QIa3rGOFDU3MRy5wmcKBI6jB3NUXLFjp4KQRY9AwhYyciJ+tW0WGDSaausdAEir hzOr+3+QNiRqmnreY2jgWr6606D4ZQs= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4360813C18; Thu, 17 Feb 2022 16:11:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qnfcD7tzDmJ7cwAAMHmgww (envelope-from ); Thu, 17 Feb 2022 16:11:39 +0000 From: =?UTF-8?q?Michal=20Koutn=C3=BD?= To: "Eric W. Biederman" Cc: Masami Ichikawa , Tabitha Sable , Tejun Heo , Zefan Li , Johannes Weiner , stable@vger.kernel.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] cgroup-v1: Correct privileges check in release_agent writes Date: Thu, 17 Feb 2022 17:11:28 +0100 Message-Id: <20220217161128.20291-1-mkoutny@suse.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 The idea is to check: a) the owning user_ns of cgroup_ns, b) capabilities in init_user_ns. The commit 24f600856418 ("cgroup-v1: Require capabilities to set release_agent") got this wrong in the write handler of release_agent since it checked user_ns of the opener (may be different from the owning user_ns of cgroup_ns). Secondly, to avoid possibly confused deputy, the capability of the opener must be checked. Fixes: 24f600856418 ("cgroup-v1: Require capabilities to set release_agent") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/stable/20220216121142.GB30035@blackbody.suse.cz/ Signed-off-by: Michal Koutný --- kernel/cgroup/cgroup-v1.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c index 0e877dbcfeea..afc6c0e9c966 100644 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c @@ -546,6 +546,7 @@ static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { struct cgroup *cgrp; + struct cgroup_file_ctx *ctx; BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX); @@ -553,8 +554,9 @@ static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of, * Release agent gets called with all capabilities, * require capabilities to set release agent. */ - if ((of->file->f_cred->user_ns != &init_user_ns) || - !capable(CAP_SYS_ADMIN)) + ctx = of->priv; + if ((ctx->ns->user_ns != &init_user_ns) || + !file_ns_capable(of->file, &init_user_ns, CAP_SYS_ADMIN)) return -EPERM; cgrp = cgroup_kn_lock_live(of->kn, false); -- 2.34.1