Skip to content

Commit 0496fc9

Browse files
robertosassumimizohar
authored andcommitted
evm: Use ordered xattrs list to calculate HMAC in evm_init_hmac()
Commit 8e5d9f9 ("smack: deduplicate xattr setting in smack_inode_init_security()") introduced xattr_dupval() to simplify setting the xattrs to be provided by the SMACK LSM on inode creation, in the smack_inode_init_security(). Unfortunately, moving lsm_get_xattr_slot() caused the SMACK64TRANSMUTE xattr be added in the array of new xattrs before SMACK64. This causes the HMAC of xattrs calculated by evm_init_hmac() for new files to diverge from the one calculated by both evm_calc_hmac_or_hash() and evmctl. evm_init_hmac() calculates the HMAC of the xattrs of new files based on the order LSMs provide them, while evm_calc_hmac_or_hash() and evmctl calculate the HMAC based on an ordered xattrs list. Fix the issue by making evm_init_hmac() calculate the HMAC of new files based on the ordered xattrs list too. Fixes: 8e5d9f9 ("smack: deduplicate xattr setting in smack_inode_init_security()") Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent 377cae9 commit 0496fc9

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

security/integrity/evm/evm_crypto.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,18 +401,24 @@ int evm_init_hmac(struct inode *inode, const struct xattr *xattrs,
401401
{
402402
struct shash_desc *desc;
403403
const struct xattr *xattr;
404+
struct xattr_list *xattr_entry;
404405

405406
desc = init_desc(EVM_XATTR_HMAC, HASH_ALGO_SHA1);
406407
if (IS_ERR(desc)) {
407408
pr_info("init_desc failed\n");
408409
return PTR_ERR(desc);
409410
}
410411

411-
for (xattr = xattrs; xattr->name; xattr++) {
412-
if (!evm_protected_xattr(xattr->name))
413-
continue;
412+
list_for_each_entry_lockless(xattr_entry, &evm_config_xattrnames,
413+
list) {
414+
for (xattr = xattrs; xattr->name; xattr++) {
415+
if (strcmp(xattr_entry->name +
416+
XATTR_SECURITY_PREFIX_LEN, xattr->name) != 0)
417+
continue;
414418

415-
crypto_shash_update(desc, xattr->value, xattr->value_len);
419+
crypto_shash_update(desc, xattr->value,
420+
xattr->value_len);
421+
}
416422
}
417423

418424
hmac_add_misc(desc, inode, EVM_XATTR_HMAC, hmac_val);

0 commit comments

Comments
 (0)