Skip to content

Commit 754f873

Browse files
Peter Zijlstramasahir0y
authored andcommitted
module: Extend the module namespace parsing
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 <[email protected]> Reviewed-by: Petr Pavlu <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 520b1a1 commit 754f873

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

kernel/module/main.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,12 +1083,44 @@ static char *get_modinfo(const struct load_info *info, const char *tag)
10831083
return get_next_modinfo(info, tag, NULL);
10841084
}
10851085

1086+
/**
1087+
* verify_module_namespace() - does @modname have access to this symbol's @namespace
1088+
* @namespace: export symbol namespace
1089+
* @modname: module name
1090+
*
1091+
* If @namespace is prefixed with "module:" to indicate it is a module namespace
1092+
* then test if @modname matches any of the comma separated patterns.
1093+
*
1094+
* The patterns only support tail-glob.
1095+
*/
10861096
static bool verify_module_namespace(const char *namespace, const char *modname)
10871097
{
1098+
size_t len, modlen = strlen(modname);
10881099
const char *prefix = "module:";
1100+
const char *sep;
1101+
bool glob;
1102+
1103+
if (!strstarts(namespace, prefix))
1104+
return false;
1105+
1106+
for (namespace += strlen(prefix); *namespace; namespace = sep) {
1107+
sep = strchrnul(namespace, ',');
1108+
len = sep - namespace;
10891109

1090-
return strstarts(namespace, prefix) &&
1091-
!strcmp(namespace + strlen(prefix), modname);
1110+
glob = false;
1111+
if (sep[-1] == '*') {
1112+
len--;
1113+
glob = true;
1114+
}
1115+
1116+
if (*sep)
1117+
sep++;
1118+
1119+
if (strncmp(namespace, modname, len) == 0 && (glob || len == modlen))
1120+
return true;
1121+
}
1122+
1123+
return false;
10921124
}
10931125

10941126
static int verify_namespace_is_imported(const struct load_info *info,

scripts/mod/modpost.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,12 +1682,44 @@ void buf_write(struct buffer *buf, const char *s, int len)
16821682
buf->pos += len;
16831683
}
16841684

1685+
/**
1686+
* verify_module_namespace() - does @modname have access to this symbol's @namespace
1687+
* @namespace: export symbol namespace
1688+
* @modname: module name
1689+
*
1690+
* If @namespace is prefixed with "module:" to indicate it is a module namespace
1691+
* then test if @modname matches any of the comma separated patterns.
1692+
*
1693+
* The patterns only support tail-glob.
1694+
*/
16851695
static bool verify_module_namespace(const char *namespace, const char *modname)
16861696
{
1697+
size_t len, modlen = strlen(modname);
16871698
const char *prefix = "module:";
1699+
const char *sep;
1700+
bool glob;
1701+
1702+
if (!strstarts(namespace, prefix))
1703+
return false;
1704+
1705+
for (namespace += strlen(prefix); *namespace; namespace = sep) {
1706+
sep = strchrnul(namespace, ',');
1707+
len = sep - namespace;
16881708

1689-
return strstarts(namespace, prefix) &&
1690-
!strcmp(namespace + strlen(prefix), modname);
1709+
glob = false;
1710+
if (sep[-1] == '*') {
1711+
len--;
1712+
glob = true;
1713+
}
1714+
1715+
if (*sep)
1716+
sep++;
1717+
1718+
if (strncmp(namespace, modname, len) == 0 && (glob || len == modlen))
1719+
return true;
1720+
}
1721+
1722+
return false;
16911723
}
16921724

16931725
static void check_exports(struct module *mod)

0 commit comments

Comments
 (0)