Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3389156ybp; Sun, 6 Oct 2019 10:51:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwbAdQZh4RPSdQmFJzMOZsEENgeq5DXIuar6RxEjk0n6jW8tSCJ93XgLazVUEbkuaTefgPq X-Received: by 2002:a17:906:3717:: with SMTP id d23mr14132325ejc.266.1570384296233; Sun, 06 Oct 2019 10:51:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570384296; cv=none; d=google.com; s=arc-20160816; b=uPrAYZFmCEfupz4d2TSqfsQR/KqjaDLTdDGod+Cd0emdA4pRPdLtHpyUZ8h5MKp0kY OJsFpK8u+GKPwlDEJQJY73hv/tsRIkWFm5k6R/P5KNTkg1dg3Pz/74q1a9P4qWV3JbuD b6latFMwrr2qaPM5b/XW9PmOghZqIdIxO78O5qfGWSbIj/4+HvjbXWauQVcx2fhpUOw+ VZ7NKZSXZ1mCi8UzH/epPXPeJ4WPQyAhrg5ZUEGpoJFsl8YK7+IGDfXPcdAADxItBHEG SSH595uztRqGSwhUG3i7AurvW/m284XfrAs7BN1y52KX/BWOtqlKdJPxIB+w3mWewllb 4miw== 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=J2MiTIhMrn8Z7xaSS7pSrjio8bQyU8Lp3WGxXN/tjEc=; b=rgAcQF6Pnmv1oo+e/Blt555SIMAtU3eaqMcgIg4rvGooN+w4ueEdAJZem8W4TwpZg3 6ryA/RykdQoHVxuSxfeTmbMPf+qNWZFmmT8+yR7CzGWPoQz0U0c5BD9a5+kolblGebe5 E75bZ6zuYRber8rB8pICwJ/7P9FbK92Vf8RmAprvofxOG9D4WjBergiOdQW+zkhlKyXT Ul7X4O5vJSWSp1Habs1fY7yhEFKye9tGV3dTblUpYARsiueYmFuoO5ZU0rqyqDNarak3 oSPbbmr0WM3ogBrrJIPzW83AiA73gZhw3VsiExnxOADWmuYTcsVFWQUuj5d/w77G/KBJ H6fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RUFJFJRe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z35si7160435edd.340.2019.10.06.10.51.12; Sun, 06 Oct 2019 10:51:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RUFJFJRe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731361AbfJFRmg (ORCPT + 99 others); Sun, 6 Oct 2019 13:42:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:42396 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730701AbfJFRmc (ORCPT ); Sun, 6 Oct 2019 13:42:32 -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 65C1921479; Sun, 6 Oct 2019 17:42:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383751; bh=es2vIaM7f5xW4Dh/JCsV+tGaGa4oEA9m7N0liZ52Yc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RUFJFJRecNj6EFqN/OCIq+xPT6T5VPt0b99PV6c6EVJ57W4/mnqXhV3HDEZ1uiYQk Tj55ABOPaPmMzatEFL/xOsXmHJFq0keQHud91/RM6kEgNfaCWCGN8oc6Co2xj2pcwF HnCfrMm2N0CBMfuNW8ztQ7QH3mQjnwVvvuXhEhsA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.3 080/166] f2fs: fix to drop meta/node pages during umount Date: Sun, 6 Oct 2019 19:20:46 +0200 Message-Id: <20191006171220.203324633@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171212.850660298@linuxfoundation.org> References: <20191006171212.850660298@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: Chao Yu [ Upstream commit a8933b6b68f775b5774e7b075447fae13f4d01fe ] As reported in bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204193 A null pointer dereference bug is triggered in f2fs under kernel-5.1.3. kasan_report.cold+0x5/0x32 f2fs_write_end_io+0x215/0x650 bio_endio+0x26e/0x320 blk_update_request+0x209/0x5d0 blk_mq_end_request+0x2e/0x230 lo_complete_rq+0x12c/0x190 blk_done_softirq+0x14a/0x1a0 __do_softirq+0x119/0x3e5 irq_exit+0x94/0xe0 call_function_single_interrupt+0xf/0x20 During umount, we will access NULL sbi->node_inode pointer in f2fs_write_end_io(): f2fs_bug_on(sbi, page->mapping == NODE_MAPPING(sbi) && page->index != nid_of_node(page)); The reason is if disable_checkpoint mount option is on, meta dirty pages can remain during umount, and then be flushed by iput() of meta_inode, however node_inode has been iput()ed before meta_inode's iput(). Since checkpoint is disabled, all meta/node datas are useless and should be dropped in next mount, so in umount, let's adjust drop_inode() to give a hint to iput_final() to drop all those dirty datas correctly. Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/super.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 78a1b873e48ad..aa3178f1b145d 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -873,7 +873,21 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb) static int f2fs_drop_inode(struct inode *inode) { + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); int ret; + + /* + * during filesystem shutdown, if checkpoint is disabled, + * drop useless meta/node dirty pages. + */ + if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { + if (inode->i_ino == F2FS_NODE_INO(sbi) || + inode->i_ino == F2FS_META_INO(sbi)) { + trace_f2fs_drop_inode(inode, 1); + return 1; + } + } + /* * This is to avoid a deadlock condition like below. * writeback_single_inode(inode) -- 2.20.1