Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp773999ybt; Fri, 19 Jun 2020 13:25:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZk1Y3rLf4cKRmWOHsUXnYZ0C/RrKNiCTu5XdWSzU4uzGNM4n3x+iTGdgxVnb4BHCQ0V1z X-Received: by 2002:a17:906:6410:: with SMTP id d16mr5591249ejm.376.1592598325467; Fri, 19 Jun 2020 13:25:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592598325; cv=none; d=google.com; s=arc-20160816; b=YpCFhr4WNGQ3xBaS2EXxVgPkna6At94TS1V+WcMN26TYUYP840sFVpwniAf1VtvwEN CdFbs8kmLR+8HwEpWJ7PS9j2GJAZRZFV3olfZd/8xIulPFtnzoB9sRL/qi/JHsEh4aGe qMnm6UpNX+HVpSptHd7uj9FXGvJS5SZ2GwqFmxSlu9MvIMy6RbRHSW9NgG6B80yzm5xY m9x3tQLRlnJrfR5TuMZ/ok76KM8a2Wl1oZLA4EkohF+pQZLh6ukmo4YaoK0OF6PaF21N o3ubuOnG2BHr9idUUeIB7ujGkwbVERaY9fCfne31ZlYmV3/Eej9XdscGY0jrjsuCb7PN dj7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=X3fQ1uecHFFbeR3wiiT4GMvk9s2gKUum8AgXHE5xrs8=; b=CXpCnzKNcLSpQuaLKz9p6sbUGqlhClZ2i1e/hj1oLgw8z1WzHBhRqyJA3IRa9Y1YhP LFu9LW56/qhSQ+DTVfgi90WwZBHjriRuH7O6/VaZ4gBJ2M/5Wor0IEH2VAhPY7j+2Zp0 L1Ckl+d7tmhPfuFIFHdDcgIEshyY68vdRAYmjNZKhIRe7LVaHa3ztYwDmBDIxPP3qHC8 E1LSc7eGXwTrQbTg1u3vOl9ff5oI+SSihV1DD7ClzDSaDC6ZhSpGls7iqvztLTyMf06n 3eX9s6PYrBXGKAzT5DK9z9GHiszasDcBnC/7vcjxbjuXEgQp3G2m1UVxfnWxdvr655NF NlqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qvBKAggz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d16si4399674edx.546.2020.06.19.13.25.03; Fri, 19 Jun 2020 13:25:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qvBKAggz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389905AbgFSOy4 (ORCPT + 99 others); Fri, 19 Jun 2020 10:54:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:49588 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389891AbgFSOyv (ORCPT ); Fri, 19 Jun 2020 10:54:51 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 D244621556; Fri, 19 Jun 2020 14:54:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592578491; bh=Z1qeNrPzQX2HeO121luRbN2+mEG0uHjTupsRDDT/lHY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qvBKAggzVQ3VDGnyAgXhJQLr8qWa70vP2OejG9Bkf23JAPhzIEtPP5iZn8F6MYTXk qQ1z4uLc3fK2CpB7Vkjcj5AhQHQSiwkNg9BfCiqrCnPFA9MuGcjjA7EhklWiFXfT0O W988AJ1KPQZpdK8QOxSrBEpJajNUoh/1cUgRrFoI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Walton Hoops , Tomas Hlavaty , ARAI Shun-ichi , Hideki EIRAKU , Ryusuke Konishi , Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 042/267] nilfs2: fix null pointer dereference at nilfs_segctor_do_construct() Date: Fri, 19 Jun 2020 16:30:27 +0200 Message-Id: <20200619141650.874090997@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141648.840376470@linuxfoundation.org> References: <20200619141648.840376470@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ryusuke Konishi commit 8301c719a2bd131436438e49130ee381d30933f5 upstream. 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. Fixes: c3aab9a0bd91 ("mm/filemap.c: don't initiate writeback if mapping has no dirty pages") Reported-by: Walton Hoops Reported-by: Tomas Hlavaty Reported-by: ARAI Shun-ichi Reported-by: Hideki EIRAKU Signed-off-by: Ryusuke Konishi Signed-off-by: Andrew Morton Tested-by: Ryusuke Konishi Cc: [5.4+] Link: http://lkml.kernel.org/r/20200608.011819.1399059588922299158.konishi.ryusuke@gmail.com Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/nilfs2/segment.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/nilfs2/segment.c +++ b/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);