Received: by 2002:a05:7208:13ce:b0:7f:395a:35b6 with SMTP id r14csp1196995rbe; Fri, 1 Mar 2024 07:05:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUn0plGFZvEr44hFABtwl/nE0zjWuhXZAIKEMTw7yNjHdKz4GQHpZ7FVrJ6PPFktKGs7M3x91DtgLCVKbasgWxY+wOab/MQTq2kRcSkjw== X-Google-Smtp-Source: AGHT+IHelZa5Q8B7xHztXSEyz5fmT5ekyAYlNyZN5ZUj4SD8iypIF6YDje/lFafVcxde/mSgQsLT X-Received: by 2002:a17:906:1cd5:b0:a44:15c3:c8e9 with SMTP id i21-20020a1709061cd500b00a4415c3c8e9mr1671832ejh.28.1709305504052; Fri, 01 Mar 2024 07:05:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709305504; cv=pass; d=google.com; s=arc-20160816; b=u0yqc3sXt5EO4ldH/U4A3nqwzDNxENuf7ODRFUINsON4KzCyoZgRThhm1UXADf7Srh S5q7E3+ouOgg3zjVcmoK2z8FlIQn9h6HrwH3+TaEwFQQSFFfcSglCs9Pl0ajL0f52LwJ iScXa0EpBr9ZCmfn10W7BSkQcJTvauTCXkS7fnJPyxpdAlPsqRs9ip50dQaK7rkxpl/J bVEnP6AdKQ+K7cURnrig0Flly6wpvaPXfVLqG4pS3qjpNL4fjwMerEVhk7b9gW1/aqDG wOIGYWmdPrZgezNZ0q+e/S5ygLb+8Y/ZJDJMNxHuaHnkpK/NZ+vIyBrMwarKx5qoTjha NYRg== 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=Hf/BsqwqcONCyipZ9cka8dXqVmnmTU2kQziFMOfcmxM=; fh=XUN01cLfU8Iz/dnSTgU4ryS2JZ8NsLzC/dcCiYNqj+U=; b=e+PEHrmrC6nCfGVtB1kVcWoumcW0by/CzbY5lAF3alQe7+lM5o+PFCizxAY3uSeIlc UYz8+CE3f4Q2x4B7ePszzh3BcTlbOoa+K/2uCZgCY9pIdSbAKMfEsvayxQZ3Jft/oIdO 56Rtnxn9NLvIUK80vWS+kDWkr9aarIm7SYrvEUn4r1PibcOKA95wNShERC6/wuiY/h3P MRcn8aqCOE3xdDOHqgORafUB4u576CPpIKEE68xVqtR+hrMa1lBYVAblKGjgvucG0bED HuRbRJGyAfHnSAw+ZqexKHr63aE74x8IWMEjwCEY43/mCqeCrLUeVWVdy/sajYbBFywj otfw==; 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-88600-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88600-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id du17-20020a17090772d100b00a43b01117aasi1573370ejc.32.2024.03.01.07.05.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 07:05:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88600-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-88600-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88600-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 am.mirrors.kernel.org (Postfix) with ESMTPS id A36F51F22BC3 for ; Fri, 1 Mar 2024 15:05:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9058F1FDD; Fri, 1 Mar 2024 15:04:45 +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 2E7EC3A8E3; Fri, 1 Mar 2024 15:04:42 +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=1709305484; cv=none; b=BLoij6TMLFgbmqEKDy9aK0Dz47jqORXmLxmTpoFab/73Jh3Ei6FJmsEqRkQtPQlGbYtxpHxtLyPjyXfU0TEJXGRHCnwTgUSIzzBaSIl05+AeMNbKCdYON/p03XC3VJ2OOHD7kt1vP82zdlun9ouAu1+yU2RPiNwtF3PP28F7daw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709305484; c=relaxed/simple; bh=CLfHGgV8g9ikDXr41EpApqiaZGI0K8iTSgXJt1K3S6Q=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=PIaPpuxN0nniTwyZEFoAaLJeGZXT5GUdAzRcE5cxQdMb9LUVtExx3OdN1wxuTQtD5yj6imY9/fazALaszKzmGRGnJJk9z3GTi8u+EuV+Whl90u3nSOULXPm/1FpdSUrFTLI+HJMJwg4dtCykAMWomrLCtgKQ5Hle6FjTYgTjYA0= 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.29]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4TmWF93hfZz9y4Sq; Fri, 1 Mar 2024 22:49:01 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.27]) by mail.maildlp.com (Postfix) with ESMTP id B87D4140D09; Fri, 1 Mar 2024 23:04:31 +0800 (CST) Received: from [127.0.0.1] (unknown [10.204.63.22]) by APP2 (Coremail) with SMTP id GxC2BwAH9Cdu7uFlW217Aw--.47273S2; Fri, 01 Mar 2024 16:04:31 +0100 (CET) Message-ID: Subject: Re: [PATCH v2 14/25] evm: add support for fscaps security hooks From: Roberto Sassu To: "Seth Forshee (DigitalOcean)" Cc: Christian Brauner , 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: Fri, 01 Mar 2024 16:04:11 +0100 In-Reply-To: References: <20240221-idmap-fscap-refactor-v2-0-3039364623bd@kernel.org> <20240221-idmap-fscap-refactor-v2-14-3039364623bd@kernel.org> <15a69385b49c4f8626f082bc9b957132388414fb.camel@huaweicloud.com> 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: MIME-Version: 1.0 X-CM-TRANSID:GxC2BwAH9Cdu7uFlW217Aw--.47273S2 X-Coremail-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or3voofrz/1tbiAgAJBF1jj5bh2gABsS On Fri, 2024-03-01 at 08:39 -0600, Seth Forshee (DigitalOcean) wrote: > On Fri, Mar 01, 2024 at 10:19:13AM +0100, Roberto Sassu wrote: > > On Wed, 2024-02-21 at 15:24 -0600, Seth Forshee (DigitalOcean) wrote: > > > Support the new fscaps security hooks by converting the vfs_caps to r= aw > > > xattr data and then handling them the same as other xattrs. > >=20 > > Hi Seth > >=20 > > I started looking at this patch set. > >=20 > > The first question I have is if you are also going to update libcap > > (and also tar, I guess), since both deal with the raw xattr. >=20 > There are no changes needed for userspace; it will still deal with raw > xattrs. As I mentioned in the cover letter, capabilities tests from > libcap2, libcap-ng, ltp, and xfstests all pass against this sereies. > That's with no modifications to userspace. Yes, figured it out after applying the patch set. Then yes, IMA/EVM tests should work too. > > From IMA/EVM perspective (Mimi will add on that), I guess it is > > important that files with a signature/HMAC continue to be accessible > > after applying this patch set. > >=20 > > Looking at the code, it seems the case (if I understood correctly, > > vfs_getxattr_alloc() is still allowed). >=20 > So this is something that would change based on Christian's request to > stop using the xattr handlers entirely for fscaps as was done for acls. > I see how this would impact EVM, but we should be able to deal with it. >=20 > I am a little curious now about this code in evm_calc_hmac_or_hash(): >=20 > size =3D vfs_getxattr_alloc(&nop_mnt_idmap, dentry, xattr->name, > &xattr_value, xattr_size, GFP_NOFS); > if (size =3D=3D -ENOMEM) { > error =3D -ENOMEM; > goto out; > } > if (size < 0) > continue; >=20 > user_space_size =3D vfs_getxattr(&nop_mnt_idmap, dentry, > xattr->name, NULL, 0); > if (user_space_size !=3D size) > pr_debug("file %s: xattr %s size mismatch (kernel: %d, user: %d)\n", > dentry->d_name.name, xattr->name, size, > user_space_size); >=20 > Because with the current fscaps code you actually could end up getting > different sizes from these two interfaces, as vfs_getxattr_alloc() reads > the xattr directly from disk but vfs_getxattr() goes through > cap_inode_getsecurity(), which may do conversion between v2 and v3 > formats which are different sizes. Yes, that was another source of confusion. It happened that security.selinux in the disk was without '\0', and the one from vfs_getxattr() had it (of course the HMAC wouldn't match). So, basically, you set something in user space and you get something different. Example: # setfattr -n security.selinux -v "unconfined_u:object_r:admin_home_t:s0" t= est-file SELinux active: # getfattr -m - -d -e hex test-file security.selinux=3D0x756e636f6e66696e65645f753a6f626a6563745f723a61646d696e= 5f686f6d655f743a733000 Smack active: # getfattr -m - -d -e hex test-file security.selinux=3D0x756e636f6e66696e65645f753a6f626a6563745f723a61646d696e= 5f686f6d655f743a7330 evmctl (will) allow to provide a hex xattr value for fscaps. That should be the one to be used (and vfs_getxattr_alloc() does that). However, I guess if the conversion happens, evmctl cannot correctly verify anymore the file, unless the same string is specified for verification (otherwise it reads the xattr through vfs_getxattr(), which would be different). Roberto