Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2916233iog; Mon, 27 Jun 2022 05:43:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1txlhp5hmklmM67xZkE7e87z8EcJ4duRprjFjyS9fCL0QSwUjfnV5iX5TET3Sp5lBSqz4zG X-Received: by 2002:a17:907:9625:b0:726:3a61:224d with SMTP id gb37-20020a170907962500b007263a61224dmr12359303ejc.286.1656333797216; Mon, 27 Jun 2022 05:43:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656333797; cv=none; d=google.com; s=arc-20160816; b=vDKxoucPPv+P4IVcDh2jrYD0OsGmsVHCa0N5v14jmqVSpsuIBob4ojW9jorHp1hZ4x 0I4qroH/5fizxAz6eWv0ECY8l5XjLzGiAsx94zt5RwOI3WprPjxFuobYeJcnzMjWqtOG 10oBnTNuKIQl9B8QVjYvTm4XeYjNYLfPI9/9BRZMxcg2Rs8JaKeSKSD9fKaOOYLhbWHC ACSEllh3jojJVLAjkHqHVmzx5frAKI5NgF7UYHUZhso8rg74hc3s3X6xw2icFJx2dTd4 E4m8BAmAoXp8+MTuWLMmxfrboeVpKObKELFHsO1ExZO6e/A9uQXNz/scFv+133UBLI2e zAbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UoZkfabUR1ZbPisdUTLBt62GazL6LooFZ5qaEe5ispI=; b=XteqONwDBxaKULnNZAvNDanGDYKTTBeiS7intABXrGEsWNWfjbMjDwfRoFLUql2D9H UsL37C6JWgo17iDpNtq9wmQ5Qsf0+b2Iam2OMQ5GEL4DSQZB7SktO4IMit+Hi209+GdZ fX7Wk6N8GQ8RHpZEnoMORy5K51neqhW+kHI6K9exnSPLJ0rlziyneA+NBfKbvQ4UIDEr nQgzGSwALScr5m/WSoy7UQOpHDBWsfnk2FCkZpSzoiMHBRhnltU6ygFt2hoRLgVhHkY+ HcLX0GgUbjpe1fzOh2JEyyWjWh9uebBYiWCLcj7qZf4Afi2MTakHVQs4ypcCGyFM3fIW bFiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HuUPajoh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gc10-20020a1709072b0a00b0070b645c8cedsi276561ejc.580.2022.06.27.05.42.50; Mon, 27 Jun 2022 05:43:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HuUPajoh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237792AbiF0LtF (ORCPT + 99 others); Mon, 27 Jun 2022 07:49:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237679AbiF0LrY (ORCPT ); Mon, 27 Jun 2022 07:47:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7B97DFF7; Mon, 27 Jun 2022 04:39:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E927CB81132; Mon, 27 Jun 2022 11:39:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FDEBC3411D; Mon, 27 Jun 2022 11:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656329952; bh=iPaPXnO6femvThk7XxvLCJLoVOjfA2IJ8p6/aAO9ZOQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HuUPajohaFyOMtOfuq5anb7Bm7J2FragaOcilzvuo0L5JqrUwg8zKZh0oXHAO5P9j vtE7pkXeg6qb/8iKntu6IxoJStBZF71pj7czQcwczD1tjNC2iDsxHIcp/BQQlJjlEB svae8CDMHa6Tc1uv9Yh1NfcIE5I0X1ZKlKAMtBn8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Chinner , Brian Foster , "Matthew Wilcox (Oracle)" Subject: [PATCH 5.18 033/181] filemap: Handle sibling entries in filemap_get_read_batch() Date: Mon, 27 Jun 2022 13:20:06 +0200 Message-Id: <20220627111945.522910063@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220627111944.553492442@linuxfoundation.org> References: <20220627111944.553492442@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox (Oracle) commit cb995f4eeba9d268fd4b56c2423ad6c1d1ea1b82 upstream. If a read races with an invalidation followed by another read, it is possible for a folio to be replaced with a higher-order folio. If that happens, we'll see a sibling entry for the new folio in the next iteration of the loop. This manifests as a NULL pointer dereference while holding the RCU read lock. Handle this by simply returning. The next call will find the new folio and handle it correctly. The other ways of handling this rare race are more complex and it's just not worth it. Reported-by: Dave Chinner Reported-by: Brian Foster Debugged-by: Brian Foster Tested-by: Brian Foster Reviewed-by: Brian Foster Fixes: cbd59c48ae2b ("mm/filemap: use head pages in generic_file_buffered_read") Cc: stable@vger.kernel.org Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Greg Kroah-Hartman --- mm/filemap.c | 2 ++ 1 file changed, 2 insertions(+) --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2385,6 +2385,8 @@ static void filemap_get_read_batch(struc continue; if (xas.xa_index > max || xa_is_value(folio)) break; + if (xa_is_sibling(folio)) + break; if (!folio_try_get_rcu(folio)) goto retry;