Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp209254ybl; Thu, 23 Jan 2020 21:59:17 -0800 (PST) X-Google-Smtp-Source: APXvYqxcQe8nDfnzbw04tvkXJne+kdhuexpNjggYy6mV3rmkXJQ84pqSUd2b2Li9ZAVNYM3f1tzX X-Received: by 2002:a05:6830:1116:: with SMTP id w22mr1610604otq.216.1579845557605; Thu, 23 Jan 2020 21:59:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579845557; cv=none; d=google.com; s=arc-20160816; b=Tj71m+wfSllOJ1LWVKhOY+W7BBbN5zVnqjFNkau7bh6MIVbk7GDVI2kWuRtFqD2Fod AKTKWRX6gDzsQTcjW0SEJISq0VNOqy0vUQL6s3Fk4USOSk6IKlAy8xVnfwnkSXUx3cqU VDkGK1HwPiDVMZ+2EL/J8a8XS7MCm0LH9Ns0/8+2qak86eP+K69Ih24goPisax0tdZRM tRKzxnAqtTsHItxCWICwHJPDjyzO6BfivvT9TrQuSUoIr7TyUTZzfJKNZfkg+n5EkiVO f3DeV1TtTxBU7XMRF8kx7mTHNLyGjDxWd1DMkmJJDVD9FwEi71Vw/yXoZn88Ja578/kj 1nag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Sk2pY5AisMa/av235iqzQb5ycJz9ETouLkY9hedRTfs=; b=fFxx6MKwC0Im7c8dy0CecWu/Ia3IoEP/zQDWxs5+Kio3fzgcgfpnmBQ6gM1kOkBzGc UnwNuSs9AUKmizU6xuj5iY2L4J3wPfJtcsUlPGWfgN0zcRTlfgc9oSXPDtOu87qHq75w jM6z9TqM3zmBplav6ok0cRYbFOGJOO4etS0m9wagzWr9MAivYOUWG8xlfgoaU1u+R64c oIEnFmLjr4GLwMjody/99T9+v+p9OYs5AeyambXGu5kNK/hG6XyyiNEJx3I7jTr/hlHk cAc4ZQu4vgThGy6waTU0bK8Jb/lqfk14HFsS5wqNGxA9j8XH3hT+Kv8wU1C05uvPI+aa onOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="F+N98E0/"; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d8si2427224oti.306.2020.01.23.21.59.06; Thu, 23 Jan 2020 21:59:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-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=@kernel.org header.s=default header.b="F+N98E0/"; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727441AbgAXFyB (ORCPT + 99 others); Fri, 24 Jan 2020 00:54:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:51574 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726725AbgAXFyA (ORCPT ); Fri, 24 Jan 2020 00:54:00 -0500 Received: from sol.localdomain (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AE5132071A; Fri, 24 Jan 2020 05:53:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579845239; bh=PD319ZtzsARpjQN1qMfKAV/AztFjbl+rqa9IicPM79c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=F+N98E0/dZZRYj9BMz9tUTtbHDoSnZvlNf8oRs8RP+l/FZb0ctHVNOVfdHtZWXdXR gG/Cx4DZH2U+0Sncv8BudMGmyMmULJOBTJyfeb3sMsM4RJltlvJVBGaMvyx7BE+ep+ O9wEiILKvXBu44x4EbHiFVxgdBWRTe4dhjwAB/Gg= Date: Thu, 23 Jan 2020 21:53:58 -0800 From: Eric Biggers To: Gao Xiang Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Alexander Viro , Daniel Rosenberg , Gabriel Krisman Bertazi Subject: Re: [PATCH] ext4: fix race conditions in ->d_compare() and ->d_hash() Message-ID: <20200124055358.GD832@sol.localdomain> References: <20200124041234.159740-1-ebiggers@kernel.org> <20200124050423.GA31271@hsiangkao-HP-ZHAN-66-Pro-G1> <20200124051601.GB832@sol.localdomain> <20200124052740.GB31271@hsiangkao-HP-ZHAN-66-Pro-G1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200124052740.GB31271@hsiangkao-HP-ZHAN-66-Pro-G1> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Fri, Jan 24, 2020 at 01:27:50PM +0800, Gao Xiang wrote: > On Thu, Jan 23, 2020 at 09:16:01PM -0800, Eric Biggers wrote: > > On Fri, Jan 24, 2020 at 01:04:25PM +0800, Gao Xiang wrote: > > > > diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c > > > > index 8964778aabefb..0129d14629881 100644 > > > > --- a/fs/ext4/dir.c > > > > +++ b/fs/ext4/dir.c > > > > @@ -671,9 +671,11 @@ static int ext4_d_compare(const struct dentry *dentry, unsigned int len, > > > > const char *str, const struct qstr *name) > > > > { > > > > struct qstr qstr = {.name = str, .len = len }; > > > > - struct inode *inode = dentry->d_parent->d_inode; > > > > + const struct dentry *parent = READ_ONCE(dentry->d_parent); > > > > > > I'm not sure if we really need READ_ONCE d_parent here (p.s. d_parent > > > won't be NULL anyway), and d_seq will guard all its validity. If I'm > > > wrong, correct me kindly... > > > > > > Otherwise, it looks good to me... > > > Reviewed-by: Gao Xiang > > > > > > > While d_parent can't be set to NULL, it can still be changed concurrently. > > So we need READ_ONCE() to ensure that a consistent value is used. > > If I understand correctly, unlazy RCU->ref-walk will be guarded by > seqlock, and for ref-walk we have d_lock (and even parent lock) > in relative paths. So I prematurely think no race of renaming or > unlinking evenually. > > I'm curious about that if experts could correct me about this. > Taking a seqlock for read doesn't prevent the protected data from changing. It just allows the reader to detect that it changed. So we still need to handle the dentry fields being changed concurrently here, even if it will be detected by a read_seqcount_retry() later. - Eric