From patchwork Fri Jun 17 20:20:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Vagin X-Patchwork-Id: 9184927 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5FFBD6075F for ; Fri, 17 Jun 2016 20:21:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 327D427EED for ; Fri, 17 Jun 2016 20:21:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26DE4280DE; Fri, 17 Jun 2016 20:21:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B89ED27EED for ; Fri, 17 Jun 2016 20:21:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932106AbcFQUVc (ORCPT ); Fri, 17 Jun 2016 16:21:32 -0400 Received: from mail-pa0-f66.google.com ([209.85.220.66]:34375 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752886AbcFQUU6 (ORCPT ); Fri, 17 Jun 2016 16:20:58 -0400 Received: by mail-pa0-f66.google.com with SMTP id us13so6358077pab.1; Fri, 17 Jun 2016 13:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Xgwf4cjLuKJqSOYXUP25v/9i+jjhNe/zuIZq1dJMBRk=; b=VbT2pTVyJMbm07ZcK0R5aCYyO+PVhTy7zHB5jKfoFM8hyQOaZonvI4MG1ehOkNlIAS D4Mo9PF4TdEOsupp0mCJIfwonKYriEQGT9hbfTrecpKAOp3qO3SCYZNPcSIEq1yYK668 waaAcbbyB4QOrVWoWrPlg/BUFEeD9puxLqYlBDEG6CoM19wEX3toBcuVi/C7eHFCeXLU tFnl9BlPYyCOVQYhhFS/5UYnUZyTKHHMZRSzYFVMR+KWkYlm+QtIZ5+M0gVqmB4Ix2vd wCtHjENuQ/0Vx/wF1FzNL2YIrWhisJYgE87+GnwgrHQiV9qpBka+PLoSJcfQKSf0dc9M umjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Xgwf4cjLuKJqSOYXUP25v/9i+jjhNe/zuIZq1dJMBRk=; b=UKJiweY95dcb/eDt9k5FfqKhn4Ymotoi37zO6XfbbFOtW6j7he75uoYt6U1EjzHlHG SDBKIvGKXar4bjqNpkdPkAXx9hbKLkvFOfAeMkMVChf3UJrTlTuRsjmlLj3lDvmwvTs+ uy5BnK9L7exCc4hznwp6tAnP+bSNC37A4puNLzIrZ6rzUVxcTzomJpp61o6HV2a8Xl4g 0MIEjmqvNUwLownvemD9+bOdFWq0vv/DmW53BNEk4CBGjHNLAVEhWCX3msp/8FEj5MId Zjd2g/ek8iUSvRfbqB8NypDqOIzJlJoA+YhVz1BpD8fiOhTZGVMvT2jV9kDIsMil/pBG 2KyA== X-Gm-Message-State: ALyK8tI9p+yt4zNBm73b9QIkszNXEoPMjPVtDnhIr9gkb2f/vtOYxzQWZa2HX9RTfJZ0Cw== X-Received: by 10.66.27.136 with SMTP id t8mr4323839pag.108.1466194857615; Fri, 17 Jun 2016 13:20:57 -0700 (PDT) Received: from laptop.vz.com ([162.246.95.100]) by smtp.gmail.com with ESMTPSA id s86sm70280827pfi.69.2016.06.17.13.20.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jun 2016 13:20:57 -0700 (PDT) From: Andrey Vagin To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Andrey Vagin , Alexander Viro , "Eric W. Biederman" Subject: [PATCH 1/2] namei: add LOOKUP_DFD_ROOT to use dfd as root Date: Fri, 17 Jun 2016 13:20:47 -0700 Message-Id: <1466194848-13824-2-git-send-email-avagin@openvz.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1466194848-13824-1-git-send-email-avagin@openvz.org> References: <1466194848-13824-1-git-send-email-avagin@openvz.org> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Andrey Vagin --- 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); + } 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); + } return s; } } diff --git a/include/linux/namei.h b/include/linux/namei.h index d3d0398..ca2ea13 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 path_pts(struct path *path); extern int user_path_at_empty(int, const char __user *, unsigned, struct path *, int *empty);