Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4012818imu; Sat, 24 Nov 2018 16:18:10 -0800 (PST) X-Google-Smtp-Source: AFSGD/VqCI1AXXdBSD2gpyGWRR7E2s7qL8HiLG5khcDkn9BY+tiGyXLSRqdsrQUn1BN3mYWQUn67 X-Received: by 2002:a17:902:6bc4:: with SMTP id m4mr6571217plt.93.1543105090135; Sat, 24 Nov 2018 16:18:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543105090; cv=none; d=google.com; s=arc-20160816; b=k2f9652NJPQTEB+/CdVNB7Cz1FpSDtMT7aJ3dIkciHL1BRYN5HWx4I1PUy69zUsSjT fQUohGHOmKvVgb6GJeB+M6zOtNuWmlYJQDVyUgPsMzW+JkgZxMnqE1keR9lCyFfRgrMx ypuCmiKdfsnwLCiVu3spTGyTMC2FKQeCElaLFGp1cF7YGu9Q19C4u/8ulLhGH5C0FN+J 3nnsgc3f53+AKT4CA8oNfbhGY1STu2tSs+8DL1Qa6npNnukFQZHnIHommb0plPJv2oFm /iUpcBeBwapzgENeL/PjRSC200STMIYoj08Us9K1omVXb0erEsZCwPFArr8hTgn1TmbL xkvg== 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=V//pgdwWyIpBtkQ4QT0cmTEgA+uszkNlv1QKI8RdRew=; b=oTReyTJXLB7TOhSiZVVa0as+OAV9N/2ikukwBa/Hhxlltc1BbzPBsdWi21mgC48S4W /0YV3m9HEalBd2lhy83WFRKvrPm56PUpp9ClSHMWb7v2NEB1QxhD4mTgwH006DR7U1JP Yw8FIqVqU/AqHUkQgLFxcss31gaq9/FG4MVCrc/kNP27wvbopEA/kaGQVYdOycpAxuSJ rZRkVUoz1clMKJ8ym2gTd9dvtc+sR1k1RTUjqLQOxXFU6oXthc9e3kQLGHCHCn2+Cd29 5rSTdmwDzzn3n58z1gWCoiHv/m+vNtnoR/b5kYnBc9AHaVGgKiUdVCusAXo3Ch85ume5 OTqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=PnrFkwHJ; 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 k134si57544880pga.401.2018.11.24.16.17.20; Sat, 24 Nov 2018 16:18:10 -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=PnrFkwHJ; 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 S1726767AbeKYLFW (ORCPT + 99 others); Sun, 25 Nov 2018 06:05:22 -0500 Received: from m12-13.163.com ([220.181.12.13]:35300 "EHLO m12-13.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726392AbeKYLFW (ORCPT ); Sun, 25 Nov 2018 06:05:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=V//pgdwWyIpBtkQ4QT 0cmTEgA+uszkNlv1QKI8RdRew=; b=PnrFkwHJGXycyVw6X7cv7g9g0xCEgfvNvU BxiTiKykOd/aHCkOeW3xXOfg6mhqP1MlaRdTe+7867dvqH/J6tTFbtRau2bpI1LS 3fYwWJTziOHmDBkeU1I4g1ssNzslkryHoHdIp/H59VkKaBAI0YtaMqw+NNp6Vq4N JWLrkeEWY= Received: from bp.localdomain (unknown [106.120.213.96]) by smtp9 (Coremail) with SMTP id DcCowACXaiSq6flbotuuBg--.56571S3; Sun, 25 Nov 2018 08:15:40 +0800 (CST) From: Pan Bian To: Alexander Viro Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH V2] namei: free new_dentry late Date: Sun, 25 Nov 2018 08:15:23 +0800 Message-Id: <1543104923-81192-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: DcCowACXaiSq6flbotuuBg--.56571S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7Gw48Ar4DWFyxCw17tr1rtFb_yoWDZrg_Cr W0va1xuFW8Wrs7J3y3C3yYkF4Iga1rtrs3GFsYqFZrta98Kr98AF4kCwn3ZryxurWfG345 Cr97try5AFya9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU8dgA7UUUUU== X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBzwwKclaD0ZreWwAAsg 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: da1ce0670c14("vfs: add cross-rename") Signed-off-by: Pan Bian --- 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