Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3199434imu; Fri, 23 Nov 2018 23:56:57 -0800 (PST) X-Google-Smtp-Source: AFSGD/WPQLDShXg+5L8VuZcDnSFEbg3IgnV3ElJKUSTrsshw1kIGlK4+cETUxXEDtqhOvmaonu13 X-Received: by 2002:a17:902:4222:: with SMTP id g31mr18901354pld.240.1543046217125; Fri, 23 Nov 2018 23:56:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543046217; cv=none; d=google.com; s=arc-20160816; b=QwUpSsmDAycLYkMiZCnPz12MjRa4rrCjGobDWVUdZ0jAq9y+MPJ2LjCrE4WfCk7s19 Vae5MCSZDEbRFeCph98dC8dSHYU5AzMRmdM0H4iJc9EUiMVQqoyZF0oILXAG3pHsm54L 9IGRMbnULCm+O5HaWZ47UfPAWkzzoRuichBX2g6TR7etlOpszJpaWag5WKW+5TvjENDx LOTPwqTreDQ9qqVMWMdhuiWIZ58eBXdcqaoHo+QYvVC9eOkYvDUS62dPB4pLjN+kJ5Hs bruA18lBL61as+YQFOFXltWM7gBxyG0tfU/heARbeQJQN9Tyea7XbJ6RHqYKdnWC6fmK E+Hw== 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=Tn2Oijgn7sTTPQfEN5ne5ei07j8RpMQ/+5fJD69TwAY=; b=Ocqu29DRAKKuwLliecj3jt22SGRpCLeKnvlOpKJImxtimbMxZq9fcqBVinCoD948U7 G88Sb7ftoQKF2Wrj1CrOyx1VqIeexNiOKe/bLBvdPXZ9V05FOlu0jeKFvm7xyymrQASZ yp4652sAkoiVACSCH6CILIF7jArM66RpgZZZNqXRCIImNTXzMS0sLRp5J0iUtwdQBoiz 8GjtPFPHT+Rq6UYewuf9AybTRDMmt+NtjCSRcGfowVklw0omtZVG2UWy21pjX/pbYbh5 Jrn4JwPZ1VSBYLnrTkLAf/8srQhgOc3W53FYL26mNglZW7XqaICsxCuvMMSU28rNaeoN OV2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=ixyZGcQQ; 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 92si29658672pld.84.2018.11.23.23.56.42; Fri, 23 Nov 2018 23:56:57 -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=ixyZGcQQ; 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 S2408025AbeKWN6Y (ORCPT + 99 others); Fri, 23 Nov 2018 08:58:24 -0500 Received: from m12-16.163.com ([220.181.12.16]:34518 "EHLO m12-16.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731824AbeKWN6Y (ORCPT ); Fri, 23 Nov 2018 08:58:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=Tn2Oijgn7sTTPQfEN5 ne5ei07j8RpMQ/+5fJD69TwAY=; b=ixyZGcQQ5DTg6DUvUMX2pmGfGQKpwr0gvU Hc2Q0ihuE7nGp9jPHzdWyIBAK3+ckUK3PT8k51yxSFGJoDBrBz6Vce4+7Mp9Ye9H NnrurnOlReoBmiq2WUMnQqhO9lkhFx6/479sEMEaCBz6OcYInbv/4Fm/Nd3+5QjJ fUEsU+/9s= Received: from bp.localdomain (unknown [106.120.213.96]) by smtp12 (Coremail) with SMTP id EMCowABHlQrpcPdbE1evBQ--.20002S3; Fri, 23 Nov 2018 11:15:55 +0800 (CST) From: Pan Bian To: Amir Goldstein , Miklos Szeredi , linux-kernel@vger.kernel.org Cc: Pan Bian Subject: [PATCH] exportfs: do not read dentry after free Date: Fri, 23 Nov 2018 11:15:53 +0800 Message-Id: <1542942953-93562-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: EMCowABHlQrpcPdbE1evBQ--.20002S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7Xw47tw45XFyktFWDWw45Wrg_yoWDJwcEka y8Wr48W398CFyxKF48ArWaqr4Sqan8ArWqyr4rJr45Za45CrWxJFZxtw1fXrs5Gw48W3W5 Cr1DtryUCr1rCjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU0ByxtUUUUU== X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiQAYIclSIYQ97ggABs2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function dentry_connected calls dput(dentry) to drop the previously acquired reference to dentry. In this case, dentry can be released. After that, IS_ROOT(dentry) checks the condition (dentry == dentry->d_parent), which may result in a use-after-free bug. This patch directly compares dentry with its parent obtained before dropping the reference. Fixes: a056cc8934c("exportfs: stop retrying once we race with rename/remove") Signed-off-by: Pan Bian --- fs/exportfs/expfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/exportfs/expfs.c b/fs/exportfs/expfs.c index 645158d..a69aaf5 100644 --- a/fs/exportfs/expfs.c +++ b/fs/exportfs/expfs.c @@ -77,7 +77,7 @@ static bool dentry_connected(struct dentry *dentry) struct dentry *parent = dget_parent(dentry); dput(dentry); - if (IS_ROOT(dentry)) { + if (dentry == parent) { /* is root entry */ dput(parent); return false; } -- 2.7.4