Skip to content

Commit 907a399

Browse files
robertosassumimizohar
authored andcommitted
evm: Check xattr size discrepancy between kernel and user
The kernel and the user obtain an xattr value in two different ways: kernel (EVM): uses vfs_getxattr_alloc() which obtains the xattr value from the filesystem handler (raw value); user (ima-evm-utils): uses vfs_getxattr() which obtains the xattr value from the LSMs (normalized value). Normally, this does not have an impact unless security.selinux is set with setfattr, with a value not terminated by '\0' (this is not the recommended way, security.selinux should be set with the appropriate tools such as chcon and restorecon). In this case, the kernel and the user see two different xattr values: the former sees the xattr value without '\0' (raw value), the latter sees the value with '\0' (value normalized by SELinux). This could result in two different verification outcomes from EVM and ima-evm-utils, if a signature was calculated with a security.selinux value terminated by '\0' and the value set in the filesystem is not terminated by '\0'. The former would report verification failure due to the missing '\0', while the latter would report verification success (because it gets the normalized value with '\0'). This patch mitigates this issue by comparing in evm_calc_hmac_or_hash() the size of the xattr returned by the two xattr functions and by warning the user if there is a discrepancy. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Suggested-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent 87ac3d0 commit 907a399

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

security/integrity/evm/evm_crypto.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
222222
size_t xattr_size = 0;
223223
char *xattr_value = NULL;
224224
int error;
225-
int size;
225+
int size, user_space_size;
226226
bool ima_present = false;
227227

228228
if (!(inode->i_opflags & IOP_XATTR) ||
@@ -277,6 +277,12 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
277277
if (size < 0)
278278
continue;
279279

280+
user_space_size = vfs_getxattr(&init_user_ns, dentry,
281+
xattr->name, NULL, 0);
282+
if (user_space_size != size)
283+
pr_debug("file %s: xattr %s size mismatch (kernel: %d, user: %d)\n",
284+
dentry->d_name.name, xattr->name, size,
285+
user_space_size);
280286
error = 0;
281287
xattr_size = size;
282288
crypto_shash_update(desc, (const u8 *)xattr_value, xattr_size);

0 commit comments

Comments
 (0)