assorted overlayfs fixes for v4.14-rc3
Subsystems (3)
Amir Goldstein
maintainercover assorted overlayfs fixes for v4.14-rc3
Miklos,
Following are 1 fix for a commit in v4.14-rc1
and 3 fixes for index error paths in v4.13.
Amir.
Amir Goldstein (4):
ovl: fix may_write_real() for overlayfs directories
ovl: fix error value printed in ovl_lookup_index()
ovl: fix dput() of ERR_PTR in ovl_cleanup_index()
ovl: fix dentry leak in ovl_indexdir_cleanup()
fs/namespace.c | 4 +++- fs/overlayfs/namei.c | 1 + fs/overlayfs/readdir.c | 6 ++++-- fs/overlayfs/util.c | 9 ++++++--- 4 files changed, 14 insertions(+), 6 deletions(-)
Signature · 1 line
2.7.4
Amir Goldstein
maintainerPATCH 1/4 ovl: fix may_write_real() for overlayfs directories
Overlayfs directory file_inode() is the overlay inode whether the real inode is upper or lower.
This fixes a regression in xfstest generic/158.
--- fs/namespace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/namespace.c +3 -1
@@ -468,7 +468,9 @@ static inline int may_write_real(struct file *file)/* File refers to upper, writable layer? */ upperdentry =d_real (dentry,NULL ,0 ,D_REAL_UPPER ); -if (upperdentry &&file_inode (file) ==d_inode (upperdentry)) +if (upperdentry && + (file_inode (file) ==d_inode (upperdentry) || +file_inode (file) ==d_inode (dentry)))return 0 ;/* Lower layer: can't write to real file, sorry... */
Signature · 1 line
2.7.4
Amir Goldstein
maintainerPATCH 2/4 ovl: fix error value printed in ovl_lookup_index()
In reply to Amir Goldstein--- fs/overlayfs/namei.c | 1 + 1 file changed, 1 insertion(+)
fs/overlayfs/namei.c +1 -0
@@ -506,6 +506,7 @@ static struct dentry *ovl_lookup_index(struct dentry *dentry, index =lookup_one_len_unlocked (name.name, ofs->indexdir, name.len);if (IS_ERR (index)) { + err =PTR_ERR (index); pr_warn_ratelimited("overlayfs: failed inode index lookup (ino=%lu, key=%*s, err=%i);\n" "overlayfs: mount with '-o index=off' to disable inodes index.\n", d_inode(origin)->i_ino, name.len, name.name,
Signature · 1 line
2.7.4
Amir Goldstein
maintainerPATCH 3/4 ovl: fix dput() of ERR_PTR in ovl_cleanup_index()
In reply to Amir Goldstein--- fs/overlayfs/util.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/overlayfs/util.c +6 -3
@@ -430,7 +430,7 @@ void ovl_inuse_unlock(struct dentry *dentry) } } -/* Called must hold OVL_I(inode)->oi_lock */ +/* Caller must hold OVL_I(inode)->lock */ static void ovl_cleanup_index (struct dentry *dentry) {struct inode *dir =ovl_indexdir (dentry->d_sb)->d_inode;
@@ -466,9 +466,12 @@ static void ovl_cleanup_index(struct dentry *dentry)inode_lock_nested (dir,I_MUTEX_PARENT );/* TODO: whiteout instead of cleanup to block future open by handle */ index =lookup_one_len (name.name,ovl_indexdir (dentry->d_sb), name.len); - err =PTR_ERR (index); -if (!IS_ERR (index)) +if (!IS_ERR (index)) { err =ovl_cleanup (dir, index); + }else { + err =PTR_ERR (index); + index =NULL ; + }inode_unlock (dir);if (err) goto fail;
Signature · 1 line
2.7.4
Amir Goldstein
maintainerPATCH 4/4 ovl: fix dentry leak in ovl_indexdir_cleanup()
In reply to Amir Goldsteinindex dentry was not released when breaking out of the loop due to index verification error.
--- fs/overlayfs/readdir.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/overlayfs/readdir.c +4 -2
@@ -988,6 +988,7 @@ int ovl_indexdir_cleanup(struct dentry *dentry, struct vfsmount *mnt, struct path *lowerstack, unsigned int numlower) { int err; +struct dentry *index =NULL ;struct inode *dir = dentry->d_inode;struct path path = { .mnt = mnt, .dentry = dentry };LIST_HEAD (list);
@@ -1007,8 +1008,6 @@ int ovl_indexdir_cleanup(struct dentry *dentry, struct vfsmount *mnt,inode_lock_nested (dir,I_MUTEX_PARENT );list_for_each_entry (p, &list, l_node) { -struct dentry *index; -if (p->name[0 ] =='.' ) {if (p->len ==1 )continue ;
@@ -1018,6 +1017,7 @@ int ovl_indexdir_cleanup(struct dentry *dentry, struct vfsmount *mnt, index =lookup_one_len (p->name, dentry, p->len);if (IS_ERR (index)) { err =PTR_ERR (index); + index =NULL ;break ; } err =ovl_verify_index (index, lowerstack, numlower);
@@ -1029,7 +1029,9 @@ int ovl_indexdir_cleanup(struct dentry *dentry, struct vfsmount *mnt,break ; }dput (index); + index =NULL ; } +dput (index);inode_unlock (dir); out:ovl_cache_free (&list);
Signature · 1 line
2.7.4
Amir Goldstein
maintainerPATCH 5/5 ovl: fix missing unlock_rename() in ovl_do_copy_up()
In reply to Amir GoldsteinUse the ovl_lock_rename_workdir() helper which requires unlock_rename() only on lock success.
--- fs/overlayfs/copy_up.c | 6 ++---- fs/overlayfs/dir.c | 20 -------------------- fs/overlayfs/overlayfs.h | 1 + fs/overlayfs/util.c | 19 +++++++++++++++++++ 4 files changed, 22 insertions(+), 24 deletions(-)
fs/overlayfs/copy_up.c +2 -4
@@ -561,10 +561,8 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c) c->tmpfile = true; err =ovl_copy_up_locked (c); }else { - err = -EIO ; -if (lock_rename (c->workdir, c->destdir) !=NULL ) { -pr_err ("overlayfs: failed to lock workdir+upperdir\n" ); - }else { + err =ovl_lock_rename_workdir (c->workdir, c->destdir); +if (!err) { err =ovl_copy_up_locked (c);unlock_rename (c->workdir, c->destdir); }
fs/overlayfs/dir.c +0 -20
@@ -216,26 +216,6 @@ static int ovl_create_upper(struct dentry *dentry, struct inode *inode,return err; } -static int ovl_lock_rename_workdir (struct dentry *workdir, -struct dentry *upperdir) -{ -/* Workdir should not be the same as upperdir */ -if (workdir == upperdir) - goto err; - -/* Workdir should not be subdir of upperdir and vice versa */ -if (lock_rename (workdir, upperdir) !=NULL ) - goto err_unlock; - -return 0 ; - -err_unlock: -unlock_rename (workdir, upperdir); -err: -pr_err ("overlayfs: failed to lock workdir+upperdir\n" ); -return -EIO ; -} -static struct dentry *ovl_clear_empty (struct dentry *dentry,struct list_head *list) {
fs/overlayfs/overlayfs.h +1 -0
@@ -235,6 +235,7 @@ bool ovl_inuse_trylock(struct dentry *dentry);void ovl_inuse_unlock (struct dentry *dentry);int ovl_nlink_start (struct dentry *dentry,bool *locked);void ovl_nlink_end (struct dentry *dentry,bool locked); +int ovl_lock_rename_workdir (struct dentry *workdir,struct dentry *upperdir);static inline bool ovl_is_impuredir (struct dentry *dentry) {
fs/overlayfs/util.c +19 -0
@@ -560,3 +560,22 @@ void ovl_nlink_end(struct dentry *dentry, bool locked)mutex_unlock (&OVL_I (d_inode (dentry))->lock); } } + +int ovl_lock_rename_workdir (struct dentry *workdir,struct dentry *upperdir) +{ +/* Workdir should not be the same as upperdir */ +if (workdir == upperdir) + goto err; + +/* Workdir should not be subdir of upperdir and vice versa */ +if (lock_rename (workdir, upperdir) !=NULL ) + goto err_unlock; + +return 0 ; + +err_unlock: +unlock_rename (workdir, upperdir); +err: +pr_err ("overlayfs: failed to lock workdir+upperdir\n" ); +return -EIO ; +}
Signature · 1 line
2.7.4
Amir Goldstein
maintainerQuoted 4 lines · Amir Goldstein
Miklos,
Following are 1 fix for a commit in v4.14-rc1
and 3 fixes for index error paths in v4.13.
Make that 4 fixes to v4.13..
Available at https://github.com/amir73il/linux/commits/ovl-fixes
Quoted 8 lines
Amir.
Amir Goldstein (5):
ovl: fixmay_write_real()for overlayfs directories
ovl: fix error value printed inovl_lookup_index()
ovl: fixdput()ofERR_PTRinovl_cleanup_index()
ovl: fix dentry leak inovl_indexdir_cleanup()
+ ovl: fix missing unlock_rename() in ovl_do_copy_up()
Quoted 10 lines
fs/namespace.c | 4 +++- fs/overlayfs/namei.c | 1 + fs/overlayfs/readdir.c | 6 ++++-- fs/overlayfs/util.c | 9 ++++++--- 4 files changed, 14 insertions(+), 6 deletions(-)--
2.7.4