Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp369795lqs; Tue, 5 Mar 2024 04:49:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWZ3UKMokDLTSLo67eN4OhWhUx4CU7Q8RiOtE6uIG9ZMVICEhu6mX7R5CiKhg0J/fBD2kJh606Z0hN7aSLe8znOnYwdx1AgabsOLZjnyw== X-Google-Smtp-Source: AGHT+IFasPaNKBFDn2CNIG87pR1z3NWtOOYFUydThPT/w9kFXvZwbkeqPVJ7vIK9bdUqkcL/pLJU X-Received: by 2002:a17:90b:68c:b0:29a:ce2b:7611 with SMTP id m12-20020a17090b068c00b0029ace2b7611mr9164755pjz.28.1709642947499; Tue, 05 Mar 2024 04:49:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709642947; cv=pass; d=google.com; s=arc-20160816; b=ULjLmP+sGnXkpg5E/1dlj3ibEkc/Y6pPnIA50wh3lGKP9BjdX1de3G+796jOjXwoqZ iidICn4I0Nk2UrAMzc8rkjCDO8H8wurGg6qKRKJn6fJXUtFm9W63/NGXwLYfncqpJvoF XX5wuRxnrH17lPJfzqewsCCUfXt0XHwKMlhrN33kW7Ar3Jve9fPsZP9GZgkbLge8/7+0 5wwFxASdxBL/fPes+st+3MC1YNAw40BCEZcezW+pFcVa0iL9nuJJ8+LoTn5LM3qirObW jbtqyZNgYeXWenUu8hdFL7VTSZ6L5oALfsbVHCSMxE0fKeg6BbexP73guStPCku2Ox4a Lr5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id; bh=RimTvGwYwrXC3fztgS66gOL5NfxbTD0Zig3ipd5iuCs=; fh=PzNEvLUCAwbSMzRoMMzLLpCchcODptkR4j0roQoSofw=; b=aKgCjs83EOQn9Wg//Oph23WWG8Au+q3l1n7cHxMGotMnZfpOEXlmTJtsYpQGWUMAby 4w46Mf9OJ0OSiT1Qp3jq/zR5BIjl7QJz74hz+pQ47QdFKONBA0D7yD74nVwBd7fJtw5B 1CYcYFF3xwCONfckx6zMUJtu6byoIqNq+BSTa8WEYUY99DH892Q6tCGG3ZWKK8rYx9jy +TVTExmzEs9PQUeGlQsF3mpXjYehUyroWxadJH7ymCMdsk/xRBqxQ+gsrvGPkFCYa1RL hhhZmodVdcwewckfwvCdznlrR/IkkeYfHlBGPANEznSj2gsJgMdoeVioAwkA/yOP/+YP G0Pw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-92391-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92391-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id fs24-20020a17090af29800b002997a9e041esi12059696pjb.184.2024.03.05.04.49.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 04:49:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-92391-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-92391-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92391-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E1D99284D08 for ; Tue, 5 Mar 2024 12:47:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 858085A4DC; Tue, 5 Mar 2024 12:47:37 +0000 (UTC) Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E84385645; Tue, 5 Mar 2024 12:47:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=14.137.139.23 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709642856; cv=none; b=bzf8OapVC3z2cyY7VAuywh8t6N9y/XrLydBiWrmS2+e1QPpYGJy5Dbq/SlOVSPkrqMGcDe6q+ZfnR14LULsihepn8kz+uwX6Md2tdkJonHgyspu1v/wQDxZzzC+dIb57VgIaQ1Vx+hq8zeav4Cq50u7ef8vwdbZtCdninYv3TxU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709642856; c=relaxed/simple; bh=6hryqrJ72wzfly2rJ+FzgO0eAdOTeU5s0vIFIR7Onrc=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=TeIFCmUhOf92cHAkNRuyGsLMkB2LracKqlhPSkjNVd9OxfVcvAmMEOLzQAmPulVpXVndZ5AV/9zYHQVYuDZzSpxyIQSgZa5k6mCltrlPNQUpy+dfLufYMKdI4pe3DQTJ8wjMxTl8RvqsY7gZ8x/I5aC0RMYMOkcifA3u/fZE7u0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=14.137.139.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.18.186.51]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4Tpw0v3nc2z9ybvS; Tue, 5 Mar 2024 20:31:43 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.47]) by mail.maildlp.com (Postfix) with ESMTP id C0E871405A1; Tue, 5 Mar 2024 20:47:16 +0800 (CST) Received: from [127.0.0.1] (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwC3YBlEFOdlb7rCAw--.65453S2; Tue, 05 Mar 2024 13:47:16 +0100 (CET) Message-ID: <3098aef3e5f924e5717b4ba4a34817d9f22ec479.camel@huaweicloud.com> Subject: Re: [PATCH v2 24/25] commoncap: use vfs fscaps interfaces From: Roberto Sassu To: Christian Brauner , "Seth Forshee (DigitalOcean)" Cc: Serge Hallyn , Paul Moore , Eric Paris , James Morris , Alexander Viro , Jan Kara , Stephen Smalley , Ondrej Mosnacek , Casey Schaufler , Mimi Zohar , Roberto Sassu , Dmitry Kasatkin , Eric Snowberg , "Matthew Wilcox (Oracle)" , Jonathan Corbet , Miklos Szeredi , Amir Goldstein , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, audit@vger.kernel.org, selinux@vger.kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-unionfs@vger.kernel.org Date: Tue, 05 Mar 2024 13:46:56 +0100 In-Reply-To: <20240305-fachjargon-abmontieren-75b1d6c67a83@brauner> References: <20240221-idmap-fscap-refactor-v2-0-3039364623bd@kernel.org> <20240221-idmap-fscap-refactor-v2-24-3039364623bd@kernel.org> <20240305-fachjargon-abmontieren-75b1d6c67a83@brauner> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: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daVFxhVjvjDU0xZFpf9x07UAkuxUUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgANBF1jj5b+nwAAsN On Tue, 2024-03-05 at 10:12 +0100, Christian Brauner wrote: > On Mon, Mar 04, 2024 at 10:56:17AM -0600, Seth Forshee (DigitalOcean) wro= te: > > On Mon, Mar 04, 2024 at 05:17:57PM +0100, Roberto Sassu wrote: > > > On Mon, 2024-03-04 at 09:31 -0600, Seth Forshee (DigitalOcean) wrote: > > > > On Mon, Mar 04, 2024 at 11:19:54AM +0100, Roberto Sassu wrote: > > > > > On Wed, 2024-02-21 at 15:24 -0600, Seth Forshee (DigitalOcean) wr= ote: > > > > > > Use the vfs interfaces for fetching file capabilities for killp= riv > > > > > > checks and from get_vfs_caps_from_disk(). While there, update t= he > > > > > > kerneldoc for get_vfs_caps_from_disk() to explain how it is dif= ferent > > > > > > from vfs_get_fscaps_nosec(). > > > > > >=20 > > > > > > Signed-off-by: Seth Forshee (DigitalOcean) > > > > > > --- > > > > > > security/commoncap.c | 30 +++++++++++++----------------- > > > > > > 1 file changed, 13 insertions(+), 17 deletions(-) > > > > > >=20 > > > > > > diff --git a/security/commoncap.c b/security/commoncap.c > > > > > > index a0ff7e6092e0..751bb26a06a6 100644 > > > > > > --- a/security/commoncap.c > > > > > > +++ b/security/commoncap.c > > > > > > @@ -296,11 +296,12 @@ int cap_capset(struct cred *new, > > > > > > */ > > > > > > int cap_inode_need_killpriv(struct dentry *dentry) > > > > > > { > > > > > > - struct inode *inode =3D d_backing_inode(dentry); > > > > > > + struct vfs_caps caps; > > > > > > int error; > > > > > > =20 > > > > > > - error =3D __vfs_getxattr(dentry, inode, XATTR_NAME_CAPS, NULL= , 0); > > > > > > - return error > 0; > > > > > > + /* Use nop_mnt_idmap for no mapping here as mapping is unimpo= rtant */ > > > > > > + error =3D vfs_get_fscaps_nosec(&nop_mnt_idmap, dentry, &caps)= ; > > > > > > + return error =3D=3D 0; > > > > > > } > > > > > > =20 > > > > > > /** > > > > > > @@ -323,7 +324,7 @@ int cap_inode_killpriv(struct mnt_idmap *id= map, struct dentry *dentry) > > > > > > { > > > > > > int error; > > > > > > =20 > > > > > > - error =3D __vfs_removexattr(idmap, dentry, XATTR_NAME_CAPS); > > > > > > + error =3D vfs_remove_fscaps_nosec(idmap, dentry); > > > > >=20 > > > > > Uhm, I see that the change is logically correct... but the origin= al > > > > > code was not correct, since the EVM post hook is not called (thus= the > > > > > HMAC is broken, or an xattr change is allowed on a portable signa= ture > > > > > which should be not). > > > > >=20 > > > > > For completeness, the xattr change on a portable signature should= not > > > > > happen in the first place, so cap_inode_killpriv() would not be c= alled. > > > > > However, since EVM allows same value change, we are here. > > > >=20 > > > > I really don't understand EVM that well and am pretty hesitant to t= ry an > > > > change any of the logic around it. But I'll hazard a thought: shoul= d EVM > > > > have a inode_need_killpriv hook which returns an error in this > > > > situation? > > >=20 > > > Uhm, I think it would not work without modifying > > > security_inode_need_killpriv() and the hook definition. > > >=20 > > > Since cap_inode_need_killpriv() returns 1, the loop stops and EVM wou= ld > > > not be invoked. We would need to continue the loop and let EVM know > > > what is the current return value. Then EVM can reject the change. > > >=20 > > > An alternative way would be to detect that actually we are setting th= e > > > same value for inode metadata, and maybe not returning 1 from > > > cap_inode_need_killpriv(). > > >=20 > > > I would prefer the second, since EVM allows same value change and we > > > would have an exception if there are fscaps. > > >=20 > > > This solves only the case of portable signatures. We would need to > > > change cap_inode_need_killpriv() anyway to update the HMAC for mutabl= e > > > files. > >=20 > > I see. In any case this sounds like a matter for a separate patch > > series. >=20 > Agreed. Christian, how realistic is that we don't kill priv if we are setting the same owner? Serge, would we be able to replace __vfs_removexattr() (or now vfs_get_fscaps_nosec()) with a security-equivalent alternative? Thanks Roberto