[PATCH v3 3/5] module: Extend the MODULE_ namespace parsing

Peter Zijlstra posted 5 patches 7 months, 2 weeks ago
[PATCH v3 3/5] module: Extend the MODULE_ namespace parsing
Posted by Peter Zijlstra 7 months, 2 weeks ago
Instead of only accepting "module:${name}", extend it with a comma
separated list of module names and add tail glob support.

That is, something like: "module:foo-*,bar" is now possible.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 kernel/module/main.c  |   36 ++++++++++++++++++++++++++++++++++--
 scripts/mod/modpost.c |   36 ++++++++++++++++++++++++++++++++++--
 2 files changed, 68 insertions(+), 4 deletions(-)

--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -1083,12 +1083,44 @@ static char *get_modinfo(const struct lo
 	return get_next_modinfo(info, tag, NULL);
 }
 
+/**
+ * verify_module_namespace() - does @modname have access to this symbol's @namespace
+ * @namespace: export symbol namespace
+ * @modname: module name
+ *
+ * If @namespace is prefixed with "module:" to indicate it is a module namespace
+ * then test if @modname matches any of the comma separated patterns.
+ *
+ * The patterns only support tail-glob.
+ */
 static bool verify_module_namespace(const char *namespace, const char *modname)
 {
+	size_t len, modlen = strlen(modname);
 	const char *prefix = "module:";
+	const char *sep;
+	bool glob;
 
-	return strstarts(namespace, prefix) &&
-	       !strsmp(namespace + strlen(prefix), modname);
+	if (!strstarts(namespace, prefix))
+		return false;
+
+	for (namespace += strlen(prefix); *namespace; namespace = sep) {
+		sep = strchrnul(namespace, ',');
+		len = sep - namespace;
+
+		glob = false;
+		if (sep[-1] == '*') {
+			len--;
+			glob = true;
+		}
+
+		if (*sep)
+			sep++;
+
+		if (strncmp(namespace, modname, len) == 0 && (glob || len == modlen))
+			return true;
+	}
+
+	return false;
 }
 
 static int verify_namespace_is_imported(const struct load_info *info,
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1682,12 +1682,44 @@ void buf_write(struct buffer *buf, const
 	buf->pos += len;
 }
 
+/**
+ * verify_module_namespace() - does @modname have access to this symbol's @namespace
+ * @namespace: export symbol namespace
+ * @modname: module name
+ *
+ * If @namespace is prefixed with "module:" to indicate it is a module namespace
+ * then test if @modname matches any of the comma separated patterns.
+ *
+ * The patterns only support tail-glob.
+ */
 static bool verify_module_namespace(const char *namespace, const char *modname)
 {
+	size_t len, modlen = strlen(modname);
 	const char *prefix = "module:";
+	const char *sep;
+	bool glob;
 
-	return strstarts(namespace, prefix) &&
-	       !strcmp(namespace + strlen(prefix), modname);
+	if (!strstarts(namespace, prefix))
+		return false;
+
+	for (namespace += strlen(prefix); *namespace; namespace = sep) {
+		sep = strchrnul(namespace, ',');
+		len = sep - namespace;
+
+		glob = false;
+		if (sep[-1] == '*') {
+			len--;
+			glob = true;
+		}
+
+		if (*sep)
+			sep++;
+
+		if (strncmp(namespace, modname, len) == 0 && (glob || len == modlen))
+			return true;
+	}
+
+	return false;
 }
 
 static void check_exports(struct module *mod)
Re: [PATCH v3 3/5] module: Extend the MODULE_ namespace parsing
Posted by Masahiro Yamada 6 months, 4 weeks ago
I think the patch subject is stale.

MODULE_ was the prefix in the previous v2 series.

Now, the prefix part is module:


On Fri, May 2, 2025 at 11:25 PM Peter Zijlstra <peterz@infradead.org> wrote:
>
> Instead of only accepting "module:${name}", extend it with a comma
> separated list of module names and add tail glob support.
>
> That is, something like: "module:foo-*,bar" is now possible.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
>  kernel/module/main.c  |   36 ++++++++++++++++++++++++++++++++++--
>  scripts/mod/modpost.c |   36 ++++++++++++++++++++++++++++++++++--
>  2 files changed, 68 insertions(+), 4 deletions(-)
>
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -1083,12 +1083,44 @@ static char *get_modinfo(const struct lo
>         return get_next_modinfo(info, tag, NULL);
>  }
>
> +/**
> + * verify_module_namespace() - does @modname have access to this symbol's @namespace
> + * @namespace: export symbol namespace
> + * @modname: module name
> + *
> + * If @namespace is prefixed with "module:" to indicate it is a module namespace
> + * then test if @modname matches any of the comma separated patterns.
> + *
> + * The patterns only support tail-glob.
> + */
>  static bool verify_module_namespace(const char *namespace, const char *modname)
>  {
> +       size_t len, modlen = strlen(modname);
>         const char *prefix = "module:";
> +       const char *sep;
> +       bool glob;
>
> -       return strstarts(namespace, prefix) &&
> -              !strsmp(namespace + strlen(prefix), modname);
> +       if (!strstarts(namespace, prefix))
> +               return false;
> +
> +       for (namespace += strlen(prefix); *namespace; namespace = sep) {
> +               sep = strchrnul(namespace, ',');
> +               len = sep - namespace;
> +
> +               glob = false;
> +               if (sep[-1] == '*') {
> +                       len--;
> +                       glob = true;
> +               }
> +
> +               if (*sep)
> +                       sep++;
> +
> +               if (strncmp(namespace, modname, len) == 0 && (glob || len == modlen))
> +                       return true;
> +       }
> +
> +       return false;
>  }
>
>  static int verify_namespace_is_imported(const struct load_info *info,
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -1682,12 +1682,44 @@ void buf_write(struct buffer *buf, const
>         buf->pos += len;
>  }
>
> +/**
> + * verify_module_namespace() - does @modname have access to this symbol's @namespace
> + * @namespace: export symbol namespace
> + * @modname: module name
> + *
> + * If @namespace is prefixed with "module:" to indicate it is a module namespace
> + * then test if @modname matches any of the comma separated patterns.
> + *
> + * The patterns only support tail-glob.
> + */
>  static bool verify_module_namespace(const char *namespace, const char *modname)
>  {
> +       size_t len, modlen = strlen(modname);
>         const char *prefix = "module:";
> +       const char *sep;
> +       bool glob;
>
> -       return strstarts(namespace, prefix) &&
> -              !strcmp(namespace + strlen(prefix), modname);
> +       if (!strstarts(namespace, prefix))
> +               return false;
> +
> +       for (namespace += strlen(prefix); *namespace; namespace = sep) {
> +               sep = strchrnul(namespace, ',');
> +               len = sep - namespace;
> +
> +               glob = false;
> +               if (sep[-1] == '*') {
> +                       len--;
> +                       glob = true;
> +               }
> +
> +               if (*sep)
> +                       sep++;
> +
> +               if (strncmp(namespace, modname, len) == 0 && (glob || len == modlen))
> +                       return true;
> +       }
> +
> +       return false;
>  }
>
>  static void check_exports(struct module *mod)
>
>


-- 
Best Regards
Masahiro Yamada
Re: [PATCH v3 3/5] module: Extend the MODULE_ namespace parsing
Posted by Masahiro Yamada 6 months, 4 weeks ago
On Wed, May 21, 2025 at 9:08 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> I think the patch subject is stale.
>
> MODULE_ was the prefix in the previous v2 series.
>
> Now, the prefix part is module:


I will apply with the subject fixed, as "MODULE_" prefix does not make
sense any more.


"module: Extend the module namespace parsing"




>
>
> On Fri, May 2, 2025 at 11:25 PM Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > Instead of only accepting "module:${name}", extend it with a comma
> > separated list of module names and add tail glob support.
> >
> > That is, something like: "module:foo-*,bar" is now possible.
> >
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > ---
> >  kernel/module/main.c  |   36 ++++++++++++++++++++++++++++++++++--
> >  scripts/mod/modpost.c |   36 ++++++++++++++++++++++++++++++++++--
> >  2 files changed, 68 insertions(+), 4 deletions(-)
> >
> > --- a/kernel/module/main.c
> > +++ b/kernel/module/main.c
> > @@ -1083,12 +1083,44 @@ static char *get_modinfo(const struct lo
> >         return get_next_modinfo(info, tag, NULL);
> >  }
> >
> > +/**
> > + * verify_module_namespace() - does @modname have access to this symbol's @namespace
> > + * @namespace: export symbol namespace
> > + * @modname: module name
> > + *
> > + * If @namespace is prefixed with "module:" to indicate it is a module namespace
> > + * then test if @modname matches any of the comma separated patterns.
> > + *
> > + * The patterns only support tail-glob.
> > + */
> >  static bool verify_module_namespace(const char *namespace, const char *modname)
> >  {
> > +       size_t len, modlen = strlen(modname);
> >         const char *prefix = "module:";
> > +       const char *sep;
> > +       bool glob;
> >
> > -       return strstarts(namespace, prefix) &&
> > -              !strsmp(namespace + strlen(prefix), modname);
> > +       if (!strstarts(namespace, prefix))
> > +               return false;
> > +
> > +       for (namespace += strlen(prefix); *namespace; namespace = sep) {
> > +               sep = strchrnul(namespace, ',');
> > +               len = sep - namespace;
> > +
> > +               glob = false;
> > +               if (sep[-1] == '*') {
> > +                       len--;
> > +                       glob = true;
> > +               }
> > +
> > +               if (*sep)
> > +                       sep++;
> > +
> > +               if (strncmp(namespace, modname, len) == 0 && (glob || len == modlen))
> > +                       return true;
> > +       }
> > +
> > +       return false;
> >  }
> >
> >  static int verify_namespace_is_imported(const struct load_info *info,
> > --- a/scripts/mod/modpost.c
> > +++ b/scripts/mod/modpost.c
> > @@ -1682,12 +1682,44 @@ void buf_write(struct buffer *buf, const
> >         buf->pos += len;
> >  }
> >
> > +/**
> > + * verify_module_namespace() - does @modname have access to this symbol's @namespace
> > + * @namespace: export symbol namespace
> > + * @modname: module name
> > + *
> > + * If @namespace is prefixed with "module:" to indicate it is a module namespace
> > + * then test if @modname matches any of the comma separated patterns.
> > + *
> > + * The patterns only support tail-glob.
> > + */
> >  static bool verify_module_namespace(const char *namespace, const char *modname)
> >  {
> > +       size_t len, modlen = strlen(modname);
> >         const char *prefix = "module:";
> > +       const char *sep;
> > +       bool glob;
> >
> > -       return strstarts(namespace, prefix) &&
> > -              !strcmp(namespace + strlen(prefix), modname);
> > +       if (!strstarts(namespace, prefix))
> > +               return false;
> > +
> > +       for (namespace += strlen(prefix); *namespace; namespace = sep) {
> > +               sep = strchrnul(namespace, ',');
> > +               len = sep - namespace;
> > +
> > +               glob = false;
> > +               if (sep[-1] == '*') {
> > +                       len--;
> > +                       glob = true;
> > +               }
> > +
> > +               if (*sep)
> > +                       sep++;
> > +
> > +               if (strncmp(namespace, modname, len) == 0 && (glob || len == modlen))
> > +                       return true;
> > +       }
> > +
> > +       return false;
> >  }
> >
> >  static void check_exports(struct module *mod)
> >
> >
>
>
> --
> Best Regards
> Masahiro Yamada



-- 
Best Regards
Masahiro Yamada
Re: [PATCH v3 3/5] module: Extend the MODULE_ namespace parsing
Posted by Petr Pavlu 7 months, 1 week ago
On 5/2/25 16:12, Peter Zijlstra wrote:
> Instead of only accepting "module:${name}", extend it with a comma
> separated list of module names and add tail glob support.
> 
> That is, something like: "module:foo-*,bar" is now possible.
> 
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>

Reviewed-by: Petr Pavlu <petr.pavlu@suse.com>

-- Petr