All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: linux-security-module@vger.kernel.org
Subject: Re: [PATCH 14/27] selftests/landlock: Make audit_message large enough for any exe filter
Date: Thu, 08 Oct 2026 14:40:54 +0000	[thread overview]
Message-ID: <sashiko-outbox-164316@kernel.org> (raw)
In-Reply-To: <20261008142604.39107-16-gnoack3000@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] selftests/landlock: OOB read in regexec due to missing null terminator
--

commit fcf4b6b95bf6821e426c4d029e2300800d7024cd
Author: Günther Noack <gnoack3000@gmail.com>

selftests/landlock: Make audit_message large enough for any exe filter

This commit increases the size of the data array in struct audit_message to
accommodate a full audit_rule_data structure and a PATH_MAX string. It also
adds a bounds check in audit_filter_exe() to return -E2BIG if the request
size exceeds the new message buffer size.

> diff --git a/tools/testing/selftests/landlock/audit.h b/tools/testing/selftests/landlock/audit.h
> --- a/tools/testing/selftests/landlock/audit.h
> +++ b/tools/testing/selftests/landlock/audit.h
> @@ -41,7 +41,11 @@ struct audit_message {
>  		struct audit_features features;
>  		struct audit_rule_data rule;
>  		struct nlmsgerr err;
> -		char data[PATH_MAX + 200];
> +		/*
> +		 * Large enough for an audit_rule_data followed by a PATH_MAX
> +		 * string (see audit_filter_exe()), and for received records.
> +		 */
> +		char data[sizeof(struct audit_rule_data) + PATH_MAX];

[Severity: Medium]
Could this lead to an out-of-bounds read during a selftest run?

The buffer size was increased here, but there is no explicit space reserved
for, or assignment of, a null terminator.

If kauditd sends an audit message equal to or larger than sizeof(*msg) (for
example, if the executable path is extremely long and hex-encoded), the
recvfrom() call in audit_recv() will truncate it and read exactly that many
bytes:

tools/testing/selftests/landlock/audit.h:audit_recv() {
    ...
    err = recvfrom(fd, msg, sizeof(*msg), 0,
                   (struct sockaddr *)&addr, &addrlen);
    ...
}

Because the raw payload lacks a null terminator and fills the buffer entirely,
msg.data will not be null-terminated. Later, regexec() in
audit_match_record() assumes msg.data is a valid C string:

tools/testing/selftests/landlock/audit.h:audit_match_record() {
    ...
    ret = regexec(&regex, msg.data, ARRAY_SIZE(matches), matches, 0);
    ...
}

Since regexec() expects a null-terminated string, passing the completely
filled buffer could result in an out-of-bounds read on the stack,
potentially crashing the test. Should we ensure the received payload is
null-terminated, or perhaps reserve an extra byte for it in the buffer?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261008142604.39107-2-gnoack3000@gmail.com?part=14

  reply	other threads:[~2026-10-08 14:40 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-08 14:25 [PATCH 00/27] landlock: Selftest fixes and cleanups Günther Noack
2026-10-08 14:25 ` [PATCH 01/27] selftests/landlock: Propagate grandchild failures in unix_scoping Günther Noack
2026-10-08 14:33   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 02/27] selftests/landlock: Propagate EXPECT failures from forked children Günther Noack
2026-10-08 14:35   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 03/27] selftests/landlock: Check the thread result in audit.thread Günther Noack
2026-10-08 14:32   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 04/27] selftests/landlock: Zero-initialize the buffer in inconsistent_attr Günther Noack
2026-10-08 14:33   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 05/27] selftests/landlock: Fix the openat() success check in fs_bench Günther Noack
2026-10-08 14:33   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 06/27] selftests/landlock: Fix the reported clock tick rate " Günther Noack
2026-10-08 14:33   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 07/27] selftests/landlock: Fix the ruleset_fd check in empty_or_same_ruleset Günther Noack
2026-10-08 14:35   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 08/27] selftests/landlock: Handle a missing control message in recv_fd() Günther Noack
2026-10-08 14:31   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 09/27] selftests/landlock: Assert tracefs_extract_field() results that are used Günther Noack
2026-10-08 14:33   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 10/27] selftests/landlock: Assert audit initialization in fixture setups Günther Noack
2026-10-08 14:44   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 11/27] selftests/landlock: Assert helper results that are used afterwards Günther Noack
2026-10-08 14:35   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 12/27] selftests/landlock: Assert audit_count_records() before using its result Günther Noack
2026-10-08 14:35   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 13/27] selftests/landlock: Fix memory leak in audit_init_filter_exe() Günther Noack
2026-10-08 14:35   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 14/27] selftests/landlock: Make audit_message large enough for any exe filter Günther Noack
2026-10-08 14:40   ` sashiko-bot [this message]
2026-10-08 14:25 ` [PATCH 15/27] selftests/landlock: Close leaked file descriptors Günther Noack
2026-10-08 14:32   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 16/27] selftests/landlock: Check errno for combined VERSION and ERRATA flags Günther Noack
2026-10-08 14:32   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 17/27] selftests/landlock: Fix SIGURG handler setup in scoped_signal_test Günther Noack
2026-10-08 14:32   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 18/27] selftests/landlock: Fix regex_escape() error handling in matches_log_fs_extra() Günther Noack
2026-10-08 14:36   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 19/27] selftests/landlock: Fix off-by-one in regex_escape() Günther Noack
2026-10-08 14:36   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 20/27] selftests/landlock: Fix the snprintf() error check in matches_log_fs_extra() Günther Noack
2026-10-08 14:34   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 21/27] selftests/landlock: Use _exit() in the named_pipe_ioctl child Günther Noack
2026-10-08 14:33   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 22/27] selftests/landlock: Fix messages and comments in helper programs Günther Noack
2026-10-08 14:33   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 23/27] selftests/landlock: Fix stale comments in common.h and audit.h Günther Noack
2026-10-08 14:33   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 24/27] selftests/landlock: Use ASSERT for syscall failures before errno checks Günther Noack
2026-10-08 14:41   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 25/27] selftests/landlock: Assert WIFEXITED() before checking the exit status Günther Noack
2026-10-08 14:38   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 26/27] selftests/landlock: Use EXPECT for closing FDs and stopping threads Günther Noack
2026-10-08 14:40   ` sashiko-bot
2026-10-08 14:25 ` [PATCH 27/27] selftests/landlock: Use EXPECT for checks that later steps do not need Günther Noack
2026-10-08 14:39   ` sashiko-bot
2026-10-08 14:33 ` [PATCH 00/27] landlock: Selftest fixes and cleanups Günther Noack

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=sashiko-outbox-164316@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.