Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3265600imu; Sat, 24 Nov 2018 01:25:37 -0800 (PST) X-Google-Smtp-Source: AJdET5cCDRIjH6k0CR7Ne2UDAluzNLZ4mfqjUm//2hy7MfhrHpjOsrpEqWbSiJO9kAjAZbprHwOb X-Received: by 2002:a62:c583:: with SMTP id j125mr19720554pfg.37.1543051537318; Sat, 24 Nov 2018 01:25:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543051537; cv=none; d=google.com; s=arc-20160816; b=CVZFLM0eNr7hBFDPz/c9MC6XMyLPwU+nrSl6n0MEkpNIAwp9hRPhNXpDB2q7uk3jY4 UZdjgSmgMeXQ3+hRH0avFe8826rotP000ms9/gju7F929vLX3FENu41QYv3j21OZ/wRZ vpTUxuLfeJRhnVGJwUoTkYmBG1f0lNIyEbm2hm24YaxM/Trk2rs+Tf5e6nOue3jFmSb3 CxgSO9ci/2M1ih26RfeUTszeE9Urw+2QEptN4bOcOdQNCkbVoRkpAb9+O2UP3yVJPpkd INiwfJ3BL9t/O1J6AcNaRH1CTDRWkBBB8TlZ11d7QGx79PC0UVlenAQ+5v4L5VNoeEcw ZFmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=mfAzntdli1b0HQ7bV8FT8wmaCJ4HtmXXBv8S0eD1ucI=; b=xQDktRM3fbMoP60Edpg/dpPv6VzpL5Jc5zM43RkGBRncwC3dVYB5smly1QwRW1S8Qv xet0Qx1kHziPpUo9YqrW2DjwXIPvQAmrDMBr7K6NBUXWgJB7Eids7zT7NaZSoxMgbzXL VxpW43Gf47tl6h1ooHNEJyyAUNXTmismjZHZhKzdxvwcy7wOUvm2GfaSclDwg2W/ZZLr BGmqEmHpXh6mpCURJjR/Otq4QN3HuzYWiTpPPv0AtXF+yjtNMxgpZu3tb7RXlo08m/hv d9fICppLvJBr+V0urJ63cO9CiiaxVoPNXyzqmiFNQm5uZ3TMOs2meDAI+UjaYAzzYpQ+ Y8qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=OCAV3cyP; 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 23si37329749pfz.20.2018.11.24.01.25.21; Sat, 24 Nov 2018 01:25: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; dkim=pass header.i=@163.com header.s=s110527 header.b=OCAV3cyP; 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 S1726087AbeKXUL1 (ORCPT + 99 others); Sat, 24 Nov 2018 15:11:27 -0500 Received: from m12-12.163.com ([220.181.12.12]:38408 "EHLO m12-12.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726050AbeKXUL1 (ORCPT ); Sat, 24 Nov 2018 15:11:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=mfAzntdli1b0HQ7bV8 FT8wmaCJ4HtmXXBv8S0eD1ucI=; b=OCAV3cyPFG+w8lgIN+TwChuBwdtgnbMH0w jCzLiSKhflGpNr6NXkmpd+QCO0ZBKGDJ2QW/18WGHBLtvudVhXfJeIFPCCLHD5/l k/HSuObUZl4xrurDmW9bWUXuWxo10jXOS++i1d4KONdIuOnDguIV2Us3SHQo8n05 GDTCZ6Z9U= Received: from bp.localdomain (unknown [106.120.213.96]) by smtp8 (Coremail) with SMTP id DMCowAB3m3WMGPlbckPZBg--.51995S3; Sat, 24 Nov 2018 17:23:26 +0800 (CST) From: Pan Bian To: Alexander Viro Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH] namei: free new_dentry late Date: Sat, 24 Nov 2018 17:23:24 +0800 Message-Id: <1543051404-42498-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: DMCowAB3m3WMGPlbckPZBg--.51995S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7Gw48Ar4DWFyxCw1kZw1rXrb_yoWDXFb_Cr Wvvw4xuFW8Wrs7J3y3C3y5KF4IgF1rtrs7AFsYvFsrtay5Gry5Aan5Aw1fZryxurWfWw15 Cr97try5CFy5tjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU829aPUUUUU== X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBzwgJclaD0ZIEJQABsK Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: 49d31c2f389a("dentry name snapshots") Signed-off-by: Pan Bian --- 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