Skip to contentSkip to conversation

lib: parser: Fix match_wildcard to correctly handle trailing stars

PATCH Applied Inseob Kim 4 participants 8 messages Mar 26 – Mar 27 Library code

lore
Share & tools
lore

Inseob Kim

author
#0 lore raw

PATCH v2 1/1 lib: parser: Fix match_wildcard to correctly handle trailing stars

This fixes a bug of match_wildcard that incorrectly handles trailing asterisks. For example, match_wildcard("abc**", "abc") must return true, but it returns false.

---
v2:
- Added Cc. No changes to the code.

---
 lib/parser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/parser.c +1 -1
index 73e8f8e5be73..62da0ac0d438 100644
@@ -315,7 +315,7 @@ bool match_wildcard(const char *pattern, const char *str)
 		}
 	}
 
-	if (*p == '*')
+	while (*p == '*')
 		++p;
 	return !*p;
 }
Signature · 1 line
2.53.0.1018.g2bb0e51243-goog
maintainer
#1 lore raw
Quoted 17 lines · On Thu, 26 Mar 2026 11:06:04 +0900 Inseob Kim <[email protected]> wrote:

This fixes a bug of match_wildcard that incorrectly handles trailing asterisks. For example, match_wildcard("abc**", "abc") must return true, but it returns false.

---
v2:
- Added Cc. No changes to the code.

---
 lib/parser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/parser.c +0 -0
index 73e8f8e5be73..62da0ac0d438 100644

lib/parser.c bool match_wildcard(const char *pattern, const char *str) · line 321

Quoted 8 lines
lib/parser.c +1 -1
@@ -315,7 +315,7 @@ bool match_wildcard(const char *pattern, const char *str)
 		}
 	}
 
-	if (*p == '*')
+	while (*p == '*')
 		++p;
 	return !*p;
 }

Thanks, looks right.

We don't appear to have any selftesting for this code.

Should all of parser.c actually exist? Some of it is a subset of lib/glob.c?

author
#2 lore raw
Quoted 31 lines · Andrew Morton
Quoted 17 lines · On Thu, 26 Mar 2026 11:06:04 +0900 Inseob Kim <[email protected]> wrote:

This fixes a bug of match_wildcard that incorrectly handles trailing asterisks. For example, match_wildcard("abc**", "abc") must return true, but it returns false.

---
v2:
- Added Cc. No changes to the code.

---
 lib/parser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/parser.c +0 -0
index 73e8f8e5be73..62da0ac0d438 100644

lib/parser.c bool match_wildcard(const char *pattern, const char *str) · line 321

Quoted 8 lines
lib/parser.c +1 -1
@@ -315,7 +315,7 @@ bool match_wildcard(const char *pattern, const char *str)
              }
      }
 
-     if (*p == '*')
+     while (*p == '*')
              ++p;
      return !*p;
 }

Thanks, looks right.

Quoted 1 line

We don't appear to have any selftesting for this code.

Would you prefer test cases for match_wildcard?

Quoted 3 lines

Should all of parser.c actually exist? Some of it is a subset of lib/glob.c?

Wildcard is definitely a subset of glob, but we're intentionally using wildcard for genfscon for example
(https://lore.kernel.org/selinux/[email protected]/).
I'd like to leave the parser.c as is.

Signature · 1 line
Inseob Kim | Software Engineer | [email protected]
maintainer
#3 lore raw
Quoted 33 lines · On Thu, 26 Mar 2026 13:12:26 +0900 Inseob Kim <[email protected]> wrote:
Quoted 31 lines · Andrew Morton
Quoted 17 lines · On Thu, 26 Mar 2026 11:06:04 +0900 Inseob Kim <[email protected]> wrote:

This fixes a bug of match_wildcard that incorrectly handles trailing asterisks. For example, match_wildcard("abc**", "abc") must return true, but it returns false.

---
v2:
- Added Cc. No changes to the code.

---
 lib/parser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/parser.c +0 -0
index 73e8f8e5be73..62da0ac0d438 100644

lib/parser.c bool match_wildcard(const char *pattern, const char *str) · line 321

Quoted 8 lines
lib/parser.c +1 -1
@@ -315,7 +315,7 @@ bool match_wildcard(const char *pattern, const char *str)
              }
      }
 
-     if (*p == '*')
+     while (*p == '*')
              ++p;
      return !*p;
 }

Thanks, looks right.

Quoted 3 lines
Quoted 1 line

We don't appear to have any selftesting for this code.

Would you prefer test cases for match_wildcard?

That would of course be wonderful, but such a contribution is unrelated to this bugfix. Up to you.

Quoted 8 lines
Quoted 3 lines

Should all of parser.c actually exist? Some of it is a subset of lib/glob.c?

Wildcard is definitely a subset of glob, but we're intentionally using wildcard for genfscon for example
(https://lore.kernel.org/selinux/[email protected]/).
I'd like to leave the parser.c as is.

That's a nice boot-time improvement, but I don't understand from that why wildcard is preferable to glob?

author
#4 lore raw
Quoted 47 lines · Andrew Morton
Quoted 33 lines · On Thu, 26 Mar 2026 13:12:26 +0900 Inseob Kim <[email protected]> wrote:
Quoted 31 lines · Andrew Morton
Quoted 17 lines · On Thu, 26 Mar 2026 11:06:04 +0900 Inseob Kim <[email protected]> wrote:

This fixes a bug of match_wildcard that incorrectly handles trailing asterisks. For example, match_wildcard("abc**", "abc") must return true, but it returns false.

---
v2:
- Added Cc. No changes to the code.

---
 lib/parser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/parser.c +0 -0
index 73e8f8e5be73..62da0ac0d438 100644

lib/parser.c bool match_wildcard(const char *pattern, const char *str) · line 321

Quoted 8 lines
lib/parser.c +1 -1
@@ -315,7 +315,7 @@ bool match_wildcard(const char *pattern, const char *str)
              }
      }
 
-     if (*p == '*')
+     while (*p == '*')
              ++p;
      return !*p;
 }

Thanks, looks right.

Quoted 3 lines
Quoted 1 line

We don't appear to have any selftesting for this code.

Would you prefer test cases for match_wildcard?

That would of course be wonderful, but such a contribution is unrelated to this bugfix. Up to you.

Quoted 4 lines
Quoted 3 lines

Should all of parser.c actually exist? Some of it is a subset of lib/glob.c?

Quoted 7 lines
Quoted 4 lines

Wildcard is definitely a subset of glob, but we're intentionally using wildcard for genfscon for example
(https://lore.kernel.org/selinux/[email protected]/).
I'd like to leave the parser.c as is.

That's a nice boot-time improvement, but I don't understand from that why wildcard is preferable to glob?

Sorry for the confusion; let me correct myself. It's not that wildcard is preferable to glob, but genfs_seclabel_wildcard is already merged and in use so moving from wildcard to glob would introduce breaking changes. Let me invite Takaya who possibly has more rationale for the wildcard.

#5 lore raw
Quoted 58 lines · Inseob Kim
Quoted 47 lines · Andrew Morton
Quoted 33 lines · On Thu, 26 Mar 2026 13:12:26 +0900 Inseob Kim <[email protected]> wrote:
Quoted 31 lines · Andrew Morton
Quoted 17 lines · On Thu, 26 Mar 2026 11:06:04 +0900 Inseob Kim <[email protected]> wrote:

This fixes a bug of match_wildcard that incorrectly handles trailing asterisks. For example, match_wildcard("abc**", "abc") must return true, but it returns false.

---
v2:
- Added Cc. No changes to the code.

---
 lib/parser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/parser.c +0 -0
index 73e8f8e5be73..62da0ac0d438 100644

lib/parser.c bool match_wildcard(const char *pattern, const char *str) · line 321

Quoted 8 lines
lib/parser.c +1 -1
@@ -315,7 +315,7 @@ bool match_wildcard(const char *pattern, const char *str)
              }
      }
 
-     if (*p == '*')
+     while (*p == '*')
              ++p;
      return !*p;
 }

Thanks, looks right.

Quoted 3 lines
Quoted 1 line

We don't appear to have any selftesting for this code.

Would you prefer test cases for match_wildcard?

That would of course be wonderful, but such a contribution is unrelated to this bugfix. Up to you.

Quoted 4 lines
Quoted 3 lines

Should all of parser.c actually exist? Some of it is a subset of lib/glob.c?

Quoted 7 lines
Quoted 4 lines

Wildcard is definitely a subset of glob, but we're intentionally using wildcard for genfscon for example
(https://lore.kernel.org/selinux/[email protected]/).
I'd like to leave the parser.c as is.

That's a nice boot-time improvement, but I don't understand from that why wildcard is preferable to glob?

Quoted 5 lines

Sorry for the confusion; let me correct myself. It's not that wildcard is preferable to glob, but genfs_seclabel_wildcard is already merged and in use so moving from wildcard to glob would introduce breaking changes. Let me invite Takaya who possibly has more rationale for the wildcard.

Yes, there wasn't strong motivation to avoid glob; wildcards were sufficient, so we just didn't consider adopting glob.
Since glob is a superset of wildcards and doesn't treat slashes as special characters,
it would certainly be more convenient to use. We might want to improve SELinux later including the network interface matching, which also uses wildcard matching.

maintainer
#6 lore raw
Quoted 6 lines · On Fri, 27 Mar 2026 19:11:21 +0900 Takaya Saeki <[email protected]> wrote:
Quoted 5 lines

Sorry for the confusion; let me correct myself. It's not that wildcard is preferable to glob, but genfs_seclabel_wildcard is already merged and in use so moving from wildcard to glob would introduce breaking changes. Let me invite Takaya who possibly has more rationale for the wildcard.

Quoted 7 lines

Yes, there wasn't strong motivation to avoid glob; wildcards were sufficient, so we just didn't consider adopting glob.
Since glob is a superset of wildcards and doesn't treat slashes as special characters,
it would certainly be more convenient to use. We might want to improve SELinux later including the network interface matching, which also uses wildcard matching.

OK, thanks.

It isn't a big deal at all - I'm just wondering if we have an opportunity to remove some code by migrating all wildcard users over to glob.

Reviewed-by
#7 lore raw
In reply to Andrew Morton
Quoted 30 lines · Andrew Morton
Quoted 17 lines · On Thu, 26 Mar 2026 11:06:04 +0900 Inseob Kim <[email protected]> wrote:

This fixes a bug of match_wildcard that incorrectly handles trailing asterisks. For example, match_wildcard("abc**", "abc") must return true, but it returns false.

---
v2:
- Added Cc. No changes to the code.

---
 lib/parser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/parser.c +0 -0
index 73e8f8e5be73..62da0ac0d438 100644

lib/parser.c bool match_wildcard(const char *pattern, const char *str) · line 321

Quoted 8 lines
lib/parser.c +1 -1
@@ -315,7 +315,7 @@ bool match_wildcard(const char *pattern, const char *str)
 		}
 	}
 
-	if (*p == '*')
+	while (*p == '*')
 		++p;
 	return !*p;
 }

Thanks, looks right.

Quoted 4 lines

We don't appear to have any selftesting for this code.

Should all of parser.c actually exist? Some of it is a subset of lib/glob.c?

Hi!

Good patch