Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3229135imu; Sat, 24 Nov 2018 00:36:14 -0800 (PST) X-Google-Smtp-Source: AJdET5cP15HtjM0im2aUIXdn73uIu74PBpM/mXkt3qE/Be/ZcBcL3XZDjyJtYs4v6/7sriaybsA7 X-Received: by 2002:a62:cf02:: with SMTP id b2mr20063808pfg.183.1543048574696; Sat, 24 Nov 2018 00:36:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543048574; cv=none; d=google.com; s=arc-20160816; b=miYHETarI71QEMpcaK8ieHZ8kJLxbYqtdhYx418pmR9d5dGhb9UqbMK19B4YY6iMZ0 E1urXY62xzWSqaSVA1Ag0j7VMkSr0S8mqzy2dyJmXmCzmrCBj8KHTZPQ8waBmY8XXEdQ DK0njm2ktg2+7KtmEwIRAvmYuFX8UY4War/2vFYLaJJpoDs35qXN1NzpSufvV7ZNZNZ2 ULP1lZJHQJrvEwVzGEdLwW0z/Shwl1uvEzPzGEx8I+4dlwA0/JaHvwlMrlLBi7FJbGPr ES78YAqDL5Iq+LCJ4p069aaZnMY0WCn7d9iLyHKv+/3szvWceGQ3NSblytf+O8V/Z55c ArXw== 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=EKxjM5CYCPwHHG/dEEFe++awv6BEOeNsEk3oUpCoPb8=; b=SfbH5kOozjJs9osQ2MLR4Ec9RcZ6AR0K2/2IBHeGOTD/DPm/BKvyxmPuS9WWzXiZPX 6lFHHo6xPiWZVryyKFMf4dsBxuvMDm3+gytj8g6CdaiveI27ntKcnIeIBvWgdgNCP6pb zeYdwQnL2F6ezeIMKGtBBEfelcvkV5/jHSvEP3DBQIM2iTLX8AiActfVUWg3KZok73a/ n4DioidfUfoydwY0yBLyRUM8aYivOsr5T5ezPaTK3pBV2mW+k/Cnzh9poAVNmAw5iuTz uxOZj2NgHzG9au+MdNYNpERzbetqD883OV2RUj84zF+a698vQ3xiCCFTBXUVd0gQZSlR IWAw== 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 g59si16061918plb.302.2018.11.24.00.36.00; Sat, 24 Nov 2018 00:36:14 -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 S2391256AbeKXAwB (ORCPT + 99 others); Fri, 23 Nov 2018 19:52:01 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:58296 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726671AbeKXAwB (ORCPT ); Fri, 23 Nov 2018 19:52:01 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.91 #2 (Red Hat Linux)) id 1gQC78-0003vG-7Y; Fri, 23 Nov 2018 14:07:22 +0000 Date: Fri, 23 Nov 2018 14:07:22 +0000 From: Al Viro To: Pan Bian Cc: Amir Goldstein , Miklos Szeredi , "J. Bruce Fields" , Christoph Hellwig , linux-kernel Subject: Re: [PATCH V2] exportfs: do not read dentry after free Message-ID: <20181123140722.GA2217@ZenIV.linux.org.uk> References: <1542959793-118334-1-git-send-email-bianpan2016@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1542959793-118334-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 Fri, Nov 23, 2018 at 03:56:33PM +0800, 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. It's a bit more subtle than the description implies (the race has dentry connected during dget_parent() and the child we'd reached it through moved elsewhere during the dput()), but you are right - the race is there and that patch fixes it. I wonder if we could avoid those dget_parent()/dput() completely - looks like we might be able to with rcu_read_lock() and some care. OTOH, that's not going to be a hot path, anyway... Applied.