Linux Integrity Measurement development
 help / color / mirror / Atom feed
From: "Bruno Meneguele" <bmeneg@redhat.com>
To: "Roberto Sassu" <roberto.sassu@huaweicloud.com>,
	<zohar@linux.ibm.com>, <dmitry.kasatkin@gmail.com>,
	<eric.snowberg@oracle.com>, <paul@paul-moore.com>,
	<jmorris@namei.org>, <serge@hallyn.com>,
	<fabrice.derepas@canonical.com>
Cc: <linux-integrity@vger.kernel.org>,
	<linux-security-module@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	"Roberto Sassu" <roberto.sassu@huawei.com>
Subject: Re: [PATCH v2] ima: Fix out-of-bounds read in ima_read_policy()
Date: Wed, 02 Dec 2026 10:23:27 -0300	[thread overview]
Message-ID: <DNAA2KXTP7QV.CTM6YZ3WHTN4@redhat.com> (raw)
In-Reply-To: <20261202105724.3056284-1-roberto.sassu@huaweicloud.com>

[-- 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 --]

      reply	other threads:[~2026-12-02 13:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DNAA2KXTP7QV.CTM6YZ3WHTN4@redhat.com \
    --to=bmeneg@redhat.com \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=eric.snowberg@oracle.com \
    --cc=fabrice.derepas@canonical.com \
    --cc=jmorris@namei.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=roberto.sassu@huawei.com \
    --cc=roberto.sassu@huaweicloud.com \
    --cc=serge@hallyn.com \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox