Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1437303
| From | Andrey Vagin <avagin@openvz.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 1/3] namei: add LOOKUP_DFD_ROOT to use dfd as root |
| Date | 2016-07-05 23:40 +0200 |
| Message-ID | <rRGeu-8pR-25@gated-at.bofh.it> (permalink) |
| References | <rP59n-1Ba-3@gated-at.bofh.it> <rP59n-1Ba-7@gated-at.bofh.it> <rQhrQ-56b-13@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Fri, Jul 1, 2016 at 5:55 PM, Omar Sandoval <osandov@osandov.com> wrote:
> On Tue, Jun 28, 2016 at 10:38:28AM -0700, Andrey Vagin wrote:
>> The problem is that a pathname can contain absolute symlinks and now
>> they are resolved relative to the current root.
>>
>> If we want to open a file in another mount namespaces and we have a file
>> descriptor to its root directory, we probably want to resolve pathname
>> in the target mount namespace. For this we add this new flag.
>>
>> If LOOKUP_DFD_ROOT is set, path_init() initializes nd->root and nd->path
>> to the same value.
>>
>> Signed-off-by: Andrey Vagin <avagin@openvz.org>
>
> Hi, Andrey,
>
> Seems like a useful feature. Make sure to cc linux-api@vger.kernel.org
> for new userspace interfaces. One comment on the implementation below.
Hi Omar,
Thank you for the patch. I have sent a new version with your changes.
If there will not be other comments in a few days, I will resent a
whole seires with linux-api@vger.kernel.org in CC.
Thanks,
Andrew
>
>> ---
>> fs/namei.c | 12 +++++++++++-
>> include/linux/namei.h | 2 ++
>> 2 files changed, 13 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/namei.c b/fs/namei.c
>> index 70580ab..5f08b69 100644
>> --- a/fs/namei.c
>> +++ b/fs/namei.c
>> @@ -2148,7 +2148,7 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
>> nd->path.dentry = NULL;
>>
>> nd->m_seq = read_seqbegin(&mount_lock);
>> - if (*s == '/') {
>> + if (*s == '/' && !(flags & LOOKUP_DFD_ROOT)) {
>> if (flags & LOOKUP_RCU)
>> rcu_read_lock();
>> set_root(nd);
>> @@ -2174,6 +2174,11 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
>> get_fs_pwd(current->fs, &nd->path);
>> nd->inode = nd->path.dentry->d_inode;
>> }
>> + if (flags & LOOKUP_DFD_ROOT) {
>> + nd->root = nd->path;
>> + if (!(flags & LOOKUP_RCU))
>> + path_get(&nd->root);
>
> You're not initializing nd->root_seq here. That means that if we end up
> going through unlazy_walk(), we're going to call legitimize_path() (and
> thus read_seqcount_retry()) with stack garbage, get a spurious ECHILD,
> and do an unnecessary restart of the path lookup instead of dropping
> into ref-walk mode.
>
>> + }
>> return s;
>> } else {
>> /* Caller must check execute permissions on the starting path component */
>> @@ -2202,6 +2207,11 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
>> nd->inode = nd->path.dentry->d_inode;
>> }
>> fdput(f);
>> + if (flags & LOOKUP_DFD_ROOT) {
>> + nd->root = nd->path;
>> + if (!(flags & LOOKUP_RCU))
>> + path_get(&nd->root);
>> + }
>
> Same here.
>
> The following should do the trick:
>
> diff --git a/fs/namei.c b/fs/namei.c
> index 9958b605e822..101d1fb8d3cb 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -2176,7 +2176,9 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
> }
> if (flags & LOOKUP_DFD_ROOT) {
> nd->root = nd->path;
> - if (!(flags & LOOKUP_RCU))
> + if (flags & LOOKUP_RCU)
> + nd->root_seq = nd->seq;
> + else
> path_get(&nd->root);
> }
> return s;
> @@ -2209,7 +2211,9 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
> fdput(f);
> if (flags & LOOKUP_DFD_ROOT) {
> nd->root = nd->path;
> - if (!(flags & LOOKUP_RCU))
> + if (flags & LOOKUP_RCU)
> + nd->root_seq = nd->seq;
> + else
> path_get(&nd->root);
> }
> return s;
>
> --
> Omar
> _______________________________________________
> Containers mailing list
> Containers@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/containers
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/3 v2] fs: allow to use dirfd as root for openat and other *at syscalls Andrey Vagin <avagin@openvz.org> - 2016-06-28 19:40 +0200
[PATCH 1/3] namei: add LOOKUP_DFD_ROOT to use dfd as root Andrey Vagin <avagin@openvz.org> - 2016-06-28 19:40 +0200
Re: [PATCH 1/3] namei: add LOOKUP_DFD_ROOT to use dfd as root Omar Sandoval <osandov@osandov.com> - 2016-07-02 03:00 +0200
[PATCH 1/3 v2] namei: add LOOKUP_DFD_ROOT to use dfd as root Andrey Vagin <avagin@openvz.org> - 2016-07-05 23:30 +0200
Re: [PATCH 1/3] namei: add LOOKUP_DFD_ROOT to use dfd as root Andrey Vagin <avagin@openvz.org> - 2016-07-05 23:40 +0200
[PATCH 3/3] selftests: check O_ATROOT and AT_FDROOT flags Andrey Vagin <avagin@openvz.org> - 2016-06-28 19:40 +0200
[PATCH 2/3] fs: allow to use dirfd as root for openat and other *at syscalls Andrey Vagin <avagin@openvz.org> - 2016-06-28 19:40 +0200
csiph-web