Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp514918imu; Tue, 27 Nov 2018 02:06:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/VIhfOHaRFtoZN+yEadoYeqQxVIsuLMM5OWG+wGBt7dvd0boNplHCRYr0XKyPQGCHKsW+g2 X-Received: by 2002:a17:902:4c85:: with SMTP id b5mr30648426ple.226.1543313197605; Tue, 27 Nov 2018 02:06:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543313197; cv=none; d=google.com; s=arc-20160816; b=klvmbTH1OSNfcm3M04zodmXb+zDdcLt4XjNtc54caGuktMlAJnHC0Naqk5UvnpPVWS 8lIA6TpXrmttRH8+k37/1v2hf6HH4fr6mJHi4H0cmy4e+QAt+22DBbwxCcTuPAfP+3WI 3PyKG7J1+EprUhGC6cOaO6HEXERc4im2PcYCla1M0l6eU/Z41i+lQ7LQTfQUMJTwceZL 71RYWcD9nppjaxhwh3mppRgr6pHjqviha+AJXgr+oYhiClaSiwIOlZlYLavBHzjyIg0M byuv6+DuGoD1RvRU+8lMNffPZ3D9xqQhBcOQzAsBTnw8/d8ZyArsofJMu/PUrXXYVqJX Hhbw== 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:message-id:subject:cc :to:from:date; bh=fZyNw609qiWyfaCJ8ZKprHEx0kxMZL/gr7xnc7YiGos=; b=nu41lqtYQ9oW7t9lClHAOy+uxf8dH8sq9IF4mlPHEpQBwqflh74dDPmR9eKO35WEX3 pIvOJ+oPrkOD3niEx4IBtcO4QGh1jW4twibSpnmUI/hpzu99raS+cphsoHQx8JacW9IA /bo0YmXJ1o2ldLg30pcQ6Hiw+j0O5fNWpJcRVs+X19FEORAiKA0V5CiQJXtkn4WS1sh3 q//UNoolXXj1syNjFMD/S/2CdQL8B6zIBdY7DkJ29U7yNddqaWlNXgs2ltwPoG039SJl ogH9eGU03fU4WB651Tufo0db45TxBsw7zKXJiq4CbV0Z9sAmZJDk/Sk6zEFJBoeFjmGM NPTA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u202si3644845pgb.115.2018.11.27.02.06.19; Tue, 27 Nov 2018 02:06:37 -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; 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 S1730501AbeK0VDB (ORCPT + 99 others); Tue, 27 Nov 2018 16:03:01 -0500 Received: from mx2.suse.de ([195.135.220.15]:53334 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726404AbeK0VDA (ORCPT ); Tue, 27 Nov 2018 16:03:00 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A63F1AEB9; Tue, 27 Nov 2018 10:05:36 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 3F2D51E07ED; Tue, 27 Nov 2018 11:05:36 +0100 (CET) Date: Tue, 27 Nov 2018 11:05:36 +0100 From: Jan Kara To: PanBian Cc: Jan Kara , Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Miklos Szeredi Subject: Re: [PATCH V2] namei: free new_dentry late Message-ID: <20181127100536.GF16301@quack2.suse.cz> References: <1543104923-81192-1-git-send-email-bianpan2016@163.com> <20181127092551.GC16301@quack2.suse.cz> <20181127095712.GA32100@bp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181127095712.GA32100@bp> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 27-11-18 17:57:12, PanBian wrote: > 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. I don't think that's the case. The dget() - dput() pair just looks superfluous to me in vfs_rename(). Am I missing something Miklos? Honza > > > 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 > -- Jan Kara SUSE Labs, CR