Skip to content

Commit 91ff20f

Browse files
amir73ilMiklos Szeredi
authored andcommitted
ovl: fix missing override creds in link of a metacopy upper
Theodore Ts'o reported a v4.19 regression with docker-dropbox: https://marc.info/?l=linux-fsdevel&m=154070089431116&w=2 "I was rebuilding my dropbox Docker container, and it failed in 4.19 with the following error: ... dpkg: error: error creating new backup file \ '/var/lib/dpkg/status-old': Invalid cross-device link" The problem did not reproduce with metacopy feature disabled. The error was caused by insufficient credentials to set "trusted.overlay.redirect" xattr on link of a metacopy file. Reproducer: echo Y > /sys/module/overlay/parameters/redirect_dir echo Y > /sys/module/overlay/parameters/metacopy cd /tmp mkdir l u w m chmod 777 l u touch l/foo ln l/foo l/link chmod 666 l/foo mount -t overlay none -olowerdir=l,upperdir=u,workdir=w m su fsgqa ln m/foo m/bar [ 21.455823] overlayfs: failed to set redirect (-1) ln: failed to create hard link 'm/bar' => 'm/foo':\ Invalid cross-device link Reported-by: Theodore Y. Ts'o <tytso@mit.edu> Reported-by: Maciej Zięba <maciekz82@gmail.com> Fixes: 4120fe6 ("ovl: Set redirect on upper inode when it is linked") Cc: <stable@vger.kernel.org> # v4.19 Signed-off-by: Amir Goldstein <amir73il@gmail.com> Acked-by: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 9ff0119 commit 91ff20f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

fs/overlayfs/dir.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,18 @@ static int ovl_symlink(struct inode *dir, struct dentry *dentry,
651651
return ovl_create_object(dentry, S_IFLNK, 0, link);
652652
}
653653

654+
static int ovl_set_link_redirect(struct dentry *dentry)
655+
{
656+
const struct cred *old_cred;
657+
int err;
658+
659+
old_cred = ovl_override_creds(dentry->d_sb);
660+
err = ovl_set_redirect(dentry, false);
661+
revert_creds(old_cred);
662+
663+
return err;
664+
}
665+
654666
static int ovl_link(struct dentry *old, struct inode *newdir,
655667
struct dentry *new)
656668
{
@@ -670,7 +682,7 @@ static int ovl_link(struct dentry *old, struct inode *newdir,
670682
goto out_drop_write;
671683

672684
if (ovl_is_metacopy_dentry(old)) {
673-
err = ovl_set_redirect(old, false);
685+
err = ovl_set_link_redirect(old);
674686
if (err)
675687
goto out_drop_write;
676688
}

0 commit comments

Comments
 (0)