linux/security/integrity/ima
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
..
ima.h ima: Avoid blocking in RCU read-side critical section 2024-07-18 13:07:34 +02:00
ima_api.c ima: Fix use-after-free on a dentry's dname.name 2024-12-14 19:51:45 +01:00
ima_appraise.c ima: fix out-of-bounds read in xattr_verify() 2026-08-19 17:14:15 +02:00
ima_asymmetric_keys.c ima: Add digest and digest_len params to the functions to measure a buffer 2021-07-23 09:27:02 -04:00
ima_crypto.c ima: check return value of crypto_shash_final() in boot aggregate 2026-06-01 17:35:34 +02:00
ima_efi.c ima: force signature verification when CONFIG_KEXEC_SIG is configured 2022-07-21 21:24:29 +02:00
ima_fs.c ima: Remove ima_policy file before directory 2022-02-16 12:56:03 +01:00
ima_init.c ima: Add digest and digest_len params to the functions to measure a buffer 2021-07-23 09:27:02 -04:00
ima_kexec.c of: kexec: Mark ima_{free,stable}_kexec_buffer() as __init 2023-09-19 12:22:30 +02:00
ima_main.c ima: detect changes to the backing overlay file 2023-11-28 16:56:29 +00:00
ima_modsig.c ima: Fix build warnings 2023-07-23 13:46:48 +02:00
ima_mok.c IMA: remove -Wmissing-prototypes warning 2021-07-23 08:05:06 -04:00
ima_policy.c ima: Handle error code returned by ima_filter_rule_match() 2026-01-19 13:09:31 +01:00
ima_queue.c IMA: support for duplicate measurement records 2021-06-11 12:54:13 -04:00
ima_queue_keys.c ima: Add digest and digest_len params to the functions to measure a buffer 2021-07-23 09:27:02 -04:00
ima_template.c ima: Fix a potential NULL pointer access in ima_restore_measurement_list 2023-01-12 11:58:57 +01:00
ima_template_lib.c ima: Fix use-after-free on a dentry's dname.name 2024-12-14 19:51:45 +01:00
ima_template_lib.h ima: Define new template fields xattrnames, xattrlengths and xattrvalues 2021-06-02 18:56:13 -04:00
Kconfig ima: rework CONFIG_IMA dependency block 2023-10-10 21:59:07 +02:00
Makefile ima: generalize x86/EFI arch glue for other EFI architectures 2020-11-06 07:40:42 +01:00