Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp619930imu; Tue, 27 Nov 2018 03:58:01 -0800 (PST) X-Google-Smtp-Source: AFSGD/WV4dZawOeoWYcJx3SW0GbUidWMYxYfUbz7mupLL3W1zZzJuDafjy6o0JA0jBfh+2EVCsFC X-Received: by 2002:a17:902:1122:: with SMTP id d31-v6mr32339575pla.259.1543319881540; Tue, 27 Nov 2018 03:58:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543319881; cv=none; d=google.com; s=arc-20160816; b=H4XkqP4BVQdVIFaEo827nrs539ixXtzJhJkCDZpjRDrc3e129Q3ZD4/ATcHHbKYq4o m5nuBK+A1rsbFU3L8g45IJOygEhsSMXSZQn0I8WQDQp3hvkZwsUc9rpE31ETAjxjUpSd otRSKkoyvykOcVlM2NHJJpb6ZVyiHjZRkUJixQK/wcM3c31EoE5WWC4VFBaz9Ci9shPF 4RfXoPZFrQTwMg7bdAvILTfK1WnF/DLWHAshjUEo8mcnSxkCRTkktxoGgFN7Gb6Oo4ur hRa2A5ToMagfzHt/ulsFoiKGe+Gu1J29atWvgICmdKax3TX2io1YHxDIDmlfOrDi3Fng nHxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=ZnzyOcQyoiiHH6J4MMHT8p8+w3Fdx9yxY66n4oJl0S8=; b=xGtmyzd6INC0xK2qttLT1IoItCpXIiBmhy1moyDNs/fzx3TMtOYRpKFh7AQVv7tgDT GDKMeuWlw0iRYZS1MFVtxATrXHtQ6c+AEVGmPM18uSME60tsW08Cq8H72hTzQOSpYX6O aP1Kc4e9L7Sa0zkVuhto3ObgljgYJPvUMdeqBa/pwzTro3bNIamfmjTR/1YUxeDVP3oM WIFx5tPNvpzdenN0JYZ46QEew3xUo46vpEBFxXxkPZig7h9xml5f584+C/ESXIgm5Q8i agP2sQe3F9hHKOyQZkjPXgF/dgbyegnH7KhcMG/pbQAF69iqXhQkPhTLSlqFjAnYvjBE VgAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=jyhq4+Bp; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si3704841pll.297.2018.11.27.03.57.45; Tue, 27 Nov 2018 03:58:01 -0800 (PST) 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; dkim=pass header.i=@163.com header.s=s110527 header.b=jyhq4+Bp; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730400AbeK0Uyj (ORCPT + 99 others); Tue, 27 Nov 2018 15:54:39 -0500 Received: from m12-14.163.com ([220.181.12.14]:56603 "EHLO m12-14.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726431AbeK0Uyj (ORCPT ); Tue, 27 Nov 2018 15:54:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Date:From:Subject:Message-ID:MIME-Version; bh=ZnzyO cQyoiiHH6J4MMHT8p8+w3Fdx9yxY66n4oJl0S8=; b=jyhq4+BpKtkIPG9uMp7fU yI3W2QBIcCc2eQ1wIBFmQ5VnFWbpO61I3CFjsAiPjO5isma5hmsOL1hS/hmBFtau 5eubxJCvJyoMRCmwENBCsOdApissmtiw6YjW4v0A7OtrFYm0UFZiCz+vOZzODMqK GQzlgga2ZdxbNv0T487KT8= Received: from bp (unknown [106.120.213.96]) by smtp10 (Coremail) with SMTP id DsCowABHlMz3FP1blOiUCA--.55858S2; Tue, 27 Nov 2018 17:57:11 +0800 (CST) Date: Tue, 27 Nov 2018 17:57:12 +0800 From: PanBian To: Jan Kara Cc: Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH V2] namei: free new_dentry late Message-ID: <20181127095712.GA32100@bp> Reply-To: PanBian References: <1543104923-81192-1-git-send-email-bianpan2016@163.com> <20181127092551.GC16301@quack2.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181127092551.GC16301@quack2.suse.cz> User-Agent: Mutt/1.5.24 (2015-08-30) X-CM-TRANSID: DsCowABHlMz3FP1blOiUCA--.55858S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7ZFWxWFWDKF43tFWrCF1rZwb_yoW8CrWDpF 4rKay8tF4fWrW0kFn3ZFs5Z3W8Zr4Igw109r109ryxtr9aqry5tFs7Wr4kuFy3urWrur1U XF48KF15Xa13ZaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jypBfUUUUU= X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiDhcMclXlpnp-6wAAsf Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 27, 2018 at 10:25:51AM +0100, Jan Kara wrote: > On Sun 25-11-18 08:15:23, Pan Bian wrote: > > After calling dput(new_dentry), new_dentry is passed to fsnotify_move. > > This may result in a use-after-free bug. This patch moves the put > > operation late. > > > > Fixes: da1ce0670c14("vfs: add cross-rename") > > Signed-off-by: Pan Bian > > The code is actually fine AFAICT. One new_dentry reference is passed into > vfs_rename() and another one is acquired directly inside vfs_rename(). That > is the one dropped early but there's still the original reference passed in > protecting new_dentry from freeing. Am I missing something? I am not quite sure about the actual execution logic. But I guess new_dentry reference may be dropped outside vfs_rename in cocurrent executions. Otherwise, there is no need to acquire & drop new_dentry reference as it is always alive along vfs_rename. Best regards, Pan > > Honza > > > --- > > V2: correct the fixes commit information > > --- > > fs/namei.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/fs/namei.c b/fs/namei.c > > index 0cab649..8b104d9 100644 > > --- a/fs/namei.c > > +++ b/fs/namei.c > > @@ -4498,7 +4498,6 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry, > > unlock_two_nondirectories(source, target); > > else if (target) > > inode_unlock(target); > > - dput(new_dentry); > > if (!error) { > > fsnotify_move(old_dir, new_dir, old_name.name, is_dir, > > !(flags & RENAME_EXCHANGE) ? target : NULL, old_dentry); > > @@ -4507,6 +4506,7 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry, > > new_is_dir, NULL, new_dentry); > > } > > } > > + dput(new_dentry); > > release_dentry_name_snapshot(&old_name); > > > > return error; > > -- > > 2.7.4 > > > > > -- > Jan Kara > SUSE Labs, CR