diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 9f3841be992f6fc5bd6b3ee686e5460a5b775f03..6d0e7b185b39b1a6e34bde9139f41b05f55745c9 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1047,6 +1047,7 @@ struct f2fs_sb_info { struct super_block *sb; /* pointer to VFS super block */ struct proc_dir_entry *s_proc; /* proc entry */ struct f2fs_super_block *raw_super; /* raw super block pointer */ + struct mutex sb_lock; /* lock for raw super block */ int valid_super_block; /* valid super block no */ unsigned long s_flag; /* flags for sbi */ diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 29956e16c58c4dd5eef0047367e34bab617555ea..c355e4435b08ad96fed7cb9d997aaf2a941d7f78 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1962,13 +1962,15 @@ static int f2fs_ioc_get_encryption_pwsalt(struct file *filp, unsigned long arg) if (!f2fs_sb_has_encrypt(inode->i_sb)) return -EOPNOTSUPP; - if (uuid_is_nonzero(sbi->raw_super->encrypt_pw_salt)) - goto got_it; - err = mnt_want_write_file(filp); if (err) return err; + mutex_lock(&sbi->sb_lock); + + if (uuid_is_nonzero(sbi->raw_super->encrypt_pw_salt)) + goto got_it; + /* update superblock with uuid */ generate_random_uuid(sbi->raw_super->encrypt_pw_salt); @@ -1976,15 +1978,16 @@ static int f2fs_ioc_get_encryption_pwsalt(struct file *filp, unsigned long arg) if (err) { /* undo new data */ memset(sbi->raw_super->encrypt_pw_salt, 0, 16); - mnt_drop_write_file(filp); - return err; + goto out_err; } - mnt_drop_write_file(filp); got_it: if (copy_to_user((__u8 __user *)arg, sbi->raw_super->encrypt_pw_salt, 16)) - return -EFAULT; - return 0; + err = -EFAULT; +out_err: + mutex_unlock(&sbi->sb_lock); + mnt_drop_write_file(filp); + return err; } static int f2fs_ioc_gc(struct file *filp, unsigned long arg) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index ff6da6e05ec9b934f378982a89efc26efca62089..d2833a2325287d68506bf2318e0a875b717e586a 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2221,6 +2221,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sbi->dirty_device = 0; spin_lock_init(&sbi->dev_lock); + + mutex_init(&sbi->sb_lock); } static int init_percpu_info(struct f2fs_sb_info *sbi)