From: Sasha Levin <sashal@kernel.org>
To: "Mickaël Salaün" <mic@digikod.net>
Cc: "Günther Noack" <gnoack@google.com>,
"Shuah Khan" <shuah@kernel.org>,
linux-security-module@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] selftests/landlock: fix the regex_escape() error check
Date: Tue, 3 Nov 2026 11:39:17 -0500 [thread overview]
Message-ID: <20261103163917.641130-1-sashal@kernel.org> (raw)
regex_escape() returns (char *)-ENOMEM when the buffer is too small, but
matches_log_fs_extra() checks the returned pointer with "< 0", which is
never true, and goes on with a bogus cursor. On 32-bit architectures gcc
also warns about the cast of the pointer in the error return:
fs_test.c:7474:24: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
Compare against (char *)-ENOMEM instead.
The size left after the escaped path also subtracts the prefix a second
time, which can make a long path fail with -E2BIG. Compute it from the
cursor instead.
Fixes: 316d06b01130 ("selftests/landlock: Add audit tests for filesystem")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
Found with 32-bit builds of the selftests (gcc 16 and clang 21 with
-m32, with and without -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64);
KernelCI's 32-bit arm builds show the same warnings. The changed files
build without them now, and the x86_64 builds don't change.
tools/testing/selftests/landlock/fs_test.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
index f725882fa4a78..27a78434d1c21 100644
--- a/tools/testing/selftests/landlock/fs_test.c
+++ b/tools/testing/selftests/landlock/fs_test.c
@@ -7470,10 +7470,10 @@ static int matches_log_fs_extra(struct __test_metadata *const _metadata,
log_match_cursor = regex_escape(absolute_path, log_match_cursor,
log_match_remaining);
free(absolute_path);
- if (log_match_cursor < 0)
- return (long long)log_match_cursor;
+ if (log_match_cursor == (char *)-ENOMEM)
+ return -ENOMEM;
- log_match_remaining -= log_match_cursor - log_match;
+ log_match_remaining = sizeof(log_match) - (log_match_cursor - log_match);
chunk_len = snprintf(log_match_cursor, log_match_remaining,
"\" dev=\"[^\"]\\+\" ino=[0-9]\\+%s$",
extra ?: "");
--
2.53.0
next reply other threads:[~2026-11-03 16:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 16:39 Sasha Levin [this message]
2026-11-03 20:31 ` Günther Noack
2026-11-03 21:49 ` Sasha Levin
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=20261103163917.641130-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=gnoack@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mic@digikod.net \
--cc=shuah@kernel.org \
/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
all inboxes | Powered by JetHome®