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=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,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 977F8C433E0 for ; Thu, 11 Jun 2020 01:41:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B25820801 for ; Thu, 11 Jun 2020 01:41:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591839698; bh=hjb8pPe585bninkqwnEsOxv0+a0hwjjw3C85+ies9CE=; h=Date:From:To:Subject:In-Reply-To:List-ID:From; b=QTTv1YjvIoYUjhRcjOb6xSYcIZikjob2JrlvXnoaTLKi0sngU1t+uLsTPL1D7Nxme Uc+vBhqgd5hqZ/Wl4Rvqvv0SPptjjvrTleXMDnWrexHUg7F4bHcgzTcFGPo5rs0Gru kG024HyqKtaFBhmMz6iNqUd6dWGC/EwmlnI32wYA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726418AbgFKBli (ORCPT ); Wed, 10 Jun 2020 21:41:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:50282 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726163AbgFKBlh (ORCPT ); Wed, 10 Jun 2020 21:41:37 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (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 9F8842074B; Thu, 11 Jun 2020 01:41:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591839696; bh=hjb8pPe585bninkqwnEsOxv0+a0hwjjw3C85+ies9CE=; h=Date:From:To:Subject:In-Reply-To:From; b=ZDKKUTdFpXXp1beKgBhU402bvkiaJfLLOUUGnseHaN3uCLXrZZVrAkc+n+T6A13O0 R35OxB2SSFe3t/epV5xkhqrBciDbizq+nlbNeGmTXOA7oqDi+Vs23P/6R1cKft/cKR bYNv2uqyfyX3ksWuo2gOLjJrYyMg9dobwBTajqOo= Date: Wed, 10 Jun 2020 18:41:35 -0700 From: Andrew Morton To: akpm@linux-foundation.org, hdk1983@gmail.com, hermes@ceres.dti.ne.jp, konishi.ryusuke@gmail.com, linux-mm@kvack.org, me@waltonhoops.com, mm-commits@vger.kernel.org, stable@vger.kernel.org, tom@logand.com, torvalds@linux-foundation.org Subject: [patch 05/25] nilfs2: fix null pointer dereference at nilfs_segctor_do_construct() Message-ID: <20200611014135.qj6WrSl6h%akpm@linux-foundation.org> In-Reply-To: <20200610184053.3fa7368ab80e23bfd44de71f@linux-foundation.org> User-Agent: s-nail v14.8.16 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Ryusuke Konishi Subject: nilfs2: fix null pointer dereference at nilfs_segctor_do_construct() After commit c3aab9a0bd91 ("mm/filemap.c: don't initiate writeback if mapping has no dirty pages"), the following null pointer dereference has been reported on nilfs2: BUG: kernel NULL pointer dereference, address: 00000000000000a8 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 0 P4D 0 Oops: 0000 [#1] SMP PTI ... RIP: 0010:percpu_counter_add_batch+0xa/0x60 ... Call Trace: __test_set_page_writeback+0x2d3/0x330 nilfs_segctor_do_construct+0x10d3/0x2110 [nilfs2] nilfs_segctor_construct+0x168/0x260 [nilfs2] nilfs_segctor_thread+0x127/0x3b0 [nilfs2] kthread+0xf8/0x130 ... This crash turned out to be caused by set_page_writeback() call for segment summary buffers at nilfs_segctor_prepare_write(). set_page_writeback() can call inc_wb_stat(inode_to_wb(inode), WB_WRITEBACK) where inode_to_wb(inode) is NULL if the inode of underlying block device does not have an associated wb. This fixes the issue by calling inode_attach_wb() in advance to ensure to associate the bdev inode with its wb. Link: http://lkml.kernel.org/r/20200608.011819.1399059588922299158.konishi.ryusuke@gmail.com Fixes: c3aab9a0bd91 ("mm/filemap.c: don't initiate writeback if mapping has no dirty pages") Signed-off-by: Ryusuke Konishi Tested-by: Ryusuke Konishi Reported-by: Walton Hoops Reported-by: Tomas Hlavaty Reported-by: ARAI Shun-ichi Reported-by: Hideki EIRAKU Cc: [5.4+] Signed-off-by: Andrew Morton --- fs/nilfs2/segment.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/nilfs2/segment.c~nilfs2-fix-null-pointer-dereference-at-nilfs_segctor_do_construct +++ a/fs/nilfs2/segment.c @@ -2780,6 +2780,8 @@ int nilfs_attach_log_writer(struct super if (!nilfs->ns_writer) return -ENOMEM; + inode_attach_wb(nilfs->ns_bdev->bd_inode, NULL); + err = nilfs_segctor_start_thread(nilfs->ns_writer); if (err) { kfree(nilfs->ns_writer); _