Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2954520imm; Thu, 24 May 2018 19:49:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq7piP0y79nR6itqWdpHMAzYeywa5MBm8Eu/PSwenMTEK+NeYNzNbp6r8Bv5DnGGhcq/j6r X-Received: by 2002:a62:d352:: with SMTP id q79-v6mr608879pfg.45.1527216573100; Thu, 24 May 2018 19:49:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527216573; cv=none; d=google.com; s=arc-20160816; b=JznqI22UBa/V+Fuh2A07rs1gOa5U8tNADceFoVvs3Utcj0be+cLn6X6irs4JJDZxoL wD9TzMP+0uiyH0YQLlwer8raUuzme2YtAHS1Po++FOPX1/+hQB17K70GubJrx7BGFR1N DXYl9J6LY6YxP7IbpWIsk7gVzewaLlvtlPg0gJNoBys+TBCZ8FoaFKqYsbGtzvHNqrY7 RNFD3BHETIsKk060TofaMqtma07S9NnAysIR6WnPGGuzUYC96s9rwAM40fzNg04k1fsx CqUwhDWxCg9ptu/n/MunpM5b66JCKD8UY9Z6uHFdY10zu3BeqttylzxxZMLVF83qcTfs hugg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:arc-authentication-results; bh=xv3gDRf5722Dj5kzkrV5wyWo86XTGgaDhqOdcSPKkmA=; b=KIPsT2SeT22KpB4yaWoooYNz8tzEd6Z9yj0y/59GawtojAePXP41BE0jvU/GGnYOE2 aw7pyqjWP8BU5Z7qWgO1sWBOFaQjbtZg0NMRk04jbvZ+H8QrT6C0pbTY2ve6Xw/IJWU9 5pMvu9pC7jdGNnv7sAABl2S2YJHE/BQUYLG4OvjiyzNc/NpWX6xPaCPw6y4suM7H8DV2 AY+tV42PtynNQ5JqRl8nq5IhL9cAomGcbCbIsiHIUb6+XLTTMHv38zcFOJZH+z14DHuN xawo+O6xvaWM1HlD+eEzCAOe2Ta9NZ4jzl6DOwmhrcwdRiLgu5cQLGAiSyyhGpPCFxHM Rivw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u10-v6si3484754plr.553.2018.05.24.19.49.18; Thu, 24 May 2018 19:49:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S971923AbeEYAI3 (ORCPT + 99 others); Thu, 24 May 2018 20:08:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36048 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965178AbeEYAI1 (ORCPT ); Thu, 24 May 2018 20:08:27 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CF3DC12AD; Fri, 25 May 2018 00:08:26 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-255.rdu2.redhat.com [10.10.120.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id B817D10EE6C1; Fri, 25 May 2018 00:08:25 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 28/32] vfs: Store the fd_cookie in nameidata, not the dfd int [ver #8] From: David Howells To: viro@zeniv.linux.org.uk Cc: dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org Date: Fri, 25 May 2018 01:08:25 +0100 Message-ID: <152720690524.9073.15509053519638438137.stgit@warthog.procyon.org.uk> In-Reply-To: <152720672288.9073.9868393448836301272.stgit@warthog.procyon.org.uk> References: <152720672288.9073.9868393448836301272.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 25 May 2018 00:08:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 25 May 2018 00:08:26 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Look up dfd in set_nameidata() if not AT_FDCWD and store the resultant fd_cookie in struct nameidata. LOOKUP_AT_FDCWD is set if AT_FDCWD was supplied. The fd_cookie is released in restore_nameidata(). This means that where the fd points in a construct like the following: set_nameidata(&nd, dfd, name); retval = path_lookupat(&nd, flags | LOOKUP_RCU, path); if (unlikely(retval == -ECHILD)) retval = path_lookupat(&nd, flags, path); if (unlikely(retval == -ESTALE)) retval = path_lookupat(&nd, flags | LOOKUP_REVAL, path); doesn't change between the three calls to path_lookupat() or similar. It also allows us to fish the fd_cookie out for the upcoming move_mount() syscall which needs to clear a file flag if successful. Signed-off-by: David Howells --- fs/namei.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 6f0dc40f88c5..819d6ee71b46 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -53,8 +53,8 @@ * The new code replaces the old recursive symlink resolution with * an iterative one (in case of non-nested symlink chains). It does * this with calls to _follow_link(). - * As a side effect, dir_namei(), _namei() and follow_link() are now - * replaced with a single function lookup_dentry() that can handle all + * As a side effect, dir_namei(), _namei() and follow_link() are now + * replaced with a single function lookup_dentry() that can handle all * the special cases of the former code. * * With the new dcache, the pathname is stored at each inode, at least as @@ -506,25 +506,34 @@ struct nameidata { struct filename *name; struct nameidata *saved; struct inode *link_inode; + struct fd_cookie *dfd; + bool have_dfd; unsigned root_seq; - int dfd; } __randomize_layout; static void set_nameidata(struct nameidata *p, int dfd, struct filename *name) { struct nameidata *old = current->nameidata; p->stack = p->internal; - p->dfd = dfd; p->name = name; p->total_link_count = old ? old->total_link_count : 0; p->saved = old; current->nameidata = p; + + if (likely(dfd == AT_FDCWD)) { + p->dfd = NULL; + p->have_dfd = false; + } else { + p->dfd = __fdget_raw(dfd); /* Error are dealt with later */ + p->have_dfd = true; + } } static void restore_nameidata(void) { struct nameidata *now = current->nameidata, *old = now->saved; + __fdput(now->dfd); current->nameidata = old; if (old) old->total_link_count = now->total_link_count; @@ -2165,7 +2174,7 @@ static const char *path_init(struct nameidata *nd, unsigned flags) nd->root.mnt = NULL; rcu_read_unlock(); return ERR_PTR(-ECHILD); - } else if (nd->dfd == AT_FDCWD) { + } else if (!nd->have_dfd) { if (flags & LOOKUP_RCU) { struct fs_struct *fs = current->fs; unsigned seq; @@ -2185,22 +2194,18 @@ static const char *path_init(struct nameidata *nd, unsigned flags) return s; } else { /* Caller must check execute permissions on the starting path component */ - struct fd f = fdget_raw(nd->dfd); struct dentry *dentry; + struct file *file = __fdfile(nd->dfd); - if (!f.file) + if (!nd->dfd) return ERR_PTR(-EBADF); - dentry = f.file->f_path.dentry; + dentry = file->f_path.dentry; - if (*s) { - if (!d_can_lookup(dentry)) { - fdput(f); - return ERR_PTR(-ENOTDIR); - } - } + if (*s && !d_can_lookup(dentry)) + return ERR_PTR(-ENOTDIR); - nd->path = f.file->f_path; + nd->path = file->f_path; if (flags & LOOKUP_RCU) { rcu_read_lock(); nd->inode = nd->path.dentry->d_inode; @@ -2209,7 +2214,6 @@ static const char *path_init(struct nameidata *nd, unsigned flags) path_get(&nd->path); nd->inode = nd->path.dentry->d_inode; } - fdput(f); return s; } } @@ -3557,7 +3561,7 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt, if (IS_ERR(filename)) return ERR_CAST(filename); - set_nameidata(&nd, -1, filename); + set_nameidata(&nd, AT_FDCWD, filename); file = path_openat(&nd, op, flags | LOOKUP_RCU); if (unlikely(file == ERR_PTR(-ECHILD))) file = path_openat(&nd, op, flags);