[Devel,2/2] module: export sysfs dentries in containers

Submitted by Stanislav Kinsburskiy on July 11, 2017, 3:29 p.m.

Details

Message ID 20170711152922.6646.91471.stgit@localhost.localdomain
State New
Series "module: expose sysfs dentries in container"
Headers show

Commit Message

Stanislav Kinsburskiy July 11, 2017, 3:29 p.m.
This patch add exposing of "/sys/module/<NAME>" and
"/sys/module/<NAME>/holders" dentries in containers.

Notes:
1) These dentries are visible only if "/sys/module" is exported.

2) Buffer for path is made static in assumption, that modules load and unload
my happen from time to time and there is not need to allocate this buffer each
time we need to expose or hide module sysfs dentries (allocating on stack
gives "the frame size of 4104 bytes is larger than 2048 bytes" warning)

https://jira.sw.ru/browse/PSBM-63892

Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
---
 kernel/module.c |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

Patch hide | download patch | download mbox

diff --git a/kernel/module.c b/kernel/module.c
index a094aeb..dfccff9 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1685,6 +1685,49 @@  static int mod_sysfs_init(struct module *mod)
 	return err;
 }
 
+#ifdef CONFIG_VE
+
+static ssize_t module_sysfs_perm_set_ve(struct module *mod, char *subdir, int mask)
+{
+	static char path[PATH_MAX];
+
+	if (snprintf(path, sizeof(path) - 1, "module/%s/%s",
+		     mod->name, (subdir) ? subdir : "") >= sizeof(path) - 1)
+		return -E2BIG;
+
+	return sysfs_perms_set(path, NULL, mask);
+}
+
+static ssize_t module_sysfs_hide_dir_ve(struct module *mod, char *subdir)
+{
+	return module_sysfs_perm_set_ve(mod, subdir, -1);
+}
+
+static ssize_t module_sysfs_expose_dir_ve(struct module *mod, char *subdir)
+{
+	return module_sysfs_perm_set_ve(mod, subdir, MAY_READ | MAY_EXEC);
+}
+
+static int module_sysfs_ve_init(struct module *mod)
+{
+	int err;
+
+	err = module_sysfs_expose_dir_ve(mod, NULL);
+	if (!err)
+		err = module_sysfs_expose_dir_ve(mod, "holders");
+	return err;
+}
+
+static void module_sysfs_ve_fini(struct module *mod)
+{
+	(void) module_sysfs_hide_dir_ve(mod, "holders");
+	(void) module_sysfs_hide_dir_ve(mod, NULL);
+}
+#else
+static __always_inline int module_sysfs_ve_init(struct module *mod) { }
+static __always_inline void module_sysfs_ve_fini(struct module *mod) { }
+#endif
+
 static int mod_sysfs_setup(struct module *mod,
 			   const struct load_info *info,
 			   struct kernel_param *kparam,
@@ -1715,6 +1758,7 @@  static int mod_sysfs_setup(struct module *mod,
 	add_notes_attrs(mod, info);
 
 	kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD);
+	(void) module_sysfs_ve_init(mod);
 	return 0;
 
 out_unreg_param:
@@ -1729,6 +1773,7 @@  static int mod_sysfs_setup(struct module *mod,
 
 static void mod_sysfs_fini(struct module *mod)
 {
+	module_sysfs_ve_fini(mod);
 	remove_notes_attrs(mod);
 	remove_sect_attrs(mod);
 	kobject_put(&mod->mkobj.kobj);