Skip to content

Commit 2c3ef4f

Browse files
committed
ovl: initialize ovl_copy_up_ctx.destname inside ovl_do_copy_up()
The ->destname member of struct ovl_copy_up_ctx is initialized inside ovl_copy_up_one() to ->d_name of the overlayfs dentry being copied up and then it may be overridden by index name inside ovl_do_copy_up(). ovl_inode_lock() in ovl_copy_up_start() and ovl_copy_up() in ovl_rename() effectively stabilze ->d_name of the overlayfs dentry being copied up, but ovl_inode_lock() is not held when ->d_name is being read. It is not a correctness bug, because if ovl_do_copy_up() races with ovl_rename() and ctx.destname is freed, we will not end up calling ovl_do_copy_up() with the dead name reference. The code becomes much easier to understand and to document if the initialization of c->destname is always done inside ovl_do_copy_up(), either to the index entry name, or to the overlay dentry ->d_name. Signed-off-by: Amir Goldstein <[email protected]>
1 parent 02d7009 commit 2c3ef4f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

fs/overlayfs/copy_up.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,13 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
929929
err = -EIO;
930930
goto out_free_fh;
931931
} else {
932+
/*
933+
* c->dentry->d_name is stabilzed by ovl_copy_up_start(),
934+
* because if we got here, it means that c->dentry has no upper
935+
* alias and changing ->d_name means going through ovl_rename()
936+
* that will call ovl_copy_up() on source and target dentry.
937+
*/
938+
c->destname = c->dentry->d_name;
932939
/*
933940
* Mark parent "impure" because it may now contain non-pure
934941
* upper
@@ -1109,7 +1116,6 @@ static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
11091116
if (parent) {
11101117
ovl_path_upper(parent, &parentpath);
11111118
ctx.destdir = parentpath.dentry;
1112-
ctx.destname = dentry->d_name;
11131119

11141120
err = vfs_getattr(&parentpath, &ctx.pstat,
11151121
STATX_ATIME | STATX_MTIME,

0 commit comments

Comments
 (0)