Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3833060ybl; Tue, 21 Jan 2020 07:52:58 -0800 (PST) X-Google-Smtp-Source: APXvYqzgeLKi+8HrZ30Qk6ZKdtX23xdMEoiodF2I76spnEcr3c9N0TE0/w5LobAzZv2xbcccGGx6 X-Received: by 2002:aca:49d5:: with SMTP id w204mr3510826oia.40.1579621977970; Tue, 21 Jan 2020 07:52:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579621977; cv=none; d=google.com; s=arc-20160816; b=xdSGvwVb7dYAhiyu4fXSFH/SwoiSw0jFNjLKOtegQc/8qcpQulzX3HOJ9gP9ibSs+h nHMi6MEZzD9BiTgimJrjJQXdXFZtGfDoRgj+j0lMmP/Bt3mvqvnPy7RsAJ3bpAbFZJRm PouwmLncee+3NAVkAdAkY4Z7viY5VhPt2wG7ibyJo+uAPjBUEFKO+ipE8Ebl/CLzRoXT M5YqO10+a7FzXAtn6c35xPggytw1fJF8Z7C8jJLmgnhFXdMOzYZ2tNV2fp6iojt6uFlQ RYpQNq2g4q3xV3nNfaYr3vs+r4S2vPet4ZB3yr1V9xAxvd9ja/ZD8UJMBpubUWpNaleU yLNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=uGlJvGX1437VJnx15oNQPVpmaIJTVKqBKKvssDwbXZQ=; b=JieJPO6guBQGTfw5lYgbr+jL2pOjVxnWias0iMsyf+qNw4cQioiRfcGLhCrv1YXDxR sjRKT0sBK2VowWr/ifvesThpfU2AWXW8mGGxE+ZN/cM0jdUgDlD5lUftSplekRxCgn4b JWXkceowxH7h/LjMXmUuPSKoXQ93mhwylUVxTRy0mPRWVcxYFliomER8XP33NiGx8rHg kluDq9Gle4GqRdSj/fm31npBF4qQAZDOy1xKOLxi/2IIp7VX1c42bkJYeXVjSNx33pu4 4pSc5BGArEECz7ohN7nCsOeLRrrZ8W/9speZcSSifxRI+FWK7sFSG4g1dPgswETJ7m6O OveA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v76si19603925oif.207.2020.01.21.07.52.45; Tue, 21 Jan 2020 07:52:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729399AbgAUPuk (ORCPT + 99 others); Tue, 21 Jan 2020 10:50:40 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:39912 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729345AbgAUPuj (ORCPT ); Tue, 21 Jan 2020 10:50:39 -0500 Received: from [154.119.55.246] (helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1itvnY-0004D0-LU; Tue, 21 Jan 2020 15:50:37 +0000 From: Christian Brauner To: linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Tejun Heo Cc: Oleg Nesterov , Christian Brauner , Johannes Weiner , Li Zefan , cgroups@vger.kernel.org Subject: [PATCH v5 4/6] cgroup: add cgroup_may_write() helper Date: Tue, 21 Jan 2020 16:48:42 +0100 Message-Id: <20200121154844.411-5-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200121154844.411-1-christian.brauner@ubuntu.com> References: <20200121154844.411-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a cgroup_may_write() helper which we can use in the CLONE_INTO_CGROUP patch series to verify that we can write to the destination cgroup. Cc: Tejun Heo Cc: Johannes Weiner Cc: Li Zefan Cc: cgroups@vger.kernel.org Signed-off-by: Christian Brauner --- /* v1 */ patch not present /* v2 */ patch not present /* v3 */ patch not present /* v4 */ Link: https://lore.kernel.org/r/20200117181219.14542-5-christian.brauner@ubuntu.com patch introduced /* v5 */ unchanged --- kernel/cgroup/cgroup.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index ce2d5b8aa19f..636fe3d46d2d 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -4649,13 +4649,28 @@ static int cgroup_procs_show(struct seq_file *s, void *v) return 0; } +static int cgroup_may_write(const struct cgroup *cgrp, struct super_block *sb) +{ + int ret; + struct inode *inode; + + lockdep_assert_held(&cgroup_mutex); + + inode = kernfs_get_inode(sb, cgrp->procs_file.kn); + if (!inode) + return -ENOMEM; + + ret = inode_permission(inode, MAY_WRITE); + iput(inode); + return ret; +} + static int cgroup_procs_write_permission(struct cgroup *src_cgrp, struct cgroup *dst_cgrp, struct super_block *sb) { struct cgroup_namespace *ns = current->nsproxy->cgroup_ns; struct cgroup *com_cgrp = src_cgrp; - struct inode *inode; int ret; lockdep_assert_held(&cgroup_mutex); @@ -4665,12 +4680,7 @@ static int cgroup_procs_write_permission(struct cgroup *src_cgrp, com_cgrp = cgroup_parent(com_cgrp); /* %current should be authorized to migrate to the common ancestor */ - inode = kernfs_get_inode(sb, com_cgrp->procs_file.kn); - if (!inode) - return -ENOMEM; - - ret = inode_permission(inode, MAY_WRITE); - iput(inode); + ret = cgroup_may_write(com_cgrp, sb); if (ret) return ret; -- 2.25.0