Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6094955rdb; Thu, 14 Dec 2023 08:10:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCfK4RO4fsBGN7lvwI33N4/FJr+ulvpRJ34Jpp52iEg2UtCu9foAE3I+WaLAuBUaX2BVaN X-Received: by 2002:a17:902:ab83:b0:1d0:6ffd:e2ef with SMTP id f3-20020a170902ab8300b001d06ffde2efmr9334214plr.137.1702570231398; Thu, 14 Dec 2023 08:10:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702570231; cv=none; d=google.com; s=arc-20160816; b=jKG4JPpd6C+qzFJDC3lA0pEHDXsRVJ1szI1iiTnMmnnlQBefBGD6CpYwatM+/HyH8u iOZq6497IOctsLfA6wxFMeDEc6hR+EloxvjTWndGuRPQeOS/VjMQ03zeRr4ZEWwmAr4U ap1NeIKvZFd6bUqkdvKeESm1dp+gyJ2+trR0MrLy8vhlhxTBHeSiPUF96PwqF1+zPDWe djHDSo06CTDaV5TLqMC2LZhtogbvCaN3Trvio1BuNV2CwziCrh3QudN+mw6NAbX58wQU +jAA8G8KlxeiUrN2ucGdzevZpYwRj7BCJw1Khms6MrzbSDa2zHYoBLwLHaRODtAd4Rcu H8RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature; bh=65zoArfKlAIKj+jHAyVvOkf//7nWNHHCKZamla+kz0Y=; fh=OBJYaYowqPj4tpG8X+ZbRjAXvdNsueQ31Fk1nb9Ya6A=; b=Lp63FmOU9sxfwaTRPnBSWpCjLB+1daNIPnTsq4b/hkibALZFimCmsCLQDDIsEVknWh 3Yo6SW2MIaF/3YzTqkGNwF9rgOE3OLMjTK9r/aPYy6hAfslWxty2CckE1mf3BV/1iyho tRtipmqILX9WoSaKyNVaKvAifAv9ZZXpcSZ17nuKvaBL5zq/2OJCpZ7krbc7FdcfQlF/ vTNSTNf9qfBdVGx2glFpFXjS6YMlFH4000Z6h63KxfklqNyNDexjW65BPd1I/LJvkeIk l/oHywkF+anKCmMF0hxCBqhkt1UCm9Adwm/BOxybokfDeh+MduJIcR/JG3KiAGhitSkG gCkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=TClWSD6Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id v12-20020a1709028d8c00b001cf9e86314dsi528521plo.637.2023.12.14.08.10.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 08:10:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=TClWSD6Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 4006982C4028; Thu, 14 Dec 2023 08:10:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443711AbjLNQKK (ORCPT + 99 others); Thu, 14 Dec 2023 11:10:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230179AbjLNQKI (ORCPT ); Thu, 14 Dec 2023 11:10:08 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC083115; Thu, 14 Dec 2023 08:10:13 -0800 (PST) Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BEFW6Fa010339; Thu, 14 Dec 2023 16:09:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=pp1; bh=65zoArfKlAIKj+jHAyVvOkf//7nWNHHCKZamla+kz0Y=; b=TClWSD6Qx0RGjGrbdNeLoCsTdrhG4E5pK6b975v+r8iHZ7BuVhFIam8BVLKja0EV8RdM O7PZ9S3ZQP/dPbFUzi6qSNo2rmQR8LR16aCFphHL5Mamla5kShsoyD6dry7ewjqVxhbk Dn/k1z70RerMnxPIs9QNmHLw3PrM8w8TtKhCZnmFoqjwA/7Bk8hoVAw1w/O+kX8jwTcX xO73n+FvpGh/SSbRrI/a2lhJ4xL+uGBWxLSaxnV9+JGQDQoNbuPRAa3zB7nNNcxmF4nI 2LOc7RttJcPjZV2PnGX75MKJQ4ilfQFpWGJy6r7Hi1E7cHaef0gt4h/n64nXq1CAh/gZ UA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3v04ea94sk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Dec 2023 16:09:48 +0000 Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3BEFWCPH010489; Thu, 14 Dec 2023 16:09:47 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3v04ea94s3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Dec 2023 16:09:47 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3BEEFE4g013874; Thu, 14 Dec 2023 16:09:46 GMT Received: from smtprelay03.wdc07v.mail.ibm.com ([172.16.1.70]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3uw592h39a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Dec 2023 16:09:46 +0000 Received: from smtpav05.dal12v.mail.ibm.com (smtpav05.dal12v.mail.ibm.com [10.241.53.104]) by smtprelay03.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3BEG9jV618612888 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Dec 2023 16:09:45 GMT Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4CF5458068; Thu, 14 Dec 2023 16:09:45 +0000 (GMT) Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7297B58065; Thu, 14 Dec 2023 16:09:42 +0000 (GMT) Received: from li-f45666cc-3089-11b2-a85c-c57d1a57929f.watson.ibm.com (unknown [9.31.99.90]) by smtpav05.dal12v.mail.ibm.com (Postfix) with ESMTP; Thu, 14 Dec 2023 16:09:42 +0000 (GMT) Message-ID: <579803fe4750b2ac1cbf31f4d38929c9ec901a41.camel@linux.ibm.com> Subject: Re: [RFC][PATCH] overlayfs: Redirect xattr ops on security.evm to security.evm_overlayfs From: Mimi Zohar To: Amir Goldstein , Roberto Sassu Cc: Christian Brauner , Seth Forshee , miklos@szeredi.hu, linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org, 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 , Eric Snowberg Date: Thu, 14 Dec 2023 11:09:41 -0500 In-Reply-To: References: <20231208172308.2876481-1-roberto.sassu@huaweicloud.com> <20231208-tauziehen-zerfetzt-026e7ee800a0@brauner> <20231211-fortziehen-basen-b8c0639044b8@brauner> <019f134a-6ab4-48ca-991c-5a5c94e042ea@huaweicloud.com> <59bf3530-2a6e-4caa-ac42-4d0dab9a71d1@huaweicloud.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-22.el8) X-TM-AS-GCONF: 00 X-Proofpoint-GUID: xcpWVQEhxlE-8galbqQJSAxdGFwLi2Nv X-Proofpoint-ORIG-GUID: EUrIUsu8j469rbUs2Joh63Hlbwdqbz-X Content-Transfer-Encoding: 8bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-14_11,2023-12-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 spamscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 lowpriorityscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312140114 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, 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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 14 Dec 2023 08:10:27 -0800 (PST) On Thu, 2023-12-14 at 17:09 +0200, Amir Goldstein wrote: > On Thu, Dec 14, 2023 at 3:43 PM Roberto Sassu > wrote: > > > > On Tue, 2023-12-12 at 10:27 -0500, Mimi Zohar wrote: > > > On Tue, 2023-12-12 at 14:13 +0100, Roberto Sassu wrote: > > > > On 12.12.23 11:44, Amir Goldstein wrote: > > > > > On Tue, Dec 12, 2023 at 12:25 PM Roberto Sassu > > > > > wrote: > > > > > > > > > > > > On 11.12.23 19:01, Christian Brauner wrote: > > > > > > > > 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. > > > > > > > > > > > > > > "Changes to the underlying filesystems while part of a mounted overlay > > > > > > > filesystem are not allowed. If the underlying filesystem is changed, the > > > > > > > behavior of the overlay is undefined, though it will not result in a > > > > > > > crash or deadlock." > > > > > > > > > > > > > > https://docs.kernel.org/filesystems/overlayfs.html#changes-to-underlying-filesystems > > > > > > > > > > > > > > So I don't know why this would be a problem. > > > > > > > > > > > > + Eric Snowberg > > > > > > > > > > > > Ok, that would reduce the surface of attack. However, when looking at: > > > > > > > > > > > > ovl: Always reevaluate the file signature for IMA > > > > > > > > > > > > Commit db1d1e8b9867 ("IMA: use vfs_getattr_nosec to get the > > > > > > i_version") > > > > > > partially closed an IMA integrity issue when directly modifying a file > > > > > > on the lower filesystem. If the overlay file is first opened by a > > > > > > user > > > > > > and later the lower backing file is modified by root, but the extended > > > > > > attribute is NOT updated, the signature validation succeeds with > > > > > > the old > > > > > > original signature. > > > > > > > > > > > > Ok, so if the behavior of overlayfs is undefined if the lower backing > > > > > > file is modified by root, do we need to reevaluate? Or instead would be > > > > > > better to forbid the write from IMA (legitimate, I think, since the > > > > > > behavior is documented)? I just saw that we have d_real_inode(), we can > > > > > > use it to determine if the write should be denied. > > > > > > > > > > > > > > > > There may be several possible legitimate actions in this case, but the > > > > > overall concept IMO should be the same as I said about EVM - > > > > > overlayfs does not need an IMA signature of its own, because it > > > > > can use the IMA signature of the underlying file. > > > > > > > > > > Whether overlayfs reads a file from lower fs or upper fs, it does not > > > > > matter, the only thing that matters is that the underlying file content > > > > > is attested when needed. > > > > > > > > > > The only incident that requires special attention is copy-up. > > > > > This is what the security hooks security_inode_copy_up() and > > > > > security_inode_copy_up_xattr() are for. > > > > > > > > > > When a file starts in state "lower" and has security.ima,evm xattrs > > > > > then before a user changes the file, it is copied up to upper fs > > > > > and suppose that security.ima,evm xattrs are copied as is? > > > > > > For IMA copying up security.ima is fine. Other than EVM portable > > > signatures, security.evm contains filesystem specific metadata. > > > Copying security.evm up only works if the metadata is the same on both > > > filesystems. Currently the i_generation and i_sb->s_uuid are > > > different. > > > > > > > > When later the overlayfs file content is read from the upper copy > > > > > the security.ima signature should be enough to attest that file content > > > > > was not tampered with between going from "lower" to "upper". > > > > > > > > > > security.evm may need to be fixed on copy up, but that should be > > > > > easy to do with the security_inode_copy_up_xattr() hook. No? > > > > > > Writing security.evm requires the existing security.evm to be valid. > > > After each security xattr in the protected list is modified, > > > security.evm HMAC needs to be updated. Perhaps calculating and writing > > > security.evm could be triggered by security_inode_copy_up_xattr(). > > > Just copying a non-portable EVM signature wouldn't work, or for that > > > matter copying an EVM HMAC with different filesystem metadata. > > > > There is another problem, when delayed copy is used. The content comes > > from one source, metadata from another. > > > > I initially created test-file-lower on the lower directory > > (overlayfs/data), before mounting overlayfs. After mount on > > overlayfs/mnt: > > > > # getfattr -m - -e hex -d overlayfs/mnt/test-file-lower > > # file: overlayfs/mnt/test-file-lower > > security.evm=0x02c86ec91a4c0cf024537fd24347b780b90973402e > > security.ima=0x0404f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2 > > security.selinux=0x73797374656d5f753a6f626a6563745f723a756e6c6162656c65645f743a733000 > > > > # chcon -t unconfined_t overlayfs/mnt/test-file-lower > > > > After this, IMA creates an empty file in the upper directory > > (overlayfs/root/data), and writes security.ima at file close. > > Unfortunately, this is what is presented from overlayfs, which is not > > in sync with the content. > > > > # getfattr -m - -e hex -d overlayfs/mnt/test-file-lower > > # file: overlayfs/mnt/test-file-lower > > security.evm=0x021d71e7df78c36745e3b651ce29cb9f47dc301248 > > security.ima=0x04048855508aade16ec573d21e6a485dfd0a7624085c1a14b5ecdd6485de0c6839a4 > > security.selinux=0x73797374656d5f753a6f626a6563745f723a756e636f6e66696e65645f743a733000 > > > > # sha256sum overlayfs/mnt/test-file-lower > > f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2 overlayfs/mnt/test-file-lower > > > > # sha256sum overlayfs/root/data/test-file-lower > > 8855508aade16ec573d21e6a485dfd0a7624085c1a14b5ecdd6485de0c6839a4 overlayfs/root/data/test-file-lower (upperdir) > > > > We would need to use the lower security.ima until the copy is made, but > > at the same time we need to keep the upper valid (with all xattrs) so > > that IMA can update the next time overlayfs requests that. > > > > Yap. > > As Seth wrote, overlayfs is a combination of upper and lower. > The information that IMA needs should be accessible from either lower > or upper, but sometimes we will need to make the right choice. > > The case of security.ima is similar to that of st_blocks - > it is a data-related metadata, so it needs to be taken from the lowerdata inode > (not even the lower inode). See example of getting STATX_BLOCKS > in ovl_getattr(). > > I would accept a patch that special cases security.ima in ovl_xattr_get() > and gets it from ovl_i_path_lowerdata(), which would need to be > factored out of ovl_path_lowerdata(). > > I would also accept filtering out security.{ima,evm} from > > But I would only accept it if I know that IMA is not trying to write the > security.ima xattr when closing an overlayfs file, only when closing the > real underlying upper file. I don't see how that would be possible. As far as I'm aware, the correlation is between the overlay and the underlying lower/uppper file, not the other way around. How could a close on the underlying file trigger IMA on an overlay file? > > I would also expect IMA to filter out security.{ima,evm} xattrs in > security_inode_copy_up_xattr() (i.e. return 1). > and most importantly, a documentation of the model of IMA/EVM > and overlayfs. Ok. Mimi