evm: Use the metadata inode to calculate metadata hash
authorStefan Berger <stefanb@linux.ibm.com>
Fri, 23 Feb 2024 17:25:07 +0000 (12:25 -0500)
committerMimi Zohar <zohar@linux.ibm.com>
Tue, 9 Apr 2024 21:14:57 +0000 (17:14 -0400)
Changes to file attributes (mode bits, uid, gid) on the lower layer are
not taken 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 in this case
holds wrong file attributes. Further, when CONFIG_OVERLAY_FS_METACOPY is
enabled and a copy-up is triggered due to file metadata changes, then
the metadata are held by the backing inode while the data are still held
by the real inode. Therefore, use d_inode(d_real(dentry, D_REAL_METADATA))
to get to the file's metadata inode and use it to calculate the metadata
hash with.

Co-developed-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Acked-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
security/integrity/evm/evm_crypto.c

index 7552d49d07258f8958a7d702b7cbc21d2439d2bc..35416f55391c0c2c30d83ce70b2e4f02cf81e351 100644 (file)
@@ -223,7 +223,7 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
                                 size_t req_xattr_value_len,
                                 uint8_t type, struct evm_digest *data)
 {
-       struct inode *inode = d_backing_inode(dentry);
+       struct inode *inode = d_inode(d_real(dentry, D_REAL_METADATA));
        struct xattr_list *xattr;
        struct shash_desc *desc;
        size_t xattr_size = 0;