Skip to content

Commit 650b29d

Browse files
bauermannmimizohar
authored andcommitted
integrity: Introduce struct evm_xattr
Even though struct evm_ima_xattr_data includes a fixed-size array to hold a SHA1 digest, most of the code ignores the array and uses the struct to mean "type indicator followed by data of unspecified size" and tracks the real size of what the struct represents in a separate length variable. The only exception to that is the EVM code, which correctly uses the definition of struct evm_ima_xattr_data. So make this explicit in the code by removing the length specification from the array in struct evm_ima_xattr_data. Also, change the name of the element from digest to data since in most places the array doesn't hold a digest. A separate struct evm_xattr is introduced, with the original definition of evm_ima_xattr_data to be used in the places that actually expect that definition, specifically the EVM HMAC code. Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent 337619e commit 650b29d

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

‎security/integrity/evm/evm_main.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry,
169169
/* check value type */
170170
switch (xattr_data->type) {
171171
case EVM_XATTR_HMAC:
172-
if (xattr_len != sizeof(struct evm_ima_xattr_data)) {
172+
if (xattr_len != sizeof(struct evm_xattr)) {
173173
evm_status = INTEGRITY_FAIL;
174174
goto out;
175175
}
@@ -179,7 +179,7 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry,
179179
xattr_value_len, &digest);
180180
if (rc)
181181
break;
182-
rc = crypto_memneq(xattr_data->digest, digest.digest,
182+
rc = crypto_memneq(xattr_data->data, digest.digest,
183183
SHA1_DIGEST_SIZE);
184184
if (rc)
185185
rc = -EINVAL;
@@ -523,7 +523,7 @@ int evm_inode_init_security(struct inode *inode,
523523
const struct xattr *lsm_xattr,
524524
struct xattr *evm_xattr)
525525
{
526-
struct evm_ima_xattr_data *xattr_data;
526+
struct evm_xattr *xattr_data;
527527
int rc;
528528

529529
if (!evm_key_loaded() || !evm_protected_xattr(lsm_xattr->name))
@@ -533,7 +533,7 @@ int evm_inode_init_security(struct inode *inode,
533533
if (!xattr_data)
534534
return -ENOMEM;
535535

536-
xattr_data->type = EVM_XATTR_HMAC;
536+
xattr_data->data.type = EVM_XATTR_HMAC;
537537
rc = evm_init_hmac(inode, lsm_xattr, xattr_data->digest);
538538
if (rc < 0)
539539
goto out;

‎security/integrity/ima/ima_appraise.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,16 @@ enum hash_algo ima_get_hash_algo(struct evm_ima_xattr_data *xattr_value,
168168
return sig->hash_algo;
169169
break;
170170
case IMA_XATTR_DIGEST_NG:
171-
ret = xattr_value->digest[0];
171+
/* first byte contains algorithm id */
172+
ret = xattr_value->data[0];
172173
if (ret < HASH_ALGO__LAST)
173174
return ret;
174175
break;
175176
case IMA_XATTR_DIGEST:
176177
/* this is for backward compatibility */
177178
if (xattr_len == 21) {
178179
unsigned int zero = 0;
179-
if (!memcmp(&xattr_value->digest[16], &zero, 4))
180+
if (!memcmp(&xattr_value->data[16], &zero, 4))
180181
return HASH_ALGO_MD5;
181182
else
182183
return HASH_ALGO_SHA1;
@@ -275,7 +276,7 @@ int ima_appraise_measurement(enum ima_hooks func,
275276
/* xattr length may be longer. md5 hash in previous
276277
version occupied 20 bytes in xattr, instead of 16
277278
*/
278-
rc = memcmp(&xattr_value->digest[hash_start],
279+
rc = memcmp(&xattr_value->data[hash_start],
279280
iint->ima_hash->digest,
280281
iint->ima_hash->length);
281282
else

‎security/integrity/integrity.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ enum evm_ima_xattr_type {
7979

8080
struct evm_ima_xattr_data {
8181
u8 type;
82+
u8 data[];
83+
} __packed;
84+
85+
/* Only used in the EVM HMAC code. */
86+
struct evm_xattr {
87+
struct evm_ima_xattr_data data;
8288
u8 digest[SHA1_DIGEST_SIZE];
8389
} __packed;
8490

0 commit comments

Comments
 (0)