Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp479605imu; Tue, 27 Nov 2018 01:27:59 -0800 (PST) X-Google-Smtp-Source: AFSGD/UQy+yxOR64WOYiYk7BrRWRW5KEDkMro4OzSjxLneTuhJ0bE/+suDf1U1vPXBVV/G0G6Ypo X-Received: by 2002:a17:902:8214:: with SMTP id x20-v6mr30416990pln.224.1543310879676; Tue, 27 Nov 2018 01:27:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543310879; cv=none; d=google.com; s=arc-20160816; b=WCynPFJ0G/dPrN/PK2tJbhcJCEFraNhxLZ4ZAZylsbkshg6DkIxHp74UdhFqUH/Dpi k2lMxyIr20yGHBMPZ0ISD6TBkGR+B0KHthCaXy5FWYGw0E9jIlRLxTHrxMiXg/6bRhiH INqbdD6iEqsuTJvZZsv153V9K5sh/g6fwxYM54Jzh29TYQ4zpnwkMzQD+lbxeV4xE09p BnxPYxbjyN0/clfMRb7Fh+uQv4m41bHgIauMvXG5y2Qd5iXAjEpbrWabiifzsVeeXaOX JlV2GmCge2LfDXcWUp1SUGoA4iaCBjccIUN2Ty5lBLTEzahkOabaSW0Q5EdkFsx0C4zs FyLg== 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=jp4VJ0QcNU+AejYN99kgP2EkipbmetI/cVqy926ZZg8=; b=ul5ytk8r5KMPCpkzAxCI+JoqoGhfac0iL4KO0K9UP1eywN/IElO4N0Gfr2IfT+arIS FOkC4vU/JMW1F7f21agzcPVnhW7M8mYoYgIXa5X72R02hIWAPzBUx8m6c4hNCMsoeDCg 9lUlHtQ5HvADwddxXlpzQozkEQQw5WUQQsV4CGfF+j1uw/HsAKCRqXzpZbGqAaAKqJjA MaaOEnLa9KEIhPldi/qAOmdnBiHOx9sask+4a9dNMUULVpKhxsqnAF2CEhyaJRj0T9gK zhXNeqOFRqMqjq4WGLbryjNmJu8FwnxVYVZpM8aHuBzNdG0buasI2nGulz6UTqAOwSCY DBHg== 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 a3si3410859pld.252.2018.11.27.01.27.44; Tue, 27 Nov 2018 01:27:59 -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 S1730111AbeK0UXL (ORCPT + 99 others); Tue, 27 Nov 2018 15:23:11 -0500 Received: from mx2.suse.de ([195.135.220.15]:45648 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728512AbeK0UXL (ORCPT ); Tue, 27 Nov 2018 15:23:11 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 09EC2AF8D; Tue, 27 Nov 2018 09:25:53 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 028551E07ED; Tue, 27 Nov 2018 10:25:51 +0100 (CET) Date: Tue, 27 Nov 2018 10:25:51 +0100 From: Jan Kara To: Pan Bian Cc: Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH V2] namei: free new_dentry late Message-ID: <20181127092551.GC16301@quack2.suse.cz> References: <1543104923-81192-1-git-send-email-bianpan2016@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1543104923-81192-1-git-send-email-bianpan2016@163.com> 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 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? 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