Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7151758ybi; Mon, 8 Jul 2019 15:41:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZ+cVYPsnoOCVt7Q5wGvoLV7+dsFkvbxNrmqZj1VvtrWRtz8IDoE6jISJ7DfyAN7BGt2RC X-Received: by 2002:a63:1c22:: with SMTP id c34mr16922168pgc.56.1562625687282; Mon, 08 Jul 2019 15:41:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625687; cv=none; d=google.com; s=arc-20160816; b=UMdxna7/hco6CNQw6jjC2G1wyCRdRYBHjHq5gCFU89v7Gbb22kv1LBYry7nFzQqkdq FcR5GL5VcT8TmN6LxY6H0SamEb5LSXujUaGsEMBGZfYmx53v/u5XrKiHFzHQQ5Yb3xwY 6BjMefeNGyV0j3WiLb9sBn0zq7PmR6H18LaVlQZxS6U5FHD6PA4LZ6oge4hOYPmzt0zO mD1zi5Mbv0jndT5OSXUAFxEO2wyRi54vx6OoyXXndAmoz9FnL91+MCezFKHAOjZfKdFW dWVQeOKaCtLYRXKVMbsJfrPSlph0SRpAtFONxLntiPCj+zakkMMbCGSDc89j8iRmIvjY Eq/w== 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=RL775sdt0Q7YMpTT85jUeIIaktYh3GVioRQ2TgNCwv4=; b=Tk0uDqT/vwx89KNHtBOX//nCnKxf00/yaO2YvFZuZkYdbmQFrZTDlzdDptD+gGONcT uG/4zGGdpNcWN/yQyg8HN9STpVNKe4E0kro9egUp0wmUt3AzwZr+hMIOvTEMysDgCypj 5YzPy7aXqBrbbTc2ZSzIqLvnPW7JcphTdXlWh1yIKL3TNXH9S7LmyLdhtZoCCKmHTkmm +y59XHBwjY4RtZC3wKShHzHiG+CCAzLA7eSQ6KFhjJcJnMs0q7wsDdfPuSsclOZ5MhnA byiebkJNWtHAzRMNRrY9ABqoXaSMgGDLUp3XFMPph9DNmOR1n9v0F/KS6+ZegO74RdkF BwxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fzEKKnz1; 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 e62si8353607pfh.254.2019.07.08.15.41.12; Mon, 08 Jul 2019 15:41:27 -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=fzEKKnz1; 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 S2390819AbfGHPjn (ORCPT + 99 others); Mon, 8 Jul 2019 11:39:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:58076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732065AbfGHP3T (ORCPT ); Mon, 8 Jul 2019 11:29:19 -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 334D4204EC; Mon, 8 Jul 2019 15:29:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562599757; bh=GggVCx1Hlzk+MVuJdPjICVgcV5W9PyPoL0nOFalkwYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fzEKKnz1ndbgMD8QtdqkWxXYXvbLY4as5M8wtHDQkRnUgBFvsqBPOEF2XdBqX/xRd rRIB0D+8EGmzFt/jviy/6j19yM6Zinj5hEdqo5IlvZrvtTUd3niyc/w2zTdFteuwur T+Zau/XNOYv/zH6aTAImL4sIWUG+7MwdvoHikpEA= 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 4.19 68/90] f2fs: dont access node/meta inode mapping after iput Date: Mon, 8 Jul 2019 17:13:35 +0200 Message-Id: <20190708150525.790996587@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150521.829733162@linuxfoundation.org> References: <20190708150521.829733162@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 [ Upstream commit 7c77bf7de1574ac7a31a2b76f4927404307d13e7 ] This fixes wrong access of address spaces of node and meta inodes after iput. Fixes: 60aa4d5536ab ("f2fs: fix use-after-free issue when accessing sbi->stat_info") Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/debug.c | 19 ++++++++++++------- fs/f2fs/super.c | 5 +++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index ebe649d9793c..bbe155465ca0 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c @@ -94,8 +94,10 @@ static void update_general_status(struct f2fs_sb_info *sbi) si->free_secs = free_sections(sbi); si->prefree_count = prefree_segments(sbi); si->dirty_count = dirty_segments(sbi); - si->node_pages = NODE_MAPPING(sbi)->nrpages; - si->meta_pages = META_MAPPING(sbi)->nrpages; + if (sbi->node_inode) + si->node_pages = NODE_MAPPING(sbi)->nrpages; + if (sbi->meta_inode) + si->meta_pages = META_MAPPING(sbi)->nrpages; si->nats = NM_I(sbi)->nat_cnt; si->dirty_nats = NM_I(sbi)->dirty_nat_cnt; si->sits = MAIN_SEGS(sbi); @@ -168,7 +170,6 @@ static void update_sit_info(struct f2fs_sb_info *sbi) static void update_mem_info(struct f2fs_sb_info *sbi) { struct f2fs_stat_info *si = F2FS_STAT(sbi); - unsigned npages; int i; if (si->base_mem) @@ -251,10 +252,14 @@ static void update_mem_info(struct f2fs_sb_info *sbi) sizeof(struct extent_node); si->page_mem = 0; - npages = NODE_MAPPING(sbi)->nrpages; - si->page_mem += (unsigned long long)npages << PAGE_SHIFT; - npages = META_MAPPING(sbi)->nrpages; - si->page_mem += (unsigned long long)npages << PAGE_SHIFT; + if (sbi->node_inode) { + unsigned npages = NODE_MAPPING(sbi)->nrpages; + si->page_mem += (unsigned long long)npages << PAGE_SHIFT; + } + if (sbi->meta_inode) { + unsigned npages = META_MAPPING(sbi)->nrpages; + si->page_mem += (unsigned long long)npages << PAGE_SHIFT; + } } static int stat_show(struct seq_file *s, void *v) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 2264f27fd26d..1871031e2d5e 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1050,7 +1050,10 @@ static void f2fs_put_super(struct super_block *sb) f2fs_bug_on(sbi, sbi->fsync_node_num); iput(sbi->node_inode); + sbi->node_inode = NULL; + iput(sbi->meta_inode); + sbi->meta_inode = NULL; /* * iput() can update stat information, if f2fs_write_checkpoint() @@ -3166,6 +3169,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) f2fs_release_ino_entry(sbi, true); truncate_inode_pages_final(NODE_MAPPING(sbi)); iput(sbi->node_inode); + sbi->node_inode = NULL; free_stats: f2fs_destroy_stats(sbi); free_nm: @@ -3178,6 +3182,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) free_meta_inode: make_bad_inode(sbi->meta_inode); iput(sbi->meta_inode); + sbi->meta_inode = NULL; free_io_dummy: mempool_destroy(sbi->write_io_dummy); free_percpu: -- 2.20.1