linux/security/integrity
Lincoln Wallace caeb105c15 ima: fix out-of-bounds read in xattr_verify()
commit 5ff232d311 upstream.

The digest-length check in xattr_verify() mixes int and size_t:

	if (xattr_len - sizeof(xattr_value->type) - hash_start >=
			iint->ima_hash->length)

sizeof() yields size_t, so the usual arithmetic conversions promote
the whole left-hand side to unsigned 64-bit before the subtraction
runs. For a truncated xattr this underflows instead of going negative:
a 1-byte IMA_XATTR_DIGEST_NG xattr (xattr_len == 1, hash_start == 1)
turns "1 - 1 - 1" into SIZE_MAX, which is trivially >= ima_hash->length.
The check then passes and the following memcmp() reads
iint->ima_hash->length bytes starting past the end of the buffer
vfs_getxattr_alloc() allocated for it.

Nothing upstream clamps xattr_len back into a safe range first:
ima_get_hash_algo() only special-cases xattr_len < 2 to pick a default
algorithm, and evm_verifyxattr() returns INTEGRITY_UNKNOWN rather than
failing when no HMAC key is loaded, so a truncated security.ima value
reaches the length check as-is.

Rewrite the comparison so every operand stays a signed int and no
implicit conversion to size_t can occur.

Fixes: 3ea7a56067 ("ima: provide hash algo info in the xattr")
Cc: stable@vger.kernel.org
Signed-off-by: Lincoln Wallace <locnnil0@gmail.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-08-19 17:14:15 +02:00
..
evm evm: terminate and bound the evm_xattrs read buffer 2026-07-24 15:51:28 +02:00
ima ima: fix out-of-bounds read in xattr_verify() 2026-08-19 17:14:15 +02:00
platform_certs efi: Add iMac Pro 2017 to uefi skip cert quirk 2023-01-12 11:58:56 +01:00
digsig.c integrity: Fix memory leakage in keyring allocation error path 2022-12-31 13:14:10 +01:00
digsig_asymmetric.c ima: fix reference leak in asymmetric_verify() 2022-02-16 12:56:03 +01:00
iint.c ima: annotate iint mutex to avoid lockdep false positive warnings 2023-11-28 16:56:29 +00:00
integrity.h ima: detect changes to the backing overlay file 2023-11-28 16:56:29 +00:00
integrity_audit.c integrity: check the return value of audit_log_start() 2022-02-16 12:56:03 +01:00
Kconfig powerpc: Load firmware trusted keys/hashes into kernel keyring 2019-11-13 00:33:23 +11:00
Makefile powerpc: Load firmware trusted keys/hashes into kernel keyring 2019-11-13 00:33:23 +11:00