Each registered binfmt_misc node pins binfmt_misc mount point, which in
turn pins the owner ve. This means that if we don't clean up binfmt_misc
nodes on ve stop, the mount point as well as the ve struct will leak.

Signed-off-by: Vladimir Davydov <[email protected]>
---
 fs/binfmt_misc.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index 44871531b810..f71e2c3f22fe 100644
--- a/fs/binfmt_misc.c
+++ b/fs/binfmt_misc.c
@@ -752,16 +752,38 @@ static struct file_system_type bm_fs_type = {
 };
 MODULE_ALIAS_FS("binfmt_misc");
 
+static void ve_binfmt_fini(void *data)
+{
+       struct binfmt_misc *bm_data = get_exec_env()->binfmt_misc;
+
+       /*
+        * Note we don't take any locks here. This is safe as long as nobody
+        * uses binfmt_misc outside the owner ve.
+        */
+       while (!list_empty(&bm_data->entries))
+               kill_node(bm_data, list_first_entry(
+                       &bm_data->entries, Node, list));
+}
+
+static struct ve_hook ve_binfmt_hook = {
+       .fini           = ve_binfmt_fini,
+       .priority       = HOOK_PRIO_DEFAULT,
+       .owner          = THIS_MODULE,
+};
+
 static int __init init_misc_binfmt(void)
 {
        int err = register_filesystem(&bm_fs_type);
-       if (!err)
+       if (!err) {
                insert_binfmt(&misc_format);
+               ve_hook_register(VE_SS_CHAIN, &ve_binfmt_hook);
+       }
        return err;
 }
 
 static void __exit exit_misc_binfmt(void)
 {
+       ve_hook_unregister(&ve_binfmt_hook);
        unregister_binfmt(&misc_format);
        unregister_filesystem(&bm_fs_type);
 }
-- 
2.1.4

_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to