From patchwork Tue Jun 28 17:38:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Vagin X-Patchwork-Id: 9203715 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 34CC56074E for ; Tue, 28 Jun 2016 17:40:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27B8D28610 for ; Tue, 28 Jun 2016 17:40:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A8A728613; Tue, 28 Jun 2016 17:40:03 +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=unavailable 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 A505528610 for ; Tue, 28 Jun 2016 17:40:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752622AbcF1Rj1 (ORCPT ); Tue, 28 Jun 2016 13:39:27 -0400 Received: from mail-pa0-f67.google.com ([209.85.220.67]:33930 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752395AbcF1RjW (ORCPT ); Tue, 28 Jun 2016 13:39:22 -0400 Received: by mail-pa0-f67.google.com with SMTP id us13so2183869pab.1; Tue, 28 Jun 2016 10:39:08 -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=OIluVvGlcSNbuL/toy1gVmwFM3JBPB+kFqnEC3Wgg04=; b=TiPmSs6ASWzXGaK9Fell3oIko/0y4UJ6J91kWmA4uCirCat2DrO+2YiXmJlxL+uYDf xRQnj2n6HGJ6EHADsD0wewM2IhP1YHrBfQrDBomUUK3PsdAewV5R13W9VlYrZJgBcHIn kGFfKqVVNFLQ9ZmHbBiDOxdJ+mo/kQw10+BfH7TjhNo9RuLfadOpn2zeUOyERPxMfuNg +7YiLaVoG+IQJsvQvvEE3rLD3yUfhHYU1xkpuuRfyYyEHCbvFJ9zDVOIadX9yFKUxnp3 SlEAA47OSy+oecGeMzbW1bX2NCVjh9TQUIVFK0UHvHDqeUVVmQQoN+Rbx8mMRVBzp+zk STsw== 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=OIluVvGlcSNbuL/toy1gVmwFM3JBPB+kFqnEC3Wgg04=; b=P5a/QM5BxkO9NiEYBZCExT3TNaRIWvBgp7PldroJ3xgAenZDAv+vP/cfxET2gZpkwq EQgUV6lGGHgrbz3vFIHuTvwOnipylYYjISfWMnvPOphcC3L0jkOgJC5vnLP4DnjYbT/3 zudfxSGFmdezaFeBZDtu9XoHrLgzkw5eYyY05+nC/YLmUACs3oeoTlywzDEe67k94aiv 2CALx1QCBuzi/DuGMgOaP9Es0MGrdVkMwZ40Cgnf0mSNZh7LG1wN1Qrls2F40aQYga4G /pvYzBwLJyboOqxsds0ZYht4Xl1TomJyFWdipgKGJUe68orT+FCXquD92y7VCDdtOU1o YeFA== X-Gm-Message-State: ALyK8tLS8VI/isO1nKgc/0/c0ryay4cuvqN/2FoHeexOoqKJbKsZ1+q/FASTPPET65EZPA== X-Received: by 10.67.23.197 with SMTP id ic5mr3851134pad.127.1467135547790; Tue, 28 Jun 2016 10:39:07 -0700 (PDT) Received: from laptop.vz.com ([162.246.95.100]) by smtp.gmail.com with ESMTPSA id 69sm458114pfc.90.2016.06.28.10.39.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jun 2016 10:39:07 -0700 (PDT) From: Andrey Vagin To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, criu@openvz.org, containers@lists.linux-foundation.org, Andrey Vagin , Alexander Viro , "Eric W. Biederman" , Arnd Bergmann , "J. Bruce Fields" , Miklos Szeredi , NeilBrown , Shuah Khan Subject: [PATCH 1/3] namei: add LOOKUP_DFD_ROOT to use dfd as root Date: Tue, 28 Jun 2016 10:38:28 -0700 Message-Id: <1467135510-2564-2-git-send-email-avagin@openvz.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1467135510-2564-1-git-send-email-avagin@openvz.org> References: <1467135510-2564-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. If LOOKUP_DFD_ROOT is set, path_init() initializes nd->root and nd->path to the same value. 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);