From patchwork Tue Jul 5 21:26:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Vagin X-Patchwork-Id: 9215227 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 3C3C360752 for ; Tue, 5 Jul 2016 21:27:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27F5A283F4 for ; Tue, 5 Jul 2016 21:27:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A3B32843C; Tue, 5 Jul 2016 21:27:32 +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 6EE0A283F4 for ; Tue, 5 Jul 2016 21:27:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755464AbcGEV12 (ORCPT ); Tue, 5 Jul 2016 17:27:28 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34065 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755374AbcGEV11 (ORCPT ); Tue, 5 Jul 2016 17:27:27 -0400 Received: by mail-pf0-f194.google.com with SMTP id 66so19967226pfy.1; Tue, 05 Jul 2016 14:27:27 -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=0aARhyXeUKs6ICDSOupsqEqY3RVaMoYyvqqw9auZ/8I=; b=UibgHWm+lyZDHZlYU+nG3wQuKFbQJom2fN8D/KEXNxCk52S6IyLIuo51/djOf9d+cg qRaIhW6SvXlcMuER9xMK2bs13hwt5S9s5N/uWFi3irONri/P9iHB5AtNBi9zTnta5SdL ThsM0+EIbCIaURKmZLSBxLCjEYD0Osbjwrspnea981pFpFZelJfJwzXnmL1u+7YHCaLL KjczzNto5YIgL5mqBYBtPb60vADMXeEII8CcAaTnxGODkWsyzdtQdPR8uXvEWa2bnvKZ L1WNeCzON+vy//RIADosTqL84rhKIdhZUAI/4Va7wGiDDkv/t3uCg9bzahEfsD5nuvBL h5hw== 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=0aARhyXeUKs6ICDSOupsqEqY3RVaMoYyvqqw9auZ/8I=; b=ZpVR/AAMa93ED3A3/r/0yB+mJzakUhf6Ep33atgE/aC6EwTE+qTiQ93gg/1alwasWr PFXBSVYu3/PakBPdXOYpliHz3K/m5ROsuLhCqhQQj9dFtSBaEBsFzG7wZJyK6F5CuYTv yyuZIOuiCWbWVK4YoeNmRNotSRvdKt2MqHpyEdCSBu3B8LLgLdD1wMAVookxtXxaQOsD HiBE6PN7Ci4MEk8ZtykiG+Ozb73qfyjhZU36v+m6eL3T1O4FMY9rWznoXm2gZ+u+ruyF LRltGeqS+3PlTEfnk9In80Gg8ceQrPlPTmnI3+96ff0Pbuu1xgc/YhwnxEeMmyPAXARZ QtvA== X-Gm-Message-State: ALyK8tKbmYMAijXO5WShht3HO0cOr0Cc/DApjHn5PZMr/AOPtWz/ps0ALYyB3f5A3BJEAw== X-Received: by 10.98.28.143 with SMTP id c137mr36040840pfc.131.1467754046525; Tue, 05 Jul 2016 14:27:26 -0700 (PDT) Received: from laptop.vz.com ([162.246.95.100]) by smtp.gmail.com with ESMTPSA id c78sm6678128pfk.11.2016.07.05.14.27.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Jul 2016 14:27:25 -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, Alexander Viro , "Eric W. Biederman" , Arnd Bergmann , "J. Bruce Fields" , Miklos Szeredi , NeilBrown , Shuah Khan , Omar Sandoval , Andrey Vagin Subject: [PATCH 1/3 v2] namei: add LOOKUP_DFD_ROOT to use dfd as root Date: Tue, 5 Jul 2016 14:26:58 -0700 Message-Id: <1467754018-29203-1-git-send-email-avagin@openvz.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <20160702005525.GA28451@vader.dhcp.thefacebook.com> References: <20160702005525.GA28451@vader.dhcp.thefacebook.com> 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. 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 70580ab..d52541a 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,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 */ @@ -2202,6 +2209,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 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);