Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp32311465rwd; Fri, 7 Jul 2023 11:45:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlE4cZAVS93jawcKqnAGmwdvwMl+PPL223+4CDWeEOvGHAeoV26X9nIGT/jv5FncWVu+Y0Yv X-Received: by 2002:a05:6a00:3920:b0:668:69fa:f791 with SMTP id fh32-20020a056a00392000b0066869faf791mr5066434pfb.3.1688755545573; Fri, 07 Jul 2023 11:45:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688755545; cv=none; d=google.com; s=arc-20160816; b=FPvl/wEFTQsOGBVtP5zqSdee6IsdFm1KzfzSFRhpz8ix+ppeN6CSsKJJzc+oydgFf1 CG5Fuf6p8FXdP9fxVv3d0RHoFwBaZ2tGDjnJfvPOsei1uE/Z/dGWxjcvyG5oZ14AH6wk RiypziRfYQqfncnLRv6mLOHDs0mtdwE3rPUBWQDq0x5tWyYGvkvooP5Yw+UgUOsq/KOQ AYAG0CELCZfLPfcB4su7eBP9NkJIp2yQXyFgnvFDPWywoXrywKip7Alp7z016tA4u0l/ OW1donFd4ffaYdMFRdGHGXAo/X+Tjs0Ti9saleUpiOKzFBMnpdeCkFHRlfRYuSzxrd7R 6ntw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=EnPO7iYPqwnxTqwStZEfw5T07yWJQFIQid3g9b9XqJw=; fh=n4BAJIW6qJwW9f5EiX5paasuGxFrJXltKuYTVaVcC1U=; b=x+k90oSZ4JTfYTIVDQZhchJmOA5bkERlg/OetzJ2ljvEP+VzFVHOseOflJe2zteLGN T2giXaFDx/ASrDsdNvR0XQ9h9htRWe07DJQ86/J71HBmXsugjqQ8gTN8/VfuRXd80Tjc hjzq7w1DIe5g/MCekMIRhNxR0c1akh5nKMq8l7wezmi8ALaD/8M7D4u0+E6dzRTin1/n B3qKvbprVzlIfqJRU+kU6tsTSV3TdEQlKTrFmj7UZcJ9GDMHep/rdNy+qWNbIqFoBlvH TP1IyM+FoveAelw2FydoIl3NbA+GvaCB1SazTUZdkr0tiCwfP2jm2La+7wzEwD0eqcvk jq3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=hSZgYMr3; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s32-20020a056a0017a000b0067be4c2b937si4626580pfg.281.2023.07.07.11.45.29; Fri, 07 Jul 2023 11:45:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=@infradead.org header.s=casper.20170209 header.b=hSZgYMr3; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231421AbjGGSd2 (ORCPT + 99 others); Fri, 7 Jul 2023 14:33:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbjGGSd1 (ORCPT ); Fri, 7 Jul 2023 14:33:27 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 731F6212D; Fri, 7 Jul 2023 11:33:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=EnPO7iYPqwnxTqwStZEfw5T07yWJQFIQid3g9b9XqJw=; b=hSZgYMr3UKHKYIY/VL4ipIs0vS 61IBklPoCl4A108p1gsJG4vlTkCOJoen6cWDC43+6NTkr8YGNcmQcJs1O3p4OQtb1NXVR4LAls2Ng /p4TPNlO1XctYmGGMC+rkDVIiNqlriS/EFc8QPJBD4SL1Z2nsXdTYGKpye4UmT0WkXCONgtsxFIeV ZzegUWujwBx4r5ew4D2ZYlNPZ/o9jjAmGtG3ZcwrWDutua9YtWwESK4CTJ8bWQsA8XK+GJhZTgRVa CxK9+UPVL47g+ChIlgIr9kUvKuQXq0PFhjJDDTHlObVTxnMgijgaiIZJ6uLFDdPe7Ztq+0PZAnrFh +1A2zrEQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qHqGZ-00CFvk-6N; Fri, 07 Jul 2023 18:33:15 +0000 Date: Fri, 7 Jul 2023 19:33:15 +0100 From: Matthew Wilcox To: David Wysochanski Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, David Howells , Andrew Morton , Linus Torvalds , Jeff Layton , Christoph Hellwig , linux-afs@lists.infradead.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs-developer@lists.sourceforge.net, linux-erofs@lists.ozlabs.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, linux-fsdevel@vger.kernel.org, Rohith Surabattula , Steve French , Shyam Prasad N , Dominique Martinet , Ilya Dryomov , linux-mm@kvack.org, Daire Byrne Subject: Re: [BUG mm-unstable] BUG: KASAN: use-after-free in shrink_folio_list+0x9f4/0x1ae0 Message-ID: References: <20230628104852.3391651-1-dhowells@redhat.com> <20230628104852.3391651-3-dhowells@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-ext4@vger.kernel.org On Fri, Jul 07, 2023 at 02:12:06PM -0400, David Wysochanski wrote: > I think myself / Daire Byrne may have already tracked this down and I > found a 1-liner that fixed a similar crash in his environment. > > Can you try this patch on top and let me know if it still crashes? > https://github.com/DaveWysochanskiRH/kernel/commit/902c990e311120179fa5de99d68364b2947b79ec Said one-liner: - struct address_space *mapping = folio->mapping; + struct address_space *mapping = folio_mapping(folio); This will definitely fix the problem. shrink_folio_list() sees anonymous folios as well as file folios. I wonder if we want to go a step further and introduce ... +static inline bool __folio_needs_release(struct address_space *mapping, + struct folio *folio) +{ + return folio_has_private(folio) || + (mapping && mapping_release_always(mapping)); +} + /* * Return true if a folio needs ->release_folio() calling upon it. */ static inline bool folio_needs_release(struct folio *folio) { - struct address_space *mapping = folio->mapping; - - return folio_has_private(folio) || - (mapping && mapping_release_always(mapping)); + return __folio_needs_release(folio_mapping(folio), folio); } since two of the three callers already have done the necessary dance to get the mapping (and they're the two which happen regularly; the third is an unusual situation).