module: expose imported namespaces via sysfs
Subsystems (3)
v2 cover module: expose imported namespaces via sysfs
Add /sys/module/*/import_ns to expose the symbol namespaces imported by a loaded module.
Changes since v1:
- Simplified commit message to drop unnecessary/incorrect background
- Use .setup/.free callbacks in module_attribute to ensure imported_namespaces is NULL-initialized before error paths and NULL'd after kfree (Sami)
- Updated KernelVersion to 7.1 in docs for next merge window
PATCH v2 1/2 module: expose imported namespaces via sysfs
Previously, the only way for userspace to inspect the symbol namespaces a module imports is to locate the .ko on disk and invoke modinfo(8) to decompress/parse the metadata. The kernel validated namespaces at load time, but it was otherwise discarded.
Add /sys/module/*/import_ns to expose imported namespaces for currently loaded modules. The file contains one namespace per line and only exists for modules that import at least one namespace.
--- Documentation/ABI/testing/sysfs-module | 9 ++++ include/linux/module.h | 1 + kernel/module/main.c | 69 +++++++++++++++++++++++++- 3 files changed, 78 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-module +9 -0
@@ -48,6 +48,15 @@ Contact: Kay Sievers <[email protected]> Description: Show the initialization state(live, coming, going) of the module. +What: /sys/module/*/import_ns +Date: January 2026 +KernelVersion: 7.1 +Contact: [email protected] +Description: List of symbol namespaces imported by this module via + MODULE_IMPORT_NS(). Each namespace appears on a separate line. + This file only exists for modules that import at least one + namespace. + What: /sys/module/*/taint Date: Jan 2012 KernelVersion: 3.3
include/linux/module.h +1 -0
@@ -413,6 +413,7 @@ struct module {struct module_attribute *modinfo_attrs;const char *version;const char *srcversion; +const char *imported_namespaces;struct kobject *holders_dir;/* Exported symbols */
kernel/module/main.c +68 -1
97 lines not on this page · raw message
Signature · 1 line
2.53.0
Quoted 8 lines · Nicholas Sielicki
Previously, the only way for userspace to inspect the symbol namespaces a module imports is to locate the .ko on disk and invoke modinfo(8) to decompress/parse the metadata. The kernel validated namespaces at load time, but it was otherwise discarded.
Add
/sys/module/*/import_nsto expose imported namespaces for currently loaded modules. The file contains one namespace per line and only exists for modules that import at least one namespace.
What I'm missing here is why users would care about this?
Matthias Männich
maintainerQuoted 7 lines · Peter Zijlstra
Quoted 5 lines · Nicholas Sielicki
Previously, the only way for userspace to inspect the symbol namespaces a module imports is to locate the .ko on disk and invoke modinfo(8) to decompress/parse the metadata. The kernel validated namespaces at load time, but it was otherwise discarded.
Quoted 5 lines
Quoted 3 lines
Add
/sys/module/*/import_nsto expose imported namespaces for currently loaded modules. The file contains one namespace per line and only exists for modules that import at least one namespace.What I'm missing here is why users would care about this?
FWIW, we use a symbol namespace in Android (GKI) [1] for symbols that should not be used by all drivers (e.g. direct file system access). This change would make it much easier to surface at runtime, which drivers are using which namespace and thus have access to symbols they should not.
Cheers,
Matthias
[1] https://android.googlesource.com/kernel/common/+/a38b207d4f4e02041f72a8168bb24d1617099988
PATCH v2 2/2 docs: symbol-namespaces: mention sysfs attribute
In reply to Nicholas SielickiReference the new /sys/module/*/import_ns sysfs attribute in docs as an alternative to modinfo for inspecting imported namespaces of loaded modules.
--- Documentation/core-api/symbol-namespaces.rst | 5 +++++ 1 file changed, 5 insertions(+)
Documentation/core-api/symbol-namespaces.rst +5 -0
@@ -114,6 +114,11 @@ inspected with modinfo:: import_ns: USB_STORAGE [...] +For modules that are currently loaded, imported namespaces are also available +via sysfs:: + + $ cat /sys/module/ums_karma/import_ns + USB_STORAGE It is advisable to add the MODULE_IMPORT_NS() statement close to other module metadata definitions like MODULE_AUTHOR() or MODULE_LICENSE().
Signature · 1 line
2.53.0
Quoted 11 lines · Nicholas Sielicki
Add
/sys/module/*/import_nsto expose the symbol namespaces imported by a loaded module.Changes since v1:
- Simplified commit message to drop unnecessary/incorrect background
- Use .setup/.free callbacks inmodule_attributeto ensureimported_namespacesis NULL-initialized before error paths and NULL'd after kfree (Sami)
- Updated KernelVersion to 7.1 in docs for next merge window[...]
Applied to modules-next, thanks!
[1/2] module: expose imported namespaces via sysfs
commit: 3fe1dcbc2d20c5dbc581c0bb458e05365bfffcf7
[2/2] docs: symbol-namespaces: mention sysfs attribute
commit: f15dbe8a94b6e3768b10e10bf8ab95b28682db80Best regards,
Sami