[Devel] [PATCH vz8 v2] ve/fs/binfmt: clean bm_data reference from ve on err path
Konstantin Khorenko
khorenko at virtuozzo.com
Fri Sep 10 19:47:20 MSK 2021
1. Make sure ve->binfmt_misc is NULL if error happens on binfmt_misc
mount, otherwise on next attempt to mount binfmt_misc (probably
successful) we won't even try to allocate/init structures for it.
2. The current bm_fill_super() code makes us suppose we can get into
the function with ve->binfmt_misc already initialized. If this is true
and simple_fill_super() fails we will free preconfigured ve->binfmt_misc
without proper deinitialization (ve_binfmt_fini()).
Hopefully this is a wrong assumption, so rewrite the code not to confuse
readers.
Fixes: 90fb0e274 ("ve/fs/binfmt: virtualization")
https://jira.sw.ru/browse/PSBM-131994
Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
fs/binfmt_misc.c | 29 ++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index 2b586d61f4a9..0946e7e6caa5 100644
--- a/fs/binfmt_misc.c
+++ b/fs/binfmt_misc.c
@@ -853,18 +853,28 @@ static int bm_fill_super(struct super_block *sb, struct fs_context *fc)
};
struct ve_struct *ve = get_exec_env();
- struct binfmt_misc *bm_data = ve->binfmt_misc;
+ struct binfmt_misc *bm_data;
- if (!bm_data) {
- bm_data = kzalloc(sizeof(struct binfmt_misc), GFP_KERNEL);
- if (!bm_data)
- return -ENOMEM;
+ /*
+ * bm_get_tree()
+ * get_tree_keyed(fc, bm_fill_super, get_ve(ve))
+ * fc->s_fs_info = current VE
+ * vfs_get_super(fc, vfs_get_keyed_super, bm_fill_super)
+ * sb = sget_fc(fc, test, set_anon_super_fc)
+ * if (!sb->s_root) {
+ * err = bm_fill_super(sb, fc);
+ *
+ * => we should never get here with initialized ve->binfmt_misc.
+ */
+ if (WARN_ON_ONCE(ve->binfmt_misc))
+ return -EEXIST;
- INIT_LIST_HEAD(&bm_data->entries);
- rwlock_init(&bm_data->entries_lock);
+ bm_data = kzalloc(sizeof(struct binfmt_misc), GFP_KERNEL);
+ if (!bm_data)
+ return -ENOMEM;
- ve->binfmt_misc = bm_data;
- }
+ INIT_LIST_HEAD(&bm_data->entries);
+ rwlock_init(&bm_data->entries_lock);
err = simple_fill_super(sb, BINFMTFS_MAGIC, bm_files);
if (err) {
@@ -874,6 +884,7 @@ static int bm_fill_super(struct super_block *sb, struct fs_context *fc)
sb->s_op = &s_ops;
+ ve->binfmt_misc = bm_data;
bm_data->enabled = 1;
return 0;
--
2.28.0
More information about the Devel
mailing list