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 Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A8A8DC43219 for ; Tue, 18 Oct 2022 00:08:44 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1oka9z-000451-Q7; Tue, 18 Oct 2022 00:08:43 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oka9x-00044v-S4 for linux-f2fs-devel@lists.sourceforge.net; Tue, 18 Oct 2022 00:08:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=o1DL+qiHYnPbHfFwBK4iBKWwA+1gSoVJdOL4VQF/0Mc=; b=leOMkjb0DyB8ptnPVGBWQjUdRs 9/xgo+WPPDBZBBp7FghEfW/sJBXCobBIcEaOhX73s+m1/srhQCMRSCHkJMEfqCuuTWUh3hcBU5HJ2 dQxs4R+aK8hie6Zu1yDkT8uSUMK335uoLG53nPZ0cxoqUBH+/5zf/jnQ56qYJDIB/MOM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=o1DL+qiHYnPbHfFwBK4iBKWwA+1gSoVJdOL4VQF/0Mc=; b=ZbmHmzh049RjQ04aqpPzJgYxhs Kpk5nPFtNTStcCTkwQ3y1g5uCTsH0ozmBNDpSwpBexJBU3A7gkmbnuWzWh6A2o2MfH4xICt8VS/1I MTG8sPjL6uWkbajeQKAaFRw4ksrEYxfo7Gj4nxo4EC1nX7iL8uAEXibJwpXP9XR5jX3I=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1oka9w-0001zX-K0 for linux-f2fs-devel@lists.sourceforge.net; Tue, 18 Oct 2022 00:08:41 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8A4B461325 for ; Tue, 18 Oct 2022 00:08:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA7A4C4314E; Tue, 18 Oct 2022 00:08:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666051708; bh=bL+HVvxvMiGzHrLEK7xG66xFmN5yqlydb7A787zVHMw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hyTOaNSQcJp6+G2LETmULp4qHMyrkqxrWQzqvVAFWbR+SdkfFw/QCXx36rX2H/GqV DL/uUVw4m5k6frIfWVtzsM7mG4jDU4IpILrZ4yJzTa4osyf8fwM7GoGFI7qMjO0jby 2D82urxgspVaPDGzuxkkF8bNpIzKc2wyrdKBfQFwGKBlOivp5D/0sMiGN3FztHNPqr nUuUZiv0zOAkMC1QXS6ILcG/7gprPVvXB9RNKo9lnS0Hb81hSuzg+QtZZ++y+zsJxy XJnb40La02dwOYEN9TJ1xUjSmIdfMeQEoeZb9/sO9rd2OFMhfqqQh8BaSoZ7mLBPJa iaqrkBR4OqHsg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Date: Mon, 17 Oct 2022 20:07:23 -0400 Message-Id: <20221018000729.2730519-26-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018000729.2730519-1-sashal@kernel.org> References: <20221018000729.2730519-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-Headers-End: 1oka9w-0001zX-K0 Subject: [f2fs-dev] [PATCH AUTOSEL 6.0 26/32] f2fs: fix to detect corrupted meta ino X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sasha Levin , Jaegeuk Kim , linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Chao Yu [ Upstream commit fcc2d8cc96b2f6141bbbe5b1e8953db990794b44 ] It is possible that ino of dirent or orphan inode is corrupted in a fuzzed image, occasionally, if corrupted ino is equal to meta ino: meta_ino, node_ino or compress_ino, caller of f2fs_iget() from below call paths will get meta inode directly, it's not allowed, let's add sanity check to detect such cases. case #1 - recover_dentry - __f2fs_find_entry - f2fs_iget_retry case #2 - recover_orphan_inode - f2fs_iget_retry Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/inode.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 6d11c365d7b4..34324ef48667 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -480,6 +480,12 @@ static int do_read_inode(struct inode *inode) return 0; } +static bool is_meta_ino(struct f2fs_sb_info *sbi, unsigned int ino) +{ + return ino == F2FS_NODE_INO(sbi) || ino == F2FS_META_INO(sbi) || + ino == F2FS_COMPRESS_INO(sbi); +} + struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) { struct f2fs_sb_info *sbi = F2FS_SB(sb); @@ -491,16 +497,21 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) return ERR_PTR(-ENOMEM); if (!(inode->i_state & I_NEW)) { + if (is_meta_ino(sbi, ino)) { + f2fs_err(sbi, "inaccessible inode: %lu, run fsck to repair", ino); + set_sbi_flag(sbi, SBI_NEED_FSCK); + ret = -EFSCORRUPTED; + trace_f2fs_iget_exit(inode, ret); + iput(inode); + return ERR_PTR(ret); + } + trace_f2fs_iget(inode); return inode; } - if (ino == F2FS_NODE_INO(sbi) || ino == F2FS_META_INO(sbi)) - goto make_now; -#ifdef CONFIG_F2FS_FS_COMPRESSION - if (ino == F2FS_COMPRESS_INO(sbi)) + if (is_meta_ino(sbi, ino)) goto make_now; -#endif ret = do_read_inode(inode); if (ret) -- 2.35.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel