From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4AF319FA8E; Tue, 30 Jul 2024 12:45:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722343547; cv=none; b=TLI7g4SewznbgRTr/NfWchGk5FSFoAfHdAXesOZGCApevyJZhlVePcvKmKTOlnVVKmpuorPEJr5W6tRpBEmipXcYLvSMlqBst37uN6UUAyIgX4OSPaamczvEJaVudRgdO+TfiJ752qioSL3reco5iyETlCpc6Dbj+5TblwmRqzU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722343547; c=relaxed/simple; bh=XWTARRowdjY3QktMvuGHZcbd38eM+zdytJtjo9ooQ8M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lGMEaTwfqkB8QVinDBBkKIcgiDjyrgiObFvny0B/u5EzZGf1EKT2g09Pax/6CfHMuAVzUgBYq0zPGqMg8ZgHuBehDAqB/Pi2Sx2Jsas4wU04giIVVgu41HlAwk33z711ujHkWSwfZ42Yq0wlldUSWOMT1qIbxHK0fVqRIycQYRw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TdEvJ5QC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TdEvJ5QC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FDA1C4AF0A; Tue, 30 Jul 2024 12:45:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722343546; bh=XWTARRowdjY3QktMvuGHZcbd38eM+zdytJtjo9ooQ8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TdEvJ5QC7sPG9FMjnjBzh+mLD+cX0hQ6NcdI52aSjFYx/AK6PWCX7j+pAYHhVg01m cLxenjsffxPK3vUxDjexgohSieWASO1DlmqwW9z7qRj3na20neIS2nSNE5RTEKNPco 0Z7xCa++xx96zOUGz8C4XqxswvAw1Q1wfcm3rxbHkUvQ20glvs3jFli5ciMEcMjvBO 9+Ni4dNaPOe2wUdfCQzKvZzDSDq5Zai6FWOfWCJ+oiFj30VM3JQTk97tmuvm1/JVmq FSp8ZwrmT4L8t/bVw5t7wFL/DYhAiqeOjQiZHsW2BIgouHR9Dl7eWCRfAGV2BalvE+ QH5HK8h60lXkw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Chao Yu , Jaegeuk Kim , Sasha Levin , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH AUTOSEL 6.6 2/7] f2fs: fix to do sanity check on blocks for inline_data inode Date: Tue, 30 Jul 2024 08:45:32 -0400 Message-ID: <20240730124542.3095044-2-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240730124542.3095044-1-sashal@kernel.org> References: <20240730124542.3095044-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.43 Content-Transfer-Encoding: 8bit From: Chao Yu [ Upstream commit c240c87bcd44a1a2375fc8ef8c645d1f1fe76466 ] inode can be fuzzed, so it can has F2FS_INLINE_DATA flag and valid i_blocks/i_nid value, this patch supports to do extra sanity check to detect such corrupted state. Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/f2fs.h | 2 +- fs/f2fs/inline.c | 20 +++++++++++++++++++- fs/f2fs/inode.c | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index c7e717ab09000..1252d57228dc6 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4143,7 +4143,7 @@ extern struct kmem_cache *f2fs_inode_entry_slab; * inline.c */ bool f2fs_may_inline_data(struct inode *inode); -bool f2fs_sanity_check_inline_data(struct inode *inode); +bool f2fs_sanity_check_inline_data(struct inode *inode, struct page *ipage); bool f2fs_may_inline_dentry(struct inode *inode); void f2fs_do_read_inline_data(struct page *page, struct page *ipage); void f2fs_truncate_inline_inode(struct inode *inode, diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 2fe25619ccb5f..529b88f0b8cc5 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -33,11 +33,29 @@ bool f2fs_may_inline_data(struct inode *inode) return !f2fs_post_read_required(inode); } -bool f2fs_sanity_check_inline_data(struct inode *inode) +static bool inode_has_blocks(struct inode *inode, struct page *ipage) +{ + struct f2fs_inode *ri = F2FS_INODE(ipage); + int i; + + if (F2FS_HAS_BLOCKS(inode)) + return true; + + for (i = 0; i < DEF_NIDS_PER_INODE; i++) { + if (ri->i_nid[i]) + return true; + } + return false; +} + +bool f2fs_sanity_check_inline_data(struct inode *inode, struct page *ipage) { if (!f2fs_has_inline_data(inode)) return false; + if (inode_has_blocks(inode, ipage)) + return false; + if (!support_inline_data(inode)) return true; diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index ab2eecd986ec5..abe2f5f043b0d 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -343,7 +343,7 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page) } } - if (f2fs_sanity_check_inline_data(inode)) { + if (f2fs_sanity_check_inline_data(inode, node_page)) { f2fs_warn(sbi, "%s: inode (ino=%lx, mode=%u) should not have inline_data, run fsck to fix", __func__, inode->i_ino, inode->i_mode); return false; -- 2.43.0