From patchwork Sat Jul 2 00:55:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9210645 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 3ECD4607D8 for ; Sat, 2 Jul 2016 00:55:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F5FE286D1 for ; Sat, 2 Jul 2016 00:55:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21AD8286A4; Sat, 2 Jul 2016 00:55:58 +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 9E828286A4 for ; Sat, 2 Jul 2016 00:55:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932086AbcGBAza (ORCPT ); Fri, 1 Jul 2016 20:55:30 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:34996 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752565AbcGBAz2 (ORCPT ); Fri, 1 Jul 2016 20:55:28 -0400 Received: by mail-pa0-f48.google.com with SMTP id hl6so42917310pac.2 for ; Fri, 01 Jul 2016 17:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=hZN3W/qW34/xwG8fPaKIDvISMdyue6Yt8L/qqDc/6MM=; b=E7+U8cuNB/R5QwrZ2F2seYolWPZiEHKAKlfrhLT9ov1sNt0Lz9vKmHb6AC4WGdyFi3 HL1XVn2cSBlDIJ7R5fceXkGEgQsJqRP4D4bAOkKV4QNQIIH7378Ku6vNAjyZGYxvioN9 d7wxY8xpa2cSESaQjTqkth19R7TTgwX/IdBs/R5ipdBlawsbn79jQeW/92jjDCfQq2g4 yQadmyAmsd+oix3fOZvzhm08Ci+iP+dZ2rfg62JFRlN8IBQsLP7b+ymZYrfVkjhh3FlN 2sbSHjKwxsXlQ9l1obmBBPcMLeT36krxlUB3LHwCcmmS75fYQ1DZX1T9UbHttgUc9dfr EXYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=hZN3W/qW34/xwG8fPaKIDvISMdyue6Yt8L/qqDc/6MM=; b=Bkybb9387rB/IB9G9htL2a0S47jiR/FmYskYVyKGCKSRDtYSztqfigz3WnDCGV0Ylr WaF4AgUz//YaWZJuZGV4+JisxHeBSaUecM2xqpZrY6J74b3qnH289IdVU97PIQQR2e+Q T7V1GYY4YY7YX5AtzCxEANeRVP7/RQIc6rr0w0Oiq5AAtGX/BJeZYsiyI2VldMBOSC5i Wb1jpxLKEsyqOwa5UksRvq9iG/u2LyDPlfrrRfOS4YieBwTJM5CnmOBZsucbKJjJz6NG CFEpQpOXB8PSjwxxsCfbpyRTM/g2JFgbLAaHyVpAmn4X0hGmCSkwKK7y6sbeEX7l9gu/ 8Cww== X-Gm-Message-State: ALyK8tLHmr//JAHgJicTotQJ/LFjyA8GwmkiLWuIjz2Ev5ex1SsItzNf4JAktLxYFUdR8hIZ X-Received: by 10.66.43.203 with SMTP id y11mr1849656pal.96.1467420927822; Fri, 01 Jul 2016 17:55:27 -0700 (PDT) Received: from vader.dhcp.thefacebook.com ([2620:10d:c090:200::9:7db5]) by smtp.gmail.com with ESMTPSA id a188sm624500pfa.70.2016.07.01.17.55.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jul 2016 17:55:27 -0700 (PDT) Date: Fri, 1 Jul 2016 17:55:25 -0700 From: Omar Sandoval To: Andrey Vagin Cc: linux-fsdevel@vger.kernel.org, Miklos Szeredi , "J. Bruce Fields" , Arnd Bergmann , NeilBrown , containers@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Shuah Khan , criu@openvz.org, "Eric W. Biederman" , Alexander Viro Subject: Re: [PATCH 1/3] namei: add LOOKUP_DFD_ROOT to use dfd as root Message-ID: <20160702005525.GA28451@vader.dhcp.thefacebook.com> References: <1467135510-2564-1-git-send-email-avagin@openvz.org> <1467135510-2564-2-git-send-email-avagin@openvz.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1467135510-2564-2-git-send-email-avagin@openvz.org> User-Agent: Mutt/1.6.1 (2016-04-27) 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 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 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. > --- > 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;