Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp529393lqs; Tue, 5 Mar 2024 08:41:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVtcqTMcYet7+mgfSn9JkeS8JyKOdsf/eUxJuid3jEPuOrM1Eksx1mbViX8Ij8b4bX+iZitmrP2eTp9X6GGbuwSxFhpvb+vkoLis+cWPg== X-Google-Smtp-Source: AGHT+IElADoisWFS7mSaDHb3CE1M5Xzx6m+aPFmOOsRV48XkhHN8LmuouBXuE7UTm1vs4yr3S+cW X-Received: by 2002:aca:2b19:0:b0:3c2:138e:92f8 with SMTP id i25-20020aca2b19000000b003c2138e92f8mr1486805oik.16.1709656887790; Tue, 05 Mar 2024 08:41:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709656887; cv=pass; d=google.com; s=arc-20160816; b=jE8qNOD90xS9G+eGDBVvR9/eRSQnIXxqyQnCQdhgMH2HCsbJkqyf9KFuLYmZFEZcdN mR6eBzywPEPQ8R9EzxMqaYkAW86ctbJXMfQD5JdtGA2fq2F6U8wcIZfPwoSZ5+uIeRoT swdKFMRWOqWuNdBMvOSctscbKJ4bQL0OinhPRzTS+9VSj8ocwd3OfYqshNkSEP/PDwAm 5/bM9YLSzgI3OhCKM3XC3Zu57uYW5V7VBLoHBxDm2zllZEJFdtWWTgUdcCAdeVoTvQ0W 3p10Asm2x2gkfNm7cO39dUunxup2UW0snx5ix2IJ87XADkz1rPMWcOpF3S9IxqfdQyZw 6+Xw== 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=0Gz+J5fZWazDXmOvFkUgJ3Nr78ncOITf99W+8icBQEo=; fh=+9iVf4/eN0Sv+Vnz0xEW2LVZosRvbbIyzfRHipoussU=; b=ODLLmB9sXT6AjrC3GMFtIWYhZ9JZeYK9RECRbv/17Tj/RNPBS7m+8Vo1wTYSOS4EHQ NSmNcaTBFJdpem+ERkj2UrKaJi73aj9ItFVrlYoxv2THL1r6i00wwMyeTaw+q8Ah78cQ t9fCwNnd8AFJVugFIwvCOOseoljA0kSYr4mqI3GiIw8++QxLo0Am8tfqieqG8+Hqc+q8 F+jJUbpWXJmLBLzxytcQx7PQMmpFjKK4XsUnFGDPeMMzkS3S9aFw2CNtPB749yeVZFld vLBfQIUAjx52N+HqKxYYbNcLaofTHVA+Allk19F584Pkpxu6os8Fly4nmdzgVvNhE0VM CB9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mCLAEoGx; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-92684-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92684-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id m11-20020a62f20b000000b006e48bbb9073si10163399pfh.309.2024.03.05.08.41.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 08:41:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-92684-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mCLAEoGx; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-92684-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92684-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 8157EB2451D for ; Tue, 5 Mar 2024 16:28:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9DB0812E1EB; Tue, 5 Mar 2024 16:26:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mCLAEoGx" 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 9322C128374; Tue, 5 Mar 2024 16:26:16 +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=1709655976; cv=none; b=tLQb6OR32SGRSRbNL+Hcrpz6XiQflvAIyZUCTOQCIf2TDwdr4DwiP7UODbY4HNfk1zxQ2rBRe0+HingJE7i6COXog1D7p6xfMquaa2/Mwu/q7VIUwihKXFkDDW3ubhD9JSX1vkeGOPrPcEe/c4ZLMA3Uk+r4BWPFOw/6bVsjjTg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709655976; c=relaxed/simple; bh=rJDCbsppxsCZ/6gOdhGNkAd2bfvRU7iE7Ysglyc+jqA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tL5PWemt8F36jDiMAtRRraxUQRq61Ts5un1xrfMXeTTL3jWbQ5VwscrAMWPcmwuZ8ohUAAXRx9QqxFafzT5ec+uONlH3ZRLvwsfP2/XBWeIJ0EfH3S6AEd9Yb7k5JzG01OonA78SbP5voYwOgWbVEtqUexRh7KrPY9r1+W7iSpU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mCLAEoGx; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBE78C43390; Tue, 5 Mar 2024 16:26:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709655976; bh=rJDCbsppxsCZ/6gOdhGNkAd2bfvRU7iE7Ysglyc+jqA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mCLAEoGxZC5006mHitJaoWtcNzJEIHdHVyzoN4RrD2KkYX82tM0YjFhucIxLOnwf+ hEbkkIh3icM7xU2GQ6hSzfWnuB8lmInH+goeDYWbitDBOVG+8NFpMYyvgLST0sGqd6 ZYfFGVSaUp/2ITdxhKmnshuznERdD47lSMOomdXMtv6/o7cMEYTlEKvS9mYgXJfylJ QZU39f1XRVlKhQepG1YHi/6JSsIYzCBGfdcmlimq3k88R0HjtUeTmjyaRmLIJaCo2b oXdnxvxOZUTCdi6kxcVU/YrQgedb+YZr7SPnX7kNkczD+9BqpHQicydKkG3tWmjMcO 93N6jg6WAXBmQ== Date: Tue, 5 Mar 2024 17:26:08 +0100 From: Christian Brauner To: Roberto Sassu Cc: "Seth Forshee (DigitalOcean)" , 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-zyklisch-halluzinationen-98b782666cf8@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> <3098aef3e5f924e5717b4ba4a34817d9f22ec479.camel@huaweicloud.com> 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: <3098aef3e5f924e5717b4ba4a34817d9f22ec479.camel@huaweicloud.com> On Tue, Mar 05, 2024 at 01:46:56PM +0100, Roberto Sassu wrote: > 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) 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. > > Christian, how realistic is that we don't kill priv if we are setting > the same owner? Uhm, I would need to see the wider context of the proposed change. But iiuc then you would be comparing current and new fscaps and if they are identical you don't kill privs? I think that would work. But again, I would need to see the actual context/change to say something meaningful.