Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3207266imu; Sat, 24 Nov 2018 00:06:19 -0800 (PST) X-Google-Smtp-Source: AFSGD/UsXZNHbsFllWsE2HVPI/w4ZjLyBl0tsBDH59WX50eaTtcYJFurwY5VH8cM1V6t94DQQTXI X-Received: by 2002:a17:902:28a8:: with SMTP id f37-v6mr19138373plb.264.1543046779904; Sat, 24 Nov 2018 00:06:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543046779; cv=none; d=google.com; s=arc-20160816; b=wbVviIAlYNT/2Jbtlfb0I/PKpTDJB1y3k9/cHAFBsV7I4hR2w0PlhCMkb6ow32e1NR TWO7qjaaxGzD8nOZHvULcquwyORNfsHiVMKZ3+mhgq1BCufBXg86rNlOP70vSN9WSjuO faYDJdhrk4Iy1ZYwoFYs0+PIU0p1J0ViK8GKKymCfQ3IU2LuLhq5QhPz2DpBWslkl6B6 pe/gMN2KMYB8BxtAqKQJef9N3clZiLJOhk2avMekkrNKyCvC+gHN1xSsyAUWGpzGyMm3 xsNQaWjPeWdQpv539VyTXtsx5ZV8bxIuhBqqrhGrKFLmGVOVsgwGXOOJ2EP6EeUDeFk3 bllw== 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:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=l7HrFAUGrX/AbS0daXYfYodInwELvxOeILo2B59k4VE=; b=0gbNzmCKgDWB07Z5hKwRUxo1X/S5ogUTWnisOoOabo7H6xYypeQb18/dgJEaHFIVzV TPfQgoYC4Qejt0iib3IntKJD1sVquULF1CGUfEKq71UCzaGUYn6bLrxheiYXLJuWWK1J hiefYZ5xr2CkhFPmn0ABdyjpHDbXssiUje3d2npN5TUcRsX6BgtPA2NV4L6cmtVwDTQd uMNyyTv2VRWvtFLKGYaUS0oKuTbD/Hwm7DQm/EwbAIwwO5vTB0j9QSKEFfh5PIvQfJSD yYL14zMSB1znHjYpCQS95BIphyz+IIcXIMGl9J3cDnOX91kGXD70mgJFUl0rCVdjK2qv hG6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=GFcnzSj1; 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 13si9279620pld.398.2018.11.24.00.06.05; Sat, 24 Nov 2018 00:06:19 -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=GFcnzSj1; 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 S2502369AbeKWSZ6 (ORCPT + 99 others); Fri, 23 Nov 2018 13:25:58 -0500 Received: from m12-13.163.com ([220.181.12.13]:48886 "EHLO m12-13.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390041AbeKWSZ6 (ORCPT ); Fri, 23 Nov 2018 13:25:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Date:From:Subject:Message-ID:MIME-Version; bh=l7HrF AUGrX/AbS0daXYfYodInwELvxOeILo2B59k4VE=; b=GFcnzSj1j2mu3yFSednpH +GC/pwKCgqrzkREQeViqs1ogibrBvrSAV/pfHwl1la86H5BJqbjQNgfORadkeIGI tmATt8z4oSTNIRRUASdktXXFS5QkA/T+DIdbSgBELEYVQrk15sLcnjYd12LtFsiH YyVxvjSGezdzO6yWb7qBWs= Received: from bp (unknown [106.120.213.96]) by smtp9 (Coremail) with SMTP id DcCowAA3JS4Pr_db3bKfBQ--.42338S2; Fri, 23 Nov 2018 15:41:05 +0800 (CST) Date: Fri, 23 Nov 2018 15:41:06 +0800 From: PanBian To: Amir Goldstein Cc: Miklos Szeredi , linux-kernel , Al Viro , "J. Bruce Fields" , Christoph Hellwig Subject: Re: [PATCH] exportfs: do not read dentry after free Message-ID: <20181123074106.GA102096@bp> Reply-To: PanBian References: <1542942953-93562-1-git-send-email-bianpan2016@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-CM-TRANSID: DcCowAA3JS4Pr_db3bKfBQ--.42338S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxJr1kAFykXw15Zr1fJry5Jwb_yoW8Aw1kpa n3Gr4FkFWvqFsxCr4xuF15X3409w1IqF15JFyUWr18Xr9xXF1F9r129w1q9Fy09rs5CFWD XF4DKw1fWF45ZaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07bUSoXUUUUU= X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBUREIclaD0R7dzQAAsw Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 23, 2018 at 07:58:15AM +0200, Amir Goldstein wrote: > On Fri, Nov 23, 2018 at 5:16 AM Pan Bian wrote: > > > > 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") > > > > CC Fixes patch author/reviewers > > How did you find this? by code review or did this actually happen? > > Normally a IS_ROOT dentry would be either DCACHE_DISCONNECTED or > pinned to some super block, but I guess there may be corner cases? I found this by code review, and I have not yet observed crash. > > > 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; > > } > > The change itself looks right, but the name IS_ROOT is confusing > enough as it is. The explicit comment is just plain wrong. > If it was really a root dentry, it wouldn't have been DCACHE_DISCONNECTED > (unless it is a filesystem bug). I will remove the comment and resubmit the patch. Thanks a lot, Pan > > Thanks, > Amir.