Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp248456rwb; Fri, 18 Nov 2022 00:29:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf7h9GZbMSoBgZ12nSXVUtaT76KdEbWGlvjEAghHWnVHknkxr8KJilmg/WVPuxOUemN1Lher X-Received: by 2002:a17:906:7215:b0:78d:a7f0:e232 with SMTP id m21-20020a170906721500b0078da7f0e232mr5127982ejk.9.1668760152448; Fri, 18 Nov 2022 00:29:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668760152; cv=none; d=google.com; s=arc-20160816; b=YiHhG00oBMNetSyJLaEVqjgv6deoEzSwmTwcQoJQdKsBDYxf+6jtEZNPiJvW1pyFyv nBTqET6zFodtrTutlM/Wxs7O+wzUK1RbfJJGWfBlHXz/DJtHVnUn8JmHlSlpSjb9EVpA B3UglOZ3HQaSHWmd5dXjpRMNiohdg43xOmFWQ6cz3GlzFRyfDTKJ5o+IVJnTEW6NY91i bmEiFG2doCeZgUDJlcU2dyZwQgtzuEdjqLxEgaS0Yhy3GaRDtpcQZbVQ2K5BBcVVe9Uv rDfGZ+/gkQMAMrbHHSKQRQcyvFGh7sUTrJTDgWNY5XWnvTaz6oHNDOJ9kuToEAC8//kp A/rw== 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=A67AbkwP8KX00tPROSsJtMhFn5xZm18oI+Xo3K1Eqq0=; b=0l/nhNfE+6UlSDFzdweuydvovtad1HuBKSKEtVYqhoQC/1Ld9XyfP0FpYoDBsScKXM jUZRDFXJUMv8dG52kd9a82pZx7UMlTCForOTt7OOOdgM2sRXB2oQM5fm4R4h3RJIe+QN CrIe7qrGGzTz+tY4+LFZoWa1+qpOeWgPcAarNUrmsnZB7U/j72vexOhTogyhk+tJ8Tpq fyN07q0ILdT+yOmur8yNWEfWV23o//NYHzzp428I0rBJD8xZ1K4SGUEPh33Zi9dWzGp3 CfK8tEFhTs7RPfi0H46Q4aJCkXnX6wZgMrm+X0iLCfyfDVOjbLDz1rafk/aDY9MM6iqF fQ8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=eIJlPU2P; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb11-20020a170907160b00b007ae6fe0f286si3026878ejc.12.2022.11.18.00.28.46; Fri, 18 Nov 2022 00:29:12 -0800 (PST) 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=@infradead.org header.s=casper.20170209 header.b=eIJlPU2P; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241345AbiKRH7Y (ORCPT + 91 others); Fri, 18 Nov 2022 02:59:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241326AbiKRH6z (ORCPT ); Fri, 18 Nov 2022 02:58:55 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA90213FB4; Thu, 17 Nov 2022 23:58:52 -0800 (PST) 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=A67AbkwP8KX00tPROSsJtMhFn5xZm18oI+Xo3K1Eqq0=; b=eIJlPU2PyZr0szgoTA8RuS/IGy EGTxgMMLgQe4PlP1kYan4s1cl73MClWuUsiK88vNCDo82C4l32pPmyJGpNZj3sQFApzGtkfEOOXed vzc28k8SEOpiPLCeDGOBHo7Jso3Egj4ciBSw68nq62O+IGnMTil9nO/4zy6H1J7QdzphAeSDrUqJK 5puyV/PLfmc6uAyc4dqV9oAlH6UAxPZI3zRdTdoJJqDeeRf4NuxR42JYYY7MVO/UMvh406/HqgU0f s6qWB4j1eQ6kZkgYckQo/OjVEf03W/LNURRNPYflbqAoGPDR2tIfZTwkZMV1lsz0I7NVJ2bCmAZPi lLCBP2Nw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1ovwH0-0024Mo-N6; Fri, 18 Nov 2022 07:58:54 +0000 Date: Fri, 18 Nov 2022 07:58:54 +0000 From: Matthew Wilcox To: Liu Shixin Cc: Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] fs/buffer: fix a NULL pointer dereference in drop_buffers() Message-ID: References: <20221109095018.4108726-1-liushixin2@huawei.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 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 On Fri, Nov 18, 2022 at 03:54:54PM +0800, Liu Shixin wrote: > On 2022/11/18 13:30, Matthew Wilcox wrote: > > On Wed, Nov 09, 2022 at 05:50:18PM +0800, Liu Shixin wrote: > >> syzbot found a null-ptr-deref by KASAN: > >> > >> BUG: KASAN: null-ptr-deref in instrument_atomic_read include/linux/instrumented.h:71 [inline] > >> BUG: KASAN: null-ptr-deref in atomic_read include/linux/atomic/atomic-instrumented.h:27 [inline] > >> BUG: KASAN: null-ptr-deref in buffer_busy fs/buffer.c:2856 [inline] > >> BUG: KASAN: null-ptr-deref in drop_buffers+0x61/0x2f0 fs/buffer.c:2868 > >> Read of size 4 at addr 0000000000000060 by task syz-executor.5/24786 > >> > >> CPU: 0 PID: 24786 Comm: syz-executor.5 Not tainted 6.0.0-syzkaller-09589-g55be6084c8e0 #0 > >> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/22/2022 > >> Call Trace: > >> > >> __dump_stack lib/dump_stack.c:88 [inline] > >> dump_stack_lvl+0x1e3/0x2cb lib/dump_stack.c:106 > >> print_report+0xf1/0x220 mm/kasan/report.c:436 > >> kasan_report+0xfb/0x130 mm/kasan/report.c:495 > >> kasan_check_range+0x2a7/0x2e0 mm/kasan/generic.c:189 > >> instrument_atomic_read include/linux/instrumented.h:71 [inline] > >> atomic_read include/linux/atomic/atomic-instrumented.h:27 [inline] > >> buffer_busy fs/buffer.c:2856 [inline] > >> drop_buffers+0x61/0x2f0 fs/buffer.c:2868 > >> try_to_free_buffers+0x2b1/0x640 fs/buffer.c:2898 > >> [...] > >> > >> We use folio_has_private() to decide whether call filemap_release_folio(), > >> which may call try_to_free_buffers() then. folio_has_private() return true > >> for both PG_private and PG_private_2. We should only call try_to_free_buffers() > >> for case PG_private. So we should recheck PG_private in try_to_free_buffers(). > >> > >> Reported-by: syzbot+fbdb4ec578ebdcfb9ed2@syzkaller.appspotmail.com > >> Fixes: 266cf658efcf ("FS-Cache: Recruit a page flags for cache management") > > but this can only happen for a filesystem which uses both bufferheads > > and PG_private_2. afaik there aren't any of those in the tree. so > > this bug can't actually happen. > > > > if you have your own filesystem that does, you need to submit it. > This null-ptr-deref is found by syzbot, not by my own filesystem. I review the related code and > found no other possible cause. There are lock protection all the place calling try_to_free_buffers(). > So I only thought of this one possibility. I'm also trying to reproduce the problem but haven't > been successful. > > If this can't actually happen, maybe I'm missing something when review the code. I'll keep trying > to see if I can reproduce the problem. perhaps you could include more information, like the rest of the call stack so we can see what filesystem is involved?