Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1745134rdb; Wed, 31 Jan 2024 07:55:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlikw9cRg3kKEiPK+8u88GRwjaVIgs6+J/m58t4dxJ6ihKXDpb3dXusGZRGsFFAiZ9Q4H1 X-Received: by 2002:a05:622a:1a8b:b0:42b:ec8d:a7f8 with SMTP id s11-20020a05622a1a8b00b0042bec8da7f8mr1269004qtc.64.1706716501264; Wed, 31 Jan 2024 07:55:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706716501; cv=pass; d=google.com; s=arc-20160816; b=KRbhxvE/vaZHfBjSj/WStGFx5rXaMW2Pal/uZOzpIqKJ00MtHSRoaDhUHxusmSxJsj 4J8oJtD5Imrum4DjYOorvkCp6ZXoHEnU7wl6oaUhP+qT93rzNK+31CgGrQiqPfm8KIrG QYwfMDQiJjYhpqbs9tTz9ocHgWGNYSx1mfaH1XoKYE3D7TPo6JoJGUoZT0OuEOMeAS7R 1T+i9sUFllCTUN6EQj7h5ceBfl9xgnG+eFUn0FHCPGC1sngzq9VqeIXjEd8cX7L/PFWG pQXM1rg6iRRz6y/fvjEnmUWWHY9ploJuDaF0o2F4oo/WU53BFBk+5uT8nZjXD/CwMkUN ySlQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=Sp+45kIh37HWYYNwuHvpyq1RNM06jOtAV4lYBAKJAiQ=; fh=ST6uo5lLkDe6/fH5ECITE0Zny10PFoocGZSJNU6SiCM=; b=MZzoYMgs0ZB5R30ry09GRX9o0UT4Q+41w9IBOX3R5/djweb4kTnr5NdhWDScftZUvq aiJyja7MBttN2f4/tSE6SHIIJ8oAK5W+7rxISrQwcqtY0kPC5XDgpSXeF+WeNfAGAWr8 0meOTQUumcCqNfIdPNFSYGEusjbXalV+uHtZ/ZMSiOgkXyXcK67A9f6IKMFAq3119RyF pE1vLBreWPe7bosMWNojizvqba1inmV3VZNRfl9i3XYojbPb3yO+puTHDpE3K8rADZY+ /wPvUa3ZPtIYlbQauLu4xlrCutwlmWgUXltge9x0/WxFwoq201gv28WkCRUrsjaiWN9k YnHg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=br+vz2sV; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-46743-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46743-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCXhAFGl3KHCaTio9ORebt0mtd+Lw3S20eNz4amWMb4y2TkIRrElDYYDIMFOR6Yca3V5Q0q9uMIEE37p2xr2fB/K5JeGs2Yn43funHckBA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b22-20020a05622a021600b0042bee2f18f2si675620qtx.229.2024.01.31.07.55.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 07:55:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46743-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=@gmail.com header.s=20230601 header.b=br+vz2sV; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-46743-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46743-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 EF3E51C231EF for ; Wed, 31 Jan 2024 15:55:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9073612A15A; Wed, 31 Jan 2024 15:54:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="br+vz2sV" Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24CC3129A8D; Wed, 31 Jan 2024 15:54:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706716490; cv=none; b=EgPkYDtFnVM8ZOTgVcYswp57VH5MtTu0+5IccnVHaey1z9g7byeNCxgISJjTfZFdW6LmeAE8I/cwg1Z89AOblM/TK9T6f+fxWpMTjf9gCV2uwa/4NqxYWsD9dXpjX7L2aM20e+0QT95musLposTvRq5sSGygc0pbQCcrWkxwgbg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706716490; c=relaxed/simple; bh=962G4SeZS6ybqHxFrU26+VODCD2iTSXY5jIdT5VAmx0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=SGZyG04ipwDyqYCb2EKcka/R67b1yB2J5Um2HVMike/g0DB6/STUGJtjhauyN88UBicWRu9/E8TpDiBeYPWD+4zThEynd1WQdNGwYeZJ9WjpvRL6uqKOxOnbBxEVyhsXuH5roYfQYJEx0dPiGBnUY3Ra+PbE4V04hZ85yHp3FQ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=br+vz2sV; arc=none smtp.client-ip=209.85.219.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-dc6b5d0e015so1155436276.1; Wed, 31 Jan 2024 07:54:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706716488; x=1707321288; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Sp+45kIh37HWYYNwuHvpyq1RNM06jOtAV4lYBAKJAiQ=; b=br+vz2sV3+EOmEV7kP4zfuON4sDb2xMWnP9TglLvKNbtKZYXG7lOpQiUv9Hmzm8MGr wau6v6SUt5jfTCzbzUQkrWERvSnWWsn8G2uZorc1uC4a+mpKDHufKuuW94ff+3LLOyAh DSedETYwVxuGfZlXWBH9lXGyg9cE574oqrh5b2bIozuzgJjp5dHbgNHlqGVAxd5yHHb0 os2SYyVBYbz1ED3sR5QSwqACG0GSilPJTHCgPQBmmL2lYIdso4pvEEVylhL9vv13r0bv 4UvBRs7KHO9G6k9hM3xHxdbTrBUXIl7Xh6XfhFeF0mvttMiuy1rt72I1BVjLJBqYxBv5 NKJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706716488; x=1707321288; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Sp+45kIh37HWYYNwuHvpyq1RNM06jOtAV4lYBAKJAiQ=; b=RnqAlLpy9rjqyZrg2o4eqv9tYhuUqMR1YU7ipCK0ClEwv7fb/7UK306J5LpnMdQ4nk PHQHMYhRbitxR+6aW1iirC9BRjAL1S9xP2fDjZiw/B1lTkpjvViRRUXCIqmEicgDbeRC gV+0ZWIPnGg76Kb3agryiiiN98KaLG0e3G3BOawdMy6asVQ1zyDpAe6yCpHQDbRhX1uM DR0SfmPgRpQqnkBKLtI7qfXg609wuAyMMwOUt7CsuKRlisO21LfRtAQMJyXgD7gcJMGB 2uRtmYxZl3gt1gLl/4Go5fY12qu1xTfzx7hdZrtTpgmpngSn7mRerBRA4rVFpMsaMqyu t7wA== X-Gm-Message-State: AOJu0YxDRfyAP/J0ZasteZp0k/aVUXk8lyqDPelvUmxwargdFHgp/HK9 8YJEioGglySmfwAYXHAdTqrxqv6MwW7Zs7Cro/aTv/lsQghgc88bD+KxfB2Qdvxcx9Ah6gy7dB7 Wj0x0BZ00MJzwTvnvIwOq7cPe+wg= X-Received: by 2002:a25:c546:0:b0:dc2:3562:d234 with SMTP id v67-20020a25c546000000b00dc23562d234mr2003329ybe.12.1706716488054; Wed, 31 Jan 2024 07:54:48 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240130214620.3155380-1-stefanb@linux.ibm.com> <20240130214620.3155380-5-stefanb@linux.ibm.com> <38230b4c-54ae-45ed-a6fb-34e63501e5b1@linux.ibm.com> In-Reply-To: From: Amir Goldstein Date: Wed, 31 Jan 2024 17:54:37 +0200 Message-ID: Subject: Re: [PATCH 4/5] evm: Use the real inode's metadata to calculate metadata hash To: Stefan Berger Cc: linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, zohar@linux.ibm.com, roberto.sassu@huawei.com, miklos@szeredi.hu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 31, 2024 at 4:40=E2=80=AFPM Stefan Berger wrote: > > > > On 1/31/24 08:16, Amir Goldstein wrote: > > On Wed, Jan 31, 2024 at 4:11=E2=80=AFAM Stefan Berger wrote: > >> > >> > >> > >> On 1/30/24 16:46, Stefan Berger wrote: > >>> Changes to the file attribute (mode bits, uid, gid) on the lower laye= r > >>> are not take into account when d_backing_inode() is used when a file = is > >>> accessed on the overlay layer and this file has not yet been copied u= p. > >>> This is because d_backing_inode() does not return the real inode of t= he > >>> lower layer but instead returns the backing inode which holds old fil= e > >>> attributes. When the old file attributes are used for calculating the > >>> metadata hash then the expected hash is calculated and the file then > >>> mistakenly passes signature verification. Therefore, use d_real_inode= () > >>> which returns the inode of the lower layer for as long as the file ha= s > >>> not been copied up and returns the upper layer's inode otherwise. > >>> > >>> Signed-off-by: Stefan Berger > >>> --- > >>> security/integrity/evm/evm_crypto.c | 2 +- > >>> 1 file changed, 1 insertion(+), 1 deletion(-) > >>> > >>> diff --git a/security/integrity/evm/evm_crypto.c b/security/integrity= /evm/evm_crypto.c > >>> index b1ffd4cc0b44..2e48fe54e899 100644 > >>> --- a/security/integrity/evm/evm_crypto.c > >>> +++ b/security/integrity/evm/evm_crypto.c > >>> @@ -223,7 +223,7 @@ static int evm_calc_hmac_or_hash(struct dentry *d= entry, > >>> size_t req_xattr_value_len, > >>> uint8_t type, struct evm_digest *data= ) > >>> { > >>> - struct inode *inode =3D d_backing_inode(dentry); > >>> + struct inode *inode =3D d_real_inode(dentry); > >>> struct xattr_list *xattr; > >>> struct shash_desc *desc; > >>> size_t xattr_size =3D 0; > >> > >> We need this patch when NOT activating CONFIG_OVERLAY_FS_METACOPY but > >> when setting CONFIG_OVERLAY_FS_METACOPY=3Dy it has to be reverted... = I am > >> not sure what the solution is. > > > > I think d_real_inode() does not work correctly for all its current user= s for > > a metacopy file. > > > > I think the solution is to change d_real_inode() to return the data ino= de > > and add another helper to get the metadata inode if needed. > > I will post some patches for it. > > I thought that we may have to go through vfs_getattr() but even better > if we don't because we don't have the file *file anywhere 'near'. > > > > > However, I must say that I do not know if evm_calc_hmac_or_hash() > > needs the lower data inode, the upper metadata inode or both. > > What it needs are data structures with mode bits, uid, and gid that stat > in userspace would show. > > With or without metacopy enabled, an overlay inode st_uid st_gid st_mode are always taken from the upper most inode which is what d_real_inode() currently returns, so I do not understand what the problem is. > > > > The last time you tried to fix ovl+IMA, I asked for documentation > > of what data/metadata is protected with EVM and how are those > > protections supposed to work across overlayfs copy up, when the > > data and metadata are often split between 2 and myabe event 3 > > differnt inode. > > I always compare against what userspace sees with stat and that's what > the EVM should also work with so it ends up in reasonable matching > result in terms of hash calculation and then access permission/rejection. > I will need a lot more analysis information to be able to help you. Exactly which setup, exactly which test, exactly which inode/dentry/file objects are used and how they are accessed when things go wrong. Thanks, Amir.