Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1648892rdb; Wed, 31 Jan 2024 05:17:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1BrbhkNi1xEZB1NMk+crfWswlnSG8DH8uJqirihE9s7D0rIJ3VD8JUu0yvRvU833+CYyP X-Received: by 2002:a17:902:f815:b0:1d8:e207:c400 with SMTP id ix21-20020a170902f81500b001d8e207c400mr933600plb.116.1706707045231; Wed, 31 Jan 2024 05:17:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706707045; cv=pass; d=google.com; s=arc-20160816; b=zTug/ZBlSMrvpZkCrVx/jsmA3EU4sr1BH/M500WdGbQ6xyiHnYu4V/GePvyxxS6FQ6 OwNef6S67YsdyZWpPuu4t4UKeBCmFfnkZfo90VnQ+rjJbTxDmFzhFPV0IGvCpsTWoVDb OXbAZsCEjE2x2ZDLsygFAwjZsNxbEOjeeJy9kg0BIDJZcH2LyppnK2+IaaKtqczig4OR LLtVzXGuwsV4+UzYFAgwQ/EV3XkAINgvkYGhvCZKZ5w3rLglWkpFP2qVseg3CRkxs/nM IhDpI9tPBefTXQ/IRGzdy9gV6NAvU59Ife9hj84bPY/ypEPwk0/B6z30mLTgLy/fVdjM YmFg== 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=5VH5uYYk0MxykRHzUiex1lRzuDUS57P3V7ajJDCHXAY=; fh=w8bmBvyYz+RudzhExn2bLHg6fh2EuRHqat1QfVMTtX8=; b=YnNMY58XiYiRbRH/y4GPq1lf9WSAAOhNewnm+5O8M+zAY2/Wce/TWnnNcNhGSfiVLS 1d00poGhUJ0QXQB/pr7sJnStfWrrGH9+eRqfvozy38zdE1kcwrsomqeV1K8F1lThOWUu wtN+9JKJpTb+qY2R38cOYH+72wkKpLtHQyiHknj1fMy0+YexihsckUaVAtsLbsggHtOE jJxhc3hMnCe1LKwjkXnXjKTVBb8+rfXnrlbLh8MKpXw88g7BBJB49BHY462JpsKn41K8 FnhylaFWlotrqnIe7Ktne+wmu8xBBlvUo3Z4QKr+gRMu/GmJsi+pY4jgUZlO3gh2db6q gLyg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OVEQGekf; 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-46476-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46476-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; AJvYcCX5OML/3AEMO2WJH9O0FDlg2gc/7G36isKIu68EynIjlNg00rIxt6FJeeYTqa7pf32TvRNOHLk1pKweeurBBMeT3oXpfqHwAYO4gdP/3Q== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d11-20020a170902cecb00b001d721475ff1si9711464plg.106.2024.01.31.05.17.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 05:17:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46476-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OVEQGekf; 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-46476-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46476-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9DF5628D302 for ; Wed, 31 Jan 2024 13:16:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A21617BAF1; Wed, 31 Jan 2024 13:16:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OVEQGekf" Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (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 4DB1D7866D; Wed, 31 Jan 2024 13:16:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706706987; cv=none; b=XRQFMK9/4bWMaY9Oy79HghU2/XjsVdJ+087askYJQIa02oYEjR6yKqH86KKngvu4XEVquI5CJnQN1OpawlZy9PSC7KVVSh4FZu9Eu2it7MZ52rQ/t84msoN0K6o7jQeYrG3u1E97qfW5epPxmQzdjZ7wnODgNxKG2UkxuN1JgqY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706706987; c=relaxed/simple; bh=jbMaNkr1bTYPXRhgukPeSj3N79rSuP6MAAxEWCK1YVM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Is8o/9lviSwbzqtfgG4dnEhS1kCjilXqRxQcGrBlaN0GCko4KCYcvYjDAzh3R5tgZiwJjJDAMflln85ExHvkCTqY8RvNBGGunhkZ2TAhOl7SljCp7Acid0f8+7auAqJanPqBDOG6WWW0uVKfDmkt3tRcXL4Es5384Ukuq8LdHeE= 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=OVEQGekf; arc=none smtp.client-ip=209.85.219.45 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-qv1-f45.google.com with SMTP id 6a1803df08f44-6818aa07d81so34218806d6.0; Wed, 31 Jan 2024 05:16:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706706985; x=1707311785; 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=5VH5uYYk0MxykRHzUiex1lRzuDUS57P3V7ajJDCHXAY=; b=OVEQGekfW7/MJyOEPRuv2/wPWAzHKFX0hVRfXqfdWDeF6Zgf1vLIKWYTLWtCDVspBS msjhaAagh4j8ZRmc991tbrgjeIjVLwaflv4OBGWZCWMhTCN2EyMOKxXfn41sbh02nR4W CxGvBCrpRi73M6tHx+2b7/2SLngUZMXgXPxttZLYSYxul5U9C8Ar/f+7JpmGjuUoTTvb ERkMj+aoL0YFqJQfhnQ6aozW2MQn8prtAL1fy1Zz1l/5pDLpFwQWDOmAvA/yk0OflT2V g6JrblnYPJAux2wR9CJrAx/AKOMDp5/FCmvjYV6NijUz/DAX7TWl9Jgo7uMXcM1dFIgz SRww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706706985; x=1707311785; 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=5VH5uYYk0MxykRHzUiex1lRzuDUS57P3V7ajJDCHXAY=; b=KyHcs7kKDzlG/Rak2/2+XekY/GrBwjTz/yBjmvZc/eyA/mQMFGM29OTwdAlNFnoZd6 OPLnFSGCUawRLVy/r+cBdksq+Irlo7EdHlAvz9mUdApxNPGOk426ZTEa2zWqBLPeuMlC hLzoMHavp+CrrhEHjgHlF7igbXQCD1xZ4TT69e4jXmqHzuNCMrVacCIWfwEuL/vrNZ/s snx6wgOe6Nrm1ofOjDklHGE8+jIahzOuRxhhb0LXkJ3Z3qv/zCuj4w7Wl/3Z1ST/LyaA K4wjIYpfeRVnPMyPwTB8jaDtkossgdYio3qHSv1g+2gEAGNIHiFv/+G63OdUUX9PYRa5 Vvpw== X-Gm-Message-State: AOJu0YxBT7TtNGKLwDmwuu68jXY22+arbnhC/5xBrKELVs8bqJ79jgkG 69boJ5uXWgLubBPjakZ4FGmcdNuOrAT+ViKxrq5SxuBibqpo0UpwrhmzJHAkeCmP06LjC0/q6OJ F8Nrj29o4L8IQAbHXPYF6zJaXIWXv8GnSOSg= X-Received: by 2002:ad4:5ce9:0:b0:686:7256:c9f4 with SMTP id iv9-20020ad45ce9000000b006867256c9f4mr1663225qvb.9.1706706985131; Wed, 31 Jan 2024 05:16:25 -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: <38230b4c-54ae-45ed-a6fb-34e63501e5b1@linux.ibm.com> From: Amir Goldstein Date: Wed, 31 Jan 2024 15:16:13 +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: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 layer > > 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 up. > > This is because d_backing_inode() does not return the real inode of the > > lower layer but instead returns the backing inode which holds old file > > 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 has > > 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/e= vm/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 *den= try, > > 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 a= m > not sure what the solution is. I think d_real_inode() does not work correctly for all its current users fo= r a metacopy file. I think the solution is to change d_real_inode() to return the data inode and add another helper to get the metadata inode if needed. I will post some patches for it. 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. 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. From the current patch set, I still don't understand what is the expected behavior before and after copy up of data/metadata-only. Thanks, Amir.