[PATCH v2] ima: Fix out-of-bounds read in ima_read_policy()

From: Roberto Sassu

Date: Wed Dec 02 2026 - 05:58:07 EST


From: Roberto Sassu <roberto.sassu@xxxxxxxxxx>

ima_read_policy() reads the policy file with kernel_read_file_from_path()
and splits it into rules with strsep(). However, the buffer allocated by
kernel_read_file_from_path() is exactly the size of the file and is not
NUL-terminated. If the policy file does not end with a newline, strsep()
scans past the end of the buffer while looking for the next separator. If
the file size is a multiple of PAGE_SIZE, the scan reaches the vmalloc
guard page and the kernel oopses.

To avoid the problem, reject the read policy if does not end with a newline
or the NUL terminator.

Fixes: 7429b092811f ("ima: load policy using path")
Reported-by: Fabrice Derepas <fabrice.derepas@xxxxxxxxxxxxx>
Closes: https://lore.kernel.org/linux-integrity/20260814085443.1211989-1-fabrice.derepas@xxxxxxxxxxxxx/
Suggested-by: Mimi Zohar <zohar@xxxxxxxxxxxxx>
Signed-off-by: Roberto Sassu <roberto.sassu@xxxxxxxxxx>
---
security/integrity/ima/ima_fs.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
index 2a0bca554316..872b2c31ca02 100644
--- a/security/integrity/ima/ima_fs.c
+++ b/security/integrity/ima/ima_fs.c
@@ -548,6 +548,12 @@ static ssize_t ima_read_policy(char *path)
rc = 0;

datap = data;
+
+ if (size && datap[size - 1] != '\n' && datap[size - 1] != '\0') {
+ vfree(data);
+ return -EINVAL;
+ }
+
while (size > 0 && (p = strsep(&datap, "\n"))) {
pr_debug("rule: %s\n", p);
rc = ima_parse_add_rule(p);
--
2.43.0