Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4022658rdb; Mon, 11 Dec 2023 06:56:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQ7QVYjjWfIC2hStbWWjZJnufCqaZEyNCNDbNZH50da3IkIsicy+HpN51+YDnZuaqy6Ane X-Received: by 2002:a17:903:258a:b0:1d0:6eae:8e7b with SMTP id jb10-20020a170903258a00b001d06eae8e7bmr5089582plb.20.1702306608154; Mon, 11 Dec 2023 06:56:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702306608; cv=none; d=google.com; s=arc-20160816; b=XrQRnzotqQDwjDx5p2vUtsOZ75eAbZDHINIOXcqfvE8gpKCkaUyJXrpOqE/x2BDVoe JcX7ToLvuIlYTd5cus5RLLdLSjkfdCUjOHOd0j2JQ/iYOWK1mMvmAkc2e0dlq8GKicBU qai7KlTMHZCea5ppTCsjz9keo+tn1t1QABV2P/sfjDuXA7bJTdgz/QZRdYfX8l2+4ulH xafrBg94zz4eAslhrpK1Bifb+VW9jdxxJMIikKxOjv4IA1D0VkAwIJjMef0hSH3sanFp +Ko5ku4v1/QkC4GcYqEBB16/J4q+lLhhD8pHp9+K2u5rImlY2X5CFgNQVeYipxoMR/0n ulyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=HW61fr3HQqlKsMQXxyLPSSuvUD9ghicfmTriBVkjUnI=; fh=QnkW7t8BQS7OL9lc23k5MGNj5AYre4e1Od69qYbWK4I=; b=Bxvam9z65sCbzwXXsoSEZa1FiUJ1AnxdETHu16nhg/lQPotTf0AZsNre03OxSaLu1k IPYUB884iFlDPF9nbvX7nl7DA2W23lHc6BiWS4fDwdaW5MTW5QPRhS6B6NbV5Vsg8SiC XgObugRB8IW7lgDzHkZSMkM7bZH2U3Z+vZ0YEd5s9c6YXTJz/x68DBhG0VhiJutjrPbW Spghidb2gioX/9WktI14bnmWKGfO5rbzjBcbOpee70FsO2ykRelKdHZ05ue4csmQFjie J4QNxnuooy0O4xkLgFQXd4PNRC5B050/XPFFsmbsih08tOjLDfUDgUU7pMnx3HDjjrEz 0sIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id jj14-20020a170903048e00b001d05235181esi6129055plb.275.2023.12.11.06.56.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 06:56:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id ABB05803E302; Mon, 11 Dec 2023 06:56:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234940AbjLKO42 convert rfc822-to-8bit (ORCPT + 99 others); Mon, 11 Dec 2023 09:56:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234618AbjLKO41 (ORCPT ); Mon, 11 Dec 2023 09:56:27 -0500 Received: from frasgout13.his.huawei.com (frasgout13.his.huawei.com [14.137.139.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 533528E; Mon, 11 Dec 2023 06:56:33 -0800 (PST) Received: from mail.maildlp.com (unknown [172.18.186.29]) by frasgout13.his.huawei.com (SkyGuard) with ESMTP id 4Spkx31B9fz9xrpQ; Mon, 11 Dec 2023 22:42:31 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.47]) by mail.maildlp.com (Postfix) with ESMTP id 2D5B1140429; Mon, 11 Dec 2023 22:56:24 +0800 (CST) Received: from [127.0.0.1] (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwA3c3MKI3dlUupYAg--.22303S2; Mon, 11 Dec 2023 15:56:23 +0100 (CET) Message-ID: Subject: Re: [RFC][PATCH] overlayfs: Redirect xattr ops on security.evm to security.evm_overlayfs From: Roberto Sassu To: Christian Brauner , Amir Goldstein , Seth Forshee Cc: miklos@szeredi.hu, linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org, zohar@linux.ibm.com, paul@paul-moore.com, stefanb@linux.ibm.com, jlayton@kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, Roberto Sassu Date: Mon, 11 Dec 2023 15:56:06 +0100 In-Reply-To: <20231208-tauziehen-zerfetzt-026e7ee800a0@brauner> References: <20231208172308.2876481-1-roberto.sassu@huaweicloud.com> <20231208-tauziehen-zerfetzt-026e7ee800a0@brauner> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 X-CM-TRANSID: LxC2BwA3c3MKI3dlUupYAg--.22303S2 X-Coremail-Antispam: 1UD129KBjvJXoWxWF4DXryktF4rGF1ftw1DZFb_yoWrZFW3pF WYka4UKrs8Jr17uwnavF47Xa40y3yrJa1UXwn8Jrn5AFWDXF1IgrWxt3WUuasrXF1kX34j q3yjk34fZ3s8Z3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUk0b4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2Ij 64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x 8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE 2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42 xK8VAvwI8IcIk0rVWrJr0_WFyUJwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv 6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUrR6zUUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgAIBF1jj5N17wAAs2 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 11 Dec 2023 06:56:44 -0800 (PST) On Fri, 2023-12-08 at 23:01 +0100, Christian Brauner wrote: > On Fri, Dec 08, 2023 at 11:55:19PM +0200, Amir Goldstein wrote: > > On Fri, Dec 8, 2023 at 7:25 PM Roberto Sassu > > wrote: > > > > > > From: Roberto Sassu > > > > > > EVM updates the HMAC in security.evm whenever there is a setxattr or > > > removexattr operation on one of its protected xattrs (e.g. security.ima). > > > > > > Unfortunately, since overlayfs redirects those xattrs operations on the > > > lower filesystem, the EVM HMAC cannot be calculated reliably, since lower > > > inode attributes on which the HMAC is calculated are different from upper > > > inode attributes (for example i_generation and s_uuid). > > > > > > Although maybe it is possible to align such attributes between the lower > > > and the upper inode, another idea is to map security.evm to another name > > > (security.evm_overlayfs) > > > > If we were to accept this solution, this will need to be trusted.overlay.evm > > to properly support private overlay xattr escaping. > > > > > during an xattr operation, so that it does not > > > collide with security.evm set by the lower filesystem. > > > > You are using wrong terminology and it is very confusing to me. > > Same. Argh, sorry... > > see the overlay mount command has lowerdir= and upperdir=. > > Seems that you are using lower filesystem to refer to the upper fs > > and upper filesystem to refer to overlayfs. > > > > > > > > Whenever overlayfs wants to set security.evm, it is actually setting > > > security.evm_overlayfs calculated with the upper inode attributes. The > > > lower filesystem continues to update security.evm. > > > > > > > I understand why that works, but I am having a hard time swallowing > > the solution, mainly because I feel that there are other issues on the > > intersection of overlayfs and IMA and I don't feel confident that this > > addresses them all. This solution is specifically for the collisions on HMACs, nothing else. Does not interfere/solve any other problem. > > If you want to try to convince me, please try to write a complete > > model of how IMA/EVM works with overlayfs, using the section > > "Permission model" in Documentation/filesystems/overlayfs.rst > > as a reference. Ok, I will try. I explain first how EVM works in general, and then why EVM does not work with overlayfs. EVM gets called before there is a set/removexattr operation, and after, if that operation is successful. Before the set/removexattr operation EVM calculates the HMAC on current inode metadata (i_ino, i_generation, i_uid, i_gid, i_mode, POSIX ACLs, protected xattrs). Finally, it compares the calculated HMAC with the one in security.evm. If the verification and the set/removexattr operation are successful, EVM calculates again the HMAC (in the post hooks) based on the updated inode metadata, and sets security.evm with the new HMAC. The problem is the combination of: overlayfs inodes have different metadata than the lower/upper inodes; overlayfs calls the VFS to set/remove xattrs. The first problem basically means the HMAC on lower/upper inodes and overlayfs ones is different. The second problem is that one security.evm is not enough. We need two, to store the two different HMACs. And we need both at the same time, since when overlayfs is mounted the lower/upper directories can be still accessible. In the example I described, IMA tries to update security.ima, but this causes EVM to attempt updating security.evm twice (once after the upper filesystem performed the setxattr requested by overlayfs, another after overlayfs performed the setxattr requested by IMA; the latter fails since EVM does not allow the VFS to directly update the HMAC). Remapping security.evm to security.evm_overlayfs (now trusted.overlay.evm) allows us to store both HMACs separately and to know which one to use. I just realized that the new xattr name should be public, because EVM rejects HMAC updates, so we should reject HMAC updates based on the new xattr name too. > I want us to go the other way. Make the overlayfs layer completely > irrelevant for EVM and IMA. See a related discussion here: Not sure it is possible, as long as overlayfs uses VFS xattr calls. > Subject: Re: [PATCH 09/16] fs: add vfs_set_fscaps() > https://lore.kernel.org/r/ZXHZ8uNEg1IK5WMW@do-x1extreme I will also read this patch, in case I missed something. Thanks Roberto