From: "Christian Göttsche" <cgzones@googlemail.com>
To: selinux@vger.kernel.org
Subject: [RFC PATCH] libselinux: disable capturing in fcontext matching
Date: Mon, 8 Jan 2024 13:00:29 +0100 [thread overview]
Message-ID: <20240108120029.38816-1-cgzones@googlemail.com> (raw)
The path of a file context definition is compared as a regular
expression against actual pathnames. Those definitions make frequently
use of groups, like `(/.*)?`, which are capturing by default, causing
the regex engine to extract and save the matched input. Matching
context definitions against pathnames only cares about whether it's a
match or not, potential captures are never accessed.
Compile regular expressions (in the default PCRE2 variant) with the flag
PCRE2_NO_AUTO_CAPTURE to turn captured groups automatically into non
captured ones, like `(/.*)?` into `(?:/.*)?`. This saves some cycles
during lookup operations (~1.5%).
Only potential regression would be the advanced usage of backreferences
or recursion/subroutine calls to numbered captures, which would need an
update to use named captures instead.
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
libselinux/src/regex.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libselinux/src/regex.c b/libselinux/src/regex.c
index 88d82fed..87423c48 100644
--- a/libselinux/src/regex.c
+++ b/libselinux/src/regex.c
@@ -80,7 +80,7 @@ int regex_prepare_data(struct regex_data **regex, char const *pattern_string,
return -1;
(*regex)->regex = pcre2_compile(
- (PCRE2_SPTR)pattern_string, PCRE2_ZERO_TERMINATED, PCRE2_DOTALL,
+ (PCRE2_SPTR)pattern_string, PCRE2_ZERO_TERMINATED, PCRE2_DOTALL | PCRE2_NO_AUTO_CAPTURE,
&errordata->error_code, &errordata->error_offset, NULL);
if (!(*regex)->regex) {
goto err;
--
2.43.0
next reply other threads:[~2024-01-08 12:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-08 12:00 Christian Göttsche [this message]
2024-02-05 19:07 ` [RFC PATCH] libselinux: disable capturing in fcontext matching James Carter
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=20240108120029.38816-1-cgzones@googlemail.com \
--to=cgzones@googlemail.com \
--cc=selinux@vger.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).