Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp371525imu; Thu, 3 Jan 2019 22:28:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/XWv3jnhZ273wxf/9jBMjB2DQq6AoJa5obI+HDWbGcV54lNTSKxZTj/KMaYDoX45X/QdzjC X-Received: by 2002:a62:3888:: with SMTP id f130mr50137025pfa.132.1546583313440; Thu, 03 Jan 2019 22:28:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546583313; cv=none; d=google.com; s=arc-20160816; b=rWw8IPR6KFTMn6KYnjvJNiBT9dMB4dd0VEKueept/VrcTFgc7hKD7U/6rYhy3NGAtn S4I2osHkMV0R4rUE0KWvfcKD7mfeD/Tj+ByHzidm6fc710iaYZznDx0EbuvOqhst/tL+ FqIwAgndrGb203tyK0FPVYnIRmsvHCmY6/uZbLhUvIQSpqb5BGQmF5jq/h/Hk9597ZBE 9Mv5XOYYxHFvpYE/HArNnPfYUrJxvQQT/XKmBYsuC2yst32zAt4HTRs6AZjv96cLu2Nf s96HCI/eQepD5bhA+0TDlThyoPrW+jbRBoAz3fdkeVhliIDuce92s1I9+ilg9tKMht09 /mEw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=f9k4z04HE1fl5chKdZFrU6fOx32MYzvmQq66EUzfVf8=; b=pLj4ayrSGcixTn38XS9eyAcb+fXpXK2siDI4HNyD/mKjtbOOWiJBEOSY/cEm9Njxsr R7I/Sm4ra6EK0lmVPsLWMrcO0bfpr4qErm3gsxuwgthTNwRYeXvjDAzGc4l5QF/UHKvE T6N8/OPP2Fvac10hkwlnQZfOKOFrktvy79InfkonC0P6P/IDArBT/irrYVtFZK5oX0Vf 8Xi1bI09d/XAjYplyJRkUwqv8O7al4BehsVvdDli76DdXNWMDyWzkS2HasPCQy7PLRes xUahZ2QGN7yDQXtpbAAMUWgiugVbCVba9YzmSp4Sm0/JsWCYPIAvCoGpje5AYPRDwgOa 8H3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rkCaBQSX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w67si6615499pgb.45.2019.01.03.22.28.18; Thu, 03 Jan 2019 22:28:33 -0800 (PST) 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=rkCaBQSX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727676AbfADEUc (ORCPT + 99 others); Thu, 3 Jan 2019 23:20:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:56232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727353AbfADEU2 (ORCPT ); Thu, 3 Jan 2019 23:20:28 -0500 Received: from localhost (unknown [104.132.1.71]) (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 29C4621871; Fri, 4 Jan 2019 04:20:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546575627; bh=AdBdhI0wNEHnRS0xHXT9PYbegyI4DnY4KfHaq4c9Jv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rkCaBQSXhuQe/E9fIoi/rx3txxGZduL7EBgy0Qm8MYGkaqzaev3ft+X7fkODjpldL Nuv0YuocGK+PyfLLED3Qe7LAA1vf4J6lb4T3UPHyHChGRWZ7nDLDTS17S9a63Itb2P VImiUiRYKQ+RAe6PebkzhfRNGtTZOrvhpo5OdW7o= From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim Subject: [PATCH 2/2] f2fs: don't access node/meta inode mapping after iput Date: Thu, 3 Jan 2019 20:20:25 -0800 Message-Id: <20190104042025.31982-2-jaegeuk@kernel.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20190104042025.31982-1-jaegeuk@kernel.org> References: <20190104042025.31982-1-jaegeuk@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") Signed-off-by: Jaegeuk Kim --- 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 ebcc121920ba..503fde8349e6 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c @@ -96,8 +96,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); @@ -175,7 +177,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) @@ -258,10 +259,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 c46a1d4318d4..14f033e1ab42 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1075,7 +1075,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() @@ -3410,6 +3413,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: @@ -3422,6 +3426,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.19.0.605.g01d371f741-goog