[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220901123350.wak7yjbvddtcnwfb@wittgenstein>
Date: Thu, 1 Sep 2022 14:33:50 +0200
From: Christian Brauner <brauner@...nel.org>
To: Zhang Tianci <zhangtianci.1997@...edance.com>
Cc: miklos@...redi.hu, linux-unionfs@...r.kernel.org,
linux-kernel@...r.kernel.org, amir73il@...il.com,
Jiachen Zhang <zhangjiachen.jaycee@...edance.com>
Subject: Re: [PATCH v3] ovl: Use ovl mounter's fsuid and fsgid in ovl_link()
On Thu, Sep 01, 2022 at 04:29:29PM +0800, Zhang Tianci wrote:
> There is a wrong case of link() on overlay:
> $ 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 we will get an error(EACCES) because fuse daemon checks the link()'s
> caller is "bin", it denied this request.
>
> In 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. This is acceptable
> to use the caller's fsuid.
>
> 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
> mounter! So this is incorrect.
>
> Fix this bug by using ovl mounter's fsuid/fsgid to do underlying
> fs's link().
>
> v1: https://lore.kernel.org/all/20220817102952.xnvesg3a7rbv576x@wittgenstein/T
> v2: https://lore.kernel.org/lkml/20220825130552.29587-1-zhangtianci.1997@bytedance.com/t
>
> Signed-off-by: Zhang Tianci <zhangtianci.1997@...edance.com>
> Signed-off-by: Jiachen Zhang <zhangjiachen.jaycee@...edance.com>
> ---
Looks good to me,
Reviewed-by: Christian Brauner (Microsoft) <brauner@...nel.org>
Powered by blists - more mailing lists