lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAP4dvsfqxEGJtQgSdfN+nxbyMAdm2rj_tmUeqXc8syPyK98MHA@mail.gmail.com>
Date:   Wed, 17 Aug 2022 17:11:40 +0800
From:   天赐张 <zhangtianci.1997@...edance.com>
To:     Amir Goldstein <amir73il@...il.com>
Cc:     Miklos Szeredi <miklos@...redi.hu>,
        overlayfs <linux-unionfs@...r.kernel.org>,
        linux-kernel <linux-kernel@...r.kernel.org>,
        Jiachen Zhang <zhangjiachen.jaycee@...edance.com>
Subject: Re: [External] Re: [PATCH] ovl: Do not override fsuid and fsgid in ovl_link()

On Wed, Aug 17, 2022 at 3:36 PM Amir Goldstein <amir73il@...il.com> wrote:
>
> On Wed, Aug 17, 2022 at 6:49 AM Zhang Tianci
> <zhangtianci.1997@...edance.com> wrote:
> >
> > ovl_link() did not create a new inode after commit
> > 51f7e52dc943 ("ovl: share inode for hard link"), so
> > in ovl_create_or_link() we should not override cred's
> > fsuid and fsgid when called by ovl_link().
> >
> > Signed-off-by: Zhang Tianci <zhangtianci.1997@...edance.com>
> > Signed-off-by: Jiachen Zhang <zhangjiachen.jaycee@...edance.com>
> > ---
> >  fs/overlayfs/dir.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
> > index 6b03457f72bb..568d338032db 100644
> > --- a/fs/overlayfs/dir.c
> > +++ b/fs/overlayfs/dir.c
> > @@ -595,9 +595,9 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
> >         err = -ENOMEM;
> >         override_cred = prepare_creds();
> >         if (override_cred) {
> > -               override_cred->fsuid = inode->i_uid;
> > -               override_cred->fsgid = inode->i_gid;
> >                 if (!attr->hardlink) {
> > +                       override_cred->fsuid = inode->i_uid;
> > +                       override_cred->fsgid = inode->i_gid;
> >                         err = security_dentry_create_files_as(dentry,
> >                                         attr->mode, &dentry->d_name, old_cred,
> >                                         override_cred);
> > --
>
> This change looks incorrect.
> Unless I am missing something, fsuid/fsgid still need to
> be overridden for calling link() on underlying fs.
> What made you do this change?
>
> Thanks,
> Amir.

Hi Amir,

I ran into an error when I tested overlay on fuse:
  $ mkdir /lower /fuse /merge
  $ mount -t fuse /fuse
  $ mkdir /fuse/upper /fuse/work
  $ mount -t overlay /merge -o lowerdir=/lower,upperdir=/fuse/upper,workdir=work
  $ touch /merge/file
  $ chown bin.bin /merge/file // the file's caller becomes "bin"
  $ ln /merge/file /merge/lnkfile

Then I got an error(EACCES) because fuse daemon checks the link()'s
caller is "bin", it denied this request.
I browsed the changing history of ovl_link(). There are two key commits:
The first is commit bb0d2b8ad296 ("ovl: fix sgid on directory") which
overrides the cred's fsuid/fsgid using the new inode. The new inode's
owner is initialized by inode_init_owner(), and inode->fsuid is
assigned to the current user. So the override fsuid becomes the
current user. We know link() is actually modifying the directory, so
the caller must have the MAY_WRITE permission on the directory. The
current caller may should have this permission. I think this is
acceptable to use the caller's fsuid(But I still feel a little
conflicted with the overlay's design).
The second is commit 51f7e52dc943 ("ovl: share inode for hard link")
which removed the inode creation in ovl_link(). This commit move
inode_init_owner() into ovl_create_object(), so the ovl_link() just
give the old inode to ovl_create_or_link(). Then the override fsuid
becomes the old inode's fsuid, neither the caller nor the overlay's
creator! So I think this is incorrect.
I think the link() should be like unlink(), overlay fs should just use
the creator cred to do underlying fs's operations.

Thanks,
Tianci.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ