From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755282AbcGTUn2 (ORCPT ); Wed, 20 Jul 2016 16:43:28 -0400 Received: from mail-pa0-f68.google.com ([209.85.220.68]:34298 "EHLO mail-pa0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754188AbcGTUnX (ORCPT ); Wed, 20 Jul 2016 16:43:23 -0400 From: Andrey Vagin To: linux-fsdevel@vger.kernel.org, Alexander Viro Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, containers@lists.linux-foundation.org, criu@openvz.org, Andrey Vagin , "Eric W. Biederman" , Arnd Bergmann , "J. Bruce Fields" , Miklos Szeredi , NeilBrown , Shuah Khan , Omar Sandoval Subject: [PATCH 1/3 v2] namei: add LOOKUP_DFD_ROOT to use dfd as root Date: Wed, 20 Jul 2016 13:42:55 -0700 Message-Id: <1469047377-13128-2-git-send-email-avagin@openvz.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1469047377-13128-1-git-send-email-avagin@openvz.org> References: <1469047377-13128-1-git-send-email-avagin@openvz.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Changes since v1: * initialize nd->root_seq (thanks to Omar Sandoval for reporting and fixing this issue) Cc: Omar Sandoval Signed-off-by: Andrey Vagin --- fs/namei.c | 16 +++++++++++++++- include/linux/namei.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/fs/namei.c b/fs/namei.c index 28cb1cd..17548b1 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2141,7 +2141,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); @@ -2167,6 +2167,13 @@ 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) + nd->root_seq = nd->seq; + else + path_get(&nd->root); + } return s; } else { /* Caller must check execute permissions on the starting path component */ @@ -2195,6 +2202,13 @@ 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) + nd->root_seq = nd->seq; + else + path_get(&nd->root); + } return s; } } diff --git a/include/linux/namei.h b/include/linux/namei.h index ec5ec28..59ca78c 100644 --- a/include/linux/namei.h +++ b/include/linux/namei.h @@ -45,6 +45,8 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND}; #define LOOKUP_ROOT 0x2000 #define LOOKUP_EMPTY 0x4000 +#define LOOKUP_DFD_ROOT 0x8000 + extern int user_path_at_empty(int, const char __user *, unsigned, struct path *, int *empty); static inline int user_path_at(int dfd, const char __user *name, unsigned flags, -- 2.5.5