Skip to content

Commit 93db202

Browse files
committed
Merge tag 'integrity-v6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity
Pull integrity fixes from Mimi Zohar: "One bug fix, one performance improvement, and the use of static_assert: - The bug fix addresses "only a cosmetic change" commit, which didn't take into account the original 'ima' template definition. - The performance improvement limits the atomic_read()" * tag 'integrity-v6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity: integrity: Use static_assert() to check struct sizes evm: stop avoidably reading i_writecount in evm_file_release ima: fix buffer overrun in ima_eventdigest_init_common
2 parents 92dda32 + 08ae3e5 commit 93db202

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

security/integrity/evm/evm_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,8 @@ static void evm_file_release(struct file *file)
10841084
if (!S_ISREG(inode->i_mode) || !(mode & FMODE_WRITE))
10851085
return;
10861086

1087-
if (iint && atomic_read(&inode->i_writecount) == 1)
1087+
if (iint && iint->flags & EVM_NEW_FILE &&
1088+
atomic_read(&inode->i_writecount) == 1)
10881089
iint->flags &= ~EVM_NEW_FILE;
10891090
}
10901091

security/integrity/ima/ima_template_lib.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,21 @@ static int ima_eventdigest_init_common(const u8 *digest, u32 digestsize,
318318
hash_algo_name[hash_algo]);
319319
}
320320

321-
if (digest)
321+
if (digest) {
322322
memcpy(buffer + offset, digest, digestsize);
323-
else
323+
} else {
324324
/*
325325
* If digest is NULL, the event being recorded is a violation.
326326
* Make room for the digest by increasing the offset by the
327-
* hash algorithm digest size.
327+
* hash algorithm digest size. If the hash algorithm is not
328+
* specified increase the offset by IMA_DIGEST_SIZE which
329+
* fits SHA1 or MD5
328330
*/
329-
offset += hash_digest_size[hash_algo];
331+
if (hash_algo < HASH_ALGO__LAST)
332+
offset += hash_digest_size[hash_algo];
333+
else
334+
offset += IMA_DIGEST_SIZE;
335+
}
330336

331337
return ima_write_template_field_data(buffer, offset + digestsize,
332338
fmt, field_data);

security/integrity/integrity.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ struct evm_ima_xattr_data {
3737
);
3838
u8 data[];
3939
} __packed;
40+
static_assert(offsetof(struct evm_ima_xattr_data, data) == sizeof(struct evm_ima_xattr_data_hdr),
41+
"struct member likely outside of __struct_group()");
4042

4143
/* Only used in the EVM HMAC code. */
4244
struct evm_xattr {
@@ -65,6 +67,8 @@ struct ima_digest_data {
6567
);
6668
u8 digest[];
6769
} __packed;
70+
static_assert(offsetof(struct ima_digest_data, digest) == sizeof(struct ima_digest_data_hdr),
71+
"struct member likely outside of __struct_group()");
6872

6973
/*
7074
* Instead of wrapping the ima_digest_data struct inside a local structure

0 commit comments

Comments
 (0)