* [PATCH v2] ima: Fix out-of-bounds read in ima_read_policy()
@ 2026-12-02 10:57 Roberto Sassu
2026-12-02 13:23 ` Bruno Meneguele
0 siblings, 1 reply; 4+ messages in thread
From: Roberto Sassu @ 2026-12-02 10:57 UTC (permalink / raw)
To: zohar, dmitry.kasatkin, eric.snowberg, paul, jmorris, serge,
fabrice.derepas
Cc: linux-integrity, linux-security-module, linux-kernel,
Roberto Sassu
From: Roberto Sassu <roberto.sassu@huawei.com>
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@canonical.com>
Closes: https://lore.kernel.org/linux-integrity/20260814085443.1211989-1-fabrice.derepas@canonical.com/
Suggested-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ima: Fix out-of-bounds read in ima_read_policy()
2026-12-02 10:57 [PATCH v2] ima: Fix out-of-bounds read in ima_read_policy() Roberto Sassu
@ 2026-12-02 13:23 ` Bruno Meneguele
2026-12-02 20:15 ` Mimi Zohar
0 siblings, 1 reply; 4+ messages in thread
From: Bruno Meneguele @ 2026-12-02 13:23 UTC (permalink / raw)
To: Roberto Sassu, zohar, dmitry.kasatkin, eric.snowberg, paul,
jmorris, serge, fabrice.derepas
Cc: linux-integrity, linux-security-module, linux-kernel,
Roberto Sassu
[-- Attachment #1: Type: text/plain, Size: 1993 bytes --]
On Wed Dec 2, 2026 at 7:57 AM -03, Roberto Sassu wrote:
> From: Roberto Sassu <roberto.sassu@huawei.com>
>
> 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@canonical.com>
> Closes: https://lore.kernel.org/linux-integrity/20260814085443.1211989-1-fabrice.derepas@canonical.com/
> Suggested-by: Mimi Zohar <zohar@linux.ibm.com>
> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
> ---
> 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);
May I suggest an addition to [1] about it? That's literally an invisible failure
the user won't find out the reason easily.
[1] https://github.com/linux-integrity/ima-doc
Acked-by: Bruno Meneguele <bmeneg@redhat.com>
--
Bruno Meneguele
PGP Key: http://bmeneg.com/pubkey.txt
[-- Attachment #2: Type: application/pgp-signature, Size: 556 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ima: Fix out-of-bounds read in ima_read_policy()
2026-12-02 13:23 ` Bruno Meneguele
@ 2026-12-02 20:15 ` Mimi Zohar
2026-12-03 15:26 ` Bruno Meneguele
0 siblings, 1 reply; 4+ messages in thread
From: Mimi Zohar @ 2026-12-02 20:15 UTC (permalink / raw)
To: Bruno Meneguele, Roberto Sassu, dmitry.kasatkin, eric.snowberg,
paul, jmorris, serge, fabrice.derepas, Kenneth Goldman
Cc: linux-integrity, linux-security-module, linux-kernel,
Roberto Sassu
On Wed, 2026-12-02 at 10:23 -0300, Bruno Meneguele wrote:
> On Wed Dec 2, 2026 at 7:57 AM -03, Roberto Sassu wrote:
> > From: Roberto Sassu <roberto.sassu@huawei.com>
> >
> > 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@canonical.com>
> > Closes: https://lore.kernel.org/linux-integrity/20260814085443.1211989-1-fabrice.derepas@canonical.com/
> > Suggested-by: Mimi Zohar <zohar@linux.ibm.com>
> > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
> > ---
> > 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);
>
> May I suggest an addition to [1] about it? That's literally an invisible failure
> the user won't find out the reason easily.
>
> [1] https://github.com/linux-integrity/ima-doc
Thanks, Bruno.
Agreed, ima-docs should be updated. It belongs as the last sentence of the
initial custom policy paragraph[1].
[1] https://ima-doc.readthedocs.io/en/latest/ima-policy.html#custom-policy
>
>
> Acked-by: Bruno Meneguele <bmeneg@redhat.com>
As per the relatively new "Acked-by" usage, let's append a comment like the one
described below (e.g. As primary user, userspace pkg maintainer, etc).
From submitting-patches documentation:
Acked-by: may also be used by other stakeholders, such as people with domain
knowledge (e.g. the original author of the code being modified), userspace-
side reviewers for a kernel uAPI patch or key users of a feature. Optionally,
in these cases, it can be useful to add a “# Suffix” to clarify its meaning:
Acked-by: The Stakeholder <stakeholder@example.org> # As primary user
thanks,
Mimi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ima: Fix out-of-bounds read in ima_read_policy()
2026-12-02 20:15 ` Mimi Zohar
@ 2026-12-03 15:26 ` Bruno Meneguele
0 siblings, 0 replies; 4+ messages in thread
From: Bruno Meneguele @ 2026-12-03 15:26 UTC (permalink / raw)
To: Mimi Zohar, Roberto Sassu, dmitry.kasatkin, eric.snowberg, paul,
jmorris, serge, fabrice.derepas, Kenneth Goldman
Cc: linux-integrity, linux-security-module, linux-kernel,
Roberto Sassu
[-- Attachment #1: Type: text/plain, Size: 3266 bytes --]
On Wed Dec 2, 2026 at 5:15 PM -03, Mimi Zohar wrote:
> On Wed, 2026-12-02 at 10:23 -0300, Bruno Meneguele wrote:
>> On Wed Dec 2, 2026 at 7:57 AM -03, Roberto Sassu wrote:
>> > From: Roberto Sassu <roberto.sassu@huawei.com>
>> >
>> > 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@canonical.com>
>> > Closes: https://lore.kernel.org/linux-integrity/20260814085443.1211989-1-fabrice.derepas@canonical.com/
>> > Suggested-by: Mimi Zohar <zohar@linux.ibm.com>
>> > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
>> > ---
>> > 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);
>>
>> May I suggest an addition to [1] about it? That's literally an invisible failure
>> the user won't find out the reason easily.
>>
>> [1] https://github.com/linux-integrity/ima-doc
>
> Thanks, Bruno.
>
> Agreed, ima-docs should be updated. It belongs as the last sentence of the
> initial custom policy paragraph[1].
>
> [1] https://ima-doc.readthedocs.io/en/latest/ima-policy.html#custom-policy
Yes. It fits nicely there.
Thanks Mimi.
>>
>>
>> Acked-by: Bruno Meneguele <bmeneg@redhat.com>
>
> As per the relatively new "Acked-by" usage, let's append a comment like the one
> described below (e.g. As primary user, userspace pkg maintainer, etc).
>
> From submitting-patches documentation:
> Acked-by: may also be used by other stakeholders, such as people with domain
> knowledge (e.g. the original author of the code being modified), userspace-
> side reviewers for a kernel uAPI patch or key users of a feature. Optionally,
> in these cases, it can be useful to add a “# Suffix” to clarify its meaning:
>
> Acked-by: The Stakeholder <stakeholder@example.org> # As primary user
Oh, sure thing. Thanks for the heads-up and pointer.
Acked-by: Bruno Meneguele <bmeneg@redhat.com> # As primary user
--
Bruno Meneguele
PGP Key: http://bmeneg.com/pubkey.txt
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 512 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-03 15:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 10:57 [PATCH v2] ima: Fix out-of-bounds read in ima_read_policy() Roberto Sassu
2026-12-02 13:23 ` Bruno Meneguele
2026-12-02 20:15 ` Mimi Zohar
2026-12-03 15:26 ` Bruno Meneguele
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox