Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Josh Law <objecting@objecting.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Brendan Higgins <brendan.higgins@linux.dev>,
	David Gow <david@davidgow.net>, Rae Moar <raemoar63@gmail.com>,
	linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
	linux-kernel@vger.kernel.org, Josh Law <objecting@objecting.org>
Subject: [PATCH v2 8/8] kunit: validate glob filter patterns before use
Date: Sun, 15 Mar 2026 20:18:16 +0000	[thread overview]
Message-ID: <20260315201816.362559-9-objecting@objecting.org> (raw)
In-Reply-To: <20260315201816.362559-1-objecting@objecting.org>

kunit_parse_glob_filter() accepts user-provided glob patterns via the
filter_glob module parameter but does not check whether they are
well-formed.  A malformed pattern like "suite[.test" (unclosed bracket)
or "suite\" (trailing backslash) is silently passed to glob_match()
which handles it gracefully but not in the way the user likely intended
— the bracket is matched as a literal character rather than starting a
character class.

Use glob_validate() to reject malformed patterns early with -EINVAL,
so users get a clear error instead of silently wrong filter results.

Signed-off-by: Josh Law <objecting@objecting.org>
---
 lib/kunit/executor.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c
index 1fef217de11d..f0cc15e4b34d 100644
--- a/lib/kunit/executor.c
+++ b/lib/kunit/executor.c
@@ -91,6 +91,8 @@ static int kunit_parse_glob_filter(struct kunit_glob_filter *parsed,
 	const char *period = strchr(filter_glob, '.');
 
 	if (!period) {
+		if (!glob_validate(filter_glob))
+			return -EINVAL;
 		parsed->suite_glob = kstrdup(filter_glob, GFP_KERNEL);
 		if (!parsed->suite_glob)
 			return -ENOMEM;
@@ -102,12 +104,23 @@ static int kunit_parse_glob_filter(struct kunit_glob_filter *parsed,
 	if (!parsed->suite_glob)
 		return -ENOMEM;
 
+	if (!glob_validate(parsed->suite_glob)) {
+		kfree(parsed->suite_glob);
+		return -EINVAL;
+	}
+
 	parsed->test_glob = kstrdup(period + 1, GFP_KERNEL);
 	if (!parsed->test_glob) {
 		kfree(parsed->suite_glob);
 		return -ENOMEM;
 	}
 
+	if (!glob_validate(parsed->test_glob)) {
+		kfree(parsed->test_glob);
+		kfree(parsed->suite_glob);
+		return -EINVAL;
+	}
+
 	return 0;
 }
 
-- 
2.34.1


      parent reply	other threads:[~2026-03-15 20:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-15 20:18 [PATCH v2 0/8] lib/glob: bug fixes, new features, and tests Josh Law
2026-03-15 20:18 ` [PATCH v2 1/8] lib/glob: normalize inverted character class ranges Josh Law
2026-03-15 20:18 ` [PATCH v2 2/8] lib/glob: treat trailing backslash as literal character Josh Law
2026-03-15 20:18 ` [PATCH v2 3/8] lib/glob: accept [^...] as character class negation syntax Josh Law
2026-03-15 20:18 ` [PATCH v2 4/8] lib/glob: add case-insensitive glob_match_nocase() Josh Law
2026-03-15 20:18 ` [PATCH v2 5/8] lib/glob: add glob_validate() for pattern syntax checking Josh Law
2026-03-15 20:18 ` [PATCH v2 6/8] lib/tests: add glob test cases for escapes, edge cases, and new features Josh Law
2026-03-15 20:18 ` [PATCH v2 7/8] lib/tests: add kunit tests for glob_match_nocase() and glob_validate() Josh Law
2026-03-15 20:18 ` Josh Law [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=20260315201816.362559-9-objecting@objecting.org \
    --to=objecting@objecting.org \
    --cc=akpm@linux-foundation.org \
    --cc=brendan.higgins@linux.dev \
    --cc=david@davidgow.net \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=raemoar63@gmail.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