Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp270220lqs; Tue, 5 Mar 2024 01:12:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW/P7e2N0KPR0We4dJ2eDWFuoKbtvFCANTXgGQqsHIwNLLHP1BdOmalSgdwl3vY6eCkTwe/6aNu3RnaFh/t0wci8g/aAShyjlX89EUYEQ== X-Google-Smtp-Source: AGHT+IFB26utw25tiQ8nbkh7MMfmdwF56oqOFwjL7roPDqm15ZxeAm1HJXdyNyve8CbVwyyoPPlY X-Received: by 2002:a25:e444:0:b0:dc2:279f:f7e with SMTP id b65-20020a25e444000000b00dc2279f0f7emr7437583ybh.10.1709629951326; Tue, 05 Mar 2024 01:12:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709629951; cv=pass; d=google.com; s=arc-20160816; b=XMhYPn6Si77yKf6BuYjZw186R3fziATCqr5XxAlusF3C4KMVWArcqQ56j3sNIQj2WY I0645t95Ht1Lh9nd5dRepsXxfmiC9ByjizZ8E0A6LGYtwwIH/Gdj6wiWJxaK8hFlzlmt ufrtR3aY940WIvCjFakXxOjAGnq5Kh84zFnDylwfGXT1Xsa7u+KOdFWfjd3qz3pfbae3 T1V86W2Qp5e5ICg2QFohawSMAJKvKFKk87GWlfbAquHkqkgpClROHpDLh0S6Tkx1DGU+ 1IYNs9CJhSeo34MqHkZmQOZxBScdkgts5+9Rzp8Q61NA2rcR1wNkfJewFxX9hwG+kS3z P44Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Q/dcfPsln7AHth3OvmEbUBch8rTNl1R15vjQCPTBgXc=; fh=VjBB8bGBlgZThp2HvqpAsodFv1ocGWYlsyWJoN2UHd4=; b=nJ1KSeXp8i7iZc/tnZrAzA8nneRxjWTRZSqVsM5mqLjBSAOJLEnc5f6SbSuOv6pXyk L+c/ut9Df3xiowPRFvwpYyYWQFvE+ZIScGUw4AULVuUxcZdfugGkfEUqrR9vWVqN37J0 oy7YDTghmKY3HTqYEXyQYPDKoFi+dmLtVJeY8UbB0irOnOOrnuouXa9EBD5TG0YIXnCb 1pz+WwFQxYrqBvM6WCYm8VzI48CBweiI7oJoywbHN2BqecEHc6t8ud7kDyxM72sr8i0v 6PYmncONtSDl0KbHSQpKbllbadGVgp0d1NxHw/3lu6IvA+u4Ab/DjSIs/XCOKrrbiSP5 AnWw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VHAMZBJR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-91970-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91970-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z2-20020ac87f82000000b0042edd2c7a15si6737741qtj.146.2024.03.05.01.12.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 01:12:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91970-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VHAMZBJR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-91970-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91970-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 136161C21A00 for ; Tue, 5 Mar 2024 09:12:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D69652F60; Tue, 5 Mar 2024 09:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VHAMZBJR" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 304B84DA1F; Tue, 5 Mar 2024 09:12:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709629936; cv=none; b=gACL2+hl1sY0dlb/04uxAT7bIt62Jh3kNvkMz+l3XUkiqMbrw2GSZooMHe66B4h44uXNHUQCI+Y8kQNddOnRznWGEA9L3OCzWB+VIPxgDBgUvxHskWZDKzUyA6fRw4QM7yEGDZ0ZUVA+YJ8rSN0EsW6NdvD3Rlfe0+0uxwwCG5Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709629936; c=relaxed/simple; bh=LQj0UdUDprFZhCk/sD0ivlB0RR+zzlR48MZkUdMbHFg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DySCKimLNW2oEK1/x35V1r9zaCURNEc9yFY4AzfV7QJVj5FTwR4xS6tI77dkCbfXlsRczfcNRut3lZElc8KHFTpsV9GILKyGcnqNl5wJEkSekvTQ3ooK9fIp2VjLPT3uAqF+oeIb4mO/upAKyANrqVFnGH+hT1ar+88CrKF7JH4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VHAMZBJR; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A036AC433C7; Tue, 5 Mar 2024 09:12:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709629935; bh=LQj0UdUDprFZhCk/sD0ivlB0RR+zzlR48MZkUdMbHFg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VHAMZBJR6iOLpsCagpRqBCTT6yOZZ/40nSbEHm6Deht9E7xa7MAJBGLwYAxT5N2AV qKjKeS42MQwQu7B5CNdNODxPK5aWJqje6X5cwSnQCQO/J8u9OD+EYKLBylhsMcO+at 8TRgDbije51zVdjQ62cqeSPZjsLBGjbwyp7Y99g21Nvq0FFm3qGWM2vePr6XAvEkSA 6ZsVoWMJrOh2P6znfrm73CEmJi+M4ZLE+YgpIoHKC08tRCPt9NELXlToCkxgpdgnfw N3KdD4dsQs1c+7TQ+Uu+dAlE17b+m/G1nzKWMh9cawmAj6ozeLIy2zCxLSioPfMW8y azUpWTy5lw/7w== Date: Tue, 5 Mar 2024 10:12:06 +0100 From: Christian Brauner To: "Seth Forshee (DigitalOcean)" Cc: Roberto Sassu , 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 Subject: Re: [PATCH v2 24/25] commoncap: use vfs fscaps interfaces Message-ID: <20240305-fachjargon-abmontieren-75b1d6c67a83@brauner> References: <20240221-idmap-fscap-refactor-v2-0-3039364623bd@kernel.org> <20240221-idmap-fscap-refactor-v2-24-3039364623bd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: On Mon, Mar 04, 2024 at 10:56:17AM -0600, Seth Forshee (DigitalOcean) wrote: > 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) wrote: > > > > > Use the vfs interfaces for fetching file capabilities for killpriv > > > > > checks and from get_vfs_caps_from_disk(). While there, update the > > > > > kerneldoc for get_vfs_caps_from_disk() to explain how it is different > > > > > from vfs_get_fscaps_nosec(). > > > > > > > > > > Signed-off-by: Seth Forshee (DigitalOcean) > > > > > --- > > > > > security/commoncap.c | 30 +++++++++++++----------------- > > > > > 1 file changed, 13 insertions(+), 17 deletions(-) > > > > > > > > > > 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 = d_backing_inode(dentry); > > > > > + struct vfs_caps caps; > > > > > int error; > > > > > > > > > > - error = __vfs_getxattr(dentry, inode, XATTR_NAME_CAPS, NULL, 0); > > > > > - return error > 0; > > > > > + /* Use nop_mnt_idmap for no mapping here as mapping is unimportant */ > > > > > + error = vfs_get_fscaps_nosec(&nop_mnt_idmap, dentry, &caps); > > > > > + return error == 0; > > > > > } > > > > > > > > > > /** > > > > > @@ -323,7 +324,7 @@ int cap_inode_killpriv(struct mnt_idmap *idmap, struct dentry *dentry) > > > > > { > > > > > int error; > > > > > > > > > > - error = __vfs_removexattr(idmap, dentry, XATTR_NAME_CAPS); > > > > > + error = vfs_remove_fscaps_nosec(idmap, dentry); > > > > > > > > Uhm, I see that the change is logically correct... but the original > > > > 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 signature > > > > which should be not). > > > > > > > > For completeness, the xattr change on a portable signature should not > > > > happen in the first place, so cap_inode_killpriv() would not be called. > > > > However, since EVM allows same value change, we are here. > > > > > > I really don't understand EVM that well and am pretty hesitant to try an > > > change any of the logic around it. But I'll hazard a thought: should EVM > > > have a inode_need_killpriv hook which returns an error in this > > > situation? > > > > Uhm, I think it would not work without modifying > > security_inode_need_killpriv() and the hook definition. > > > > Since cap_inode_need_killpriv() returns 1, the loop stops and EVM would > > 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. > > > > An alternative way would be to detect that actually we are setting the > > same value for inode metadata, and maybe not returning 1 from > > cap_inode_need_killpriv(). > > > > I would prefer the second, since EVM allows same value change and we > > would have an exception if there are fscaps. > > > > This solves only the case of portable signatures. We would need to > > change cap_inode_need_killpriv() anyway to update the HMAC for mutable > > files. > > I see. In any case this sounds like a matter for a separate patch > series. Agreed.