From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C90C9C3F68F for ; Sat, 25 Jan 2020 03:35:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A05A42072C for ; Sat, 25 Jan 2020 03:35:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387736AbgAYDfv (ORCPT ); Fri, 24 Jan 2020 22:35:51 -0500 Received: from outgoing-auth-1.mit.edu ([18.9.28.11]:37004 "EHLO outgoing.mit.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387685AbgAYDfv (ORCPT ); Fri, 24 Jan 2020 22:35:51 -0500 Received: from callcc.thunk.org (rrcs-67-53-201-206.west.biz.rr.com [67.53.201.206]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 00P3ZNia013355 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jan 2020 22:35:26 -0500 Received: by callcc.thunk.org (Postfix, from userid 15806) id DA14842014A; Fri, 24 Jan 2020 22:35:22 -0500 (EST) Date: Fri, 24 Jan 2020 22:35:22 -0500 From: "Theodore Y. Ts'o" To: Eric Biggers 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: <20200125033522.GM147870@mit.edu> References: <20200124041234.159740-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200124041234.159740-1-ebiggers@kernel.org> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Thu, Jan 23, 2020 at 08:12:34PM -0800, Eric Biggers wrote: > From: Eric Biggers > > Since ->d_compare() and ->d_hash() can be called in RCU-walk mode, > ->d_parent and ->d_inode can be concurrently modified, and in > particular, ->d_inode may be changed to NULL. For ext4_d_hash() this > resulted in a reproducible NULL dereference if a lookup is done in a > directory being deleted, e.g. with: > > int main() > { > if (fork()) { > for (;;) { > mkdir("subdir", 0700); > rmdir("subdir"); > } > } else { > for (;;) > access("subdir/file", 0); > } > } > > ... or by running the 't_encrypted_d_revalidate' program from xfstests. > Both repros work in any directory on a filesystem with the encoding > feature, even if the directory doesn't actually have the casefold flag. > > I couldn't reproduce a crash in ext4_d_compare(), but it appears that a > similar crash is possible there. > > Fix these bugs by reading ->d_parent and ->d_inode using READ_ONCE() and > falling back to the case sensitive behavior if the inode is NULL. > > Reported-by: Al Viro > Fixes: b886ee3e778e ("ext4: Support case-insensitive file name lookups") > Cc: # v5.2+ > Signed-off-by: Eric Biggers Thanks, applied. - Ted