Commit 2ed2d5b3 authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: fix a deadlock during init_acl procedure

The deadlock is found through the following scenario.

sys_mkdir()
 -> f2fs_add_link()
  -> __f2fs_add_link()
   -> init_inode_metadata()
     : lock_page(inode);
    -> f2fs_init_acl()
     -> f2fs_set_acl()
      -> f2fs_setxattr(..., NULL)
       : This NULL page incurs a deadlock at update_inode_page().

So, likewise f2fs_init_security(), this patch adds a parameter to transfer the
locked inode page to f2fs_setxattr().

Found by Linux File System Verification project (linuxtesting.org).
Reported-by: default avatarAlexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk.kim@samsung.com>
parent b8b60e1a
...@@ -205,7 +205,8 @@ struct posix_acl *f2fs_get_acl(struct inode *inode, int type) ...@@ -205,7 +205,8 @@ struct posix_acl *f2fs_get_acl(struct inode *inode, int type)
return acl; return acl;
} }
static int f2fs_set_acl(struct inode *inode, int type, struct posix_acl *acl) static int f2fs_set_acl(struct inode *inode, int type,
struct posix_acl *acl, struct page *ipage)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
struct f2fs_inode_info *fi = F2FS_I(inode); struct f2fs_inode_info *fi = F2FS_I(inode);
...@@ -250,7 +251,7 @@ static int f2fs_set_acl(struct inode *inode, int type, struct posix_acl *acl) ...@@ -250,7 +251,7 @@ static int f2fs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
} }
} }
error = f2fs_setxattr(inode, name_index, "", value, size, NULL); error = f2fs_setxattr(inode, name_index, "", value, size, ipage);
kfree(value); kfree(value);
if (!error) if (!error)
...@@ -260,7 +261,7 @@ static int f2fs_set_acl(struct inode *inode, int type, struct posix_acl *acl) ...@@ -260,7 +261,7 @@ static int f2fs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
return error; return error;
} }
int f2fs_init_acl(struct inode *inode, struct inode *dir) int f2fs_init_acl(struct inode *inode, struct inode *dir, struct page *ipage)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
struct posix_acl *acl = NULL; struct posix_acl *acl = NULL;
...@@ -280,7 +281,7 @@ int f2fs_init_acl(struct inode *inode, struct inode *dir) ...@@ -280,7 +281,7 @@ int f2fs_init_acl(struct inode *inode, struct inode *dir)
goto cleanup; goto cleanup;
if (S_ISDIR(inode->i_mode)) { if (S_ISDIR(inode->i_mode)) {
error = f2fs_set_acl(inode, ACL_TYPE_DEFAULT, acl); error = f2fs_set_acl(inode, ACL_TYPE_DEFAULT, acl, ipage);
if (error) if (error)
goto cleanup; goto cleanup;
} }
...@@ -288,7 +289,7 @@ int f2fs_init_acl(struct inode *inode, struct inode *dir) ...@@ -288,7 +289,7 @@ int f2fs_init_acl(struct inode *inode, struct inode *dir)
if (error < 0) if (error < 0)
return error; return error;
if (error > 0) if (error > 0)
error = f2fs_set_acl(inode, ACL_TYPE_ACCESS, acl); error = f2fs_set_acl(inode, ACL_TYPE_ACCESS, acl, ipage);
cleanup: cleanup:
posix_acl_release(acl); posix_acl_release(acl);
return error; return error;
...@@ -314,7 +315,7 @@ int f2fs_acl_chmod(struct inode *inode) ...@@ -314,7 +315,7 @@ int f2fs_acl_chmod(struct inode *inode)
if (error) if (error)
return error; return error;
error = f2fs_set_acl(inode, ACL_TYPE_ACCESS, acl); error = f2fs_set_acl(inode, ACL_TYPE_ACCESS, acl, NULL);
posix_acl_release(acl); posix_acl_release(acl);
return error; return error;
} }
...@@ -389,7 +390,7 @@ static int f2fs_xattr_set_acl(struct dentry *dentry, const char *name, ...@@ -389,7 +390,7 @@ static int f2fs_xattr_set_acl(struct dentry *dentry, const char *name,
acl = NULL; acl = NULL;
} }
error = f2fs_set_acl(inode, type, acl); error = f2fs_set_acl(inode, type, acl, NULL);
release_and_out: release_and_out:
posix_acl_release(acl); posix_acl_release(acl);
......
...@@ -38,7 +38,7 @@ struct f2fs_acl_header { ...@@ -38,7 +38,7 @@ struct f2fs_acl_header {
extern struct posix_acl *f2fs_get_acl(struct inode *, int); extern struct posix_acl *f2fs_get_acl(struct inode *, int);
extern int f2fs_acl_chmod(struct inode *); extern int f2fs_acl_chmod(struct inode *);
extern int f2fs_init_acl(struct inode *, struct inode *); extern int f2fs_init_acl(struct inode *, struct inode *, struct page *);
#else #else
#define f2fs_check_acl NULL #define f2fs_check_acl NULL
#define f2fs_get_acl NULL #define f2fs_get_acl NULL
...@@ -49,7 +49,8 @@ static inline int f2fs_acl_chmod(struct inode *inode) ...@@ -49,7 +49,8 @@ static inline int f2fs_acl_chmod(struct inode *inode)
return 0; return 0;
} }
static inline int f2fs_init_acl(struct inode *inode, struct inode *dir) static inline int f2fs_init_acl(struct inode *inode, struct inode *dir,
struct page *page)
{ {
return 0; return 0;
} }
......
...@@ -346,7 +346,7 @@ static struct page *init_inode_metadata(struct inode *inode, ...@@ -346,7 +346,7 @@ static struct page *init_inode_metadata(struct inode *inode,
goto error; goto error;
} }
err = f2fs_init_acl(inode, dir); err = f2fs_init_acl(inode, dir, page);
if (err) if (err)
goto error; goto error;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment