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 42DE5CD98DA for ; Tue, 16 Jun 2026 09:48:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type:Cc: Reply-To:From:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Subject:MIME-Version:References:In-Reply-To: Message-ID:Date:To:Sender:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=W3bHbJotzyOXhmGwyAiQ8oGO9X2BSu6+60A1quYPliQ=; b=VfZM1pl7U/Tp3N+/VI7VtesBOz pP6CttS/0Tj0HXV5S4gwLhA/R3NgF0fUj/EmaF1d22IPnbrzdJdrAeOtIMwLwSMG7DeDgPvS0dA4o hltfUumY2cNnw59Xrspr/W+yBwJ2MUqB2CD9BYHWhJWS3Aq7SBJp3wReBqD+6QEGZhkU=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1wZQPB-0008Mh-BG; Tue, 16 Jun 2026 09:48:26 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1wZQP9-0008Mb-Pl for linux-f2fs-devel@lists.sourceforge.net; Tue, 16 Jun 2026 09:48:24 +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=b5AeoaNVGfAdnEbBqArUeJ2Koo25N1m9xuuEF8E6Vyc=; b=m69uYa/vvsRVbRss/URV45ksE1 SPg5rhgK9l/sC2RCJqvzm4ji7ngzvlZ9E3acEcNmDFC97kkgq/IzIfVe517vjG5Z7xTB1pXVo+aW2 HtCAvdB0ZCX6HQ4PefYQxvb0/Gcj/sCZREgpb9FOVKxobEPGhmRfzPJyzxAzhTkUbpZU=; 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=b5AeoaNVGfAdnEbBqArUeJ2Koo25N1m9xuuEF8E6Vyc=; b=GFwUbL77MfeqY6MbeF9DxwTeX+ CUGzgabq4lfwE+Ph8J1oeNNIC0yfdZLvsid2aMfGQnYSqMCPGIWDUWmiQaWvDwS2F/wRE9/NgcEA6 0+AgJXS7TXabnujRvhHHNO26rNXsP3YQOJHni5cEe/FvzVHMS1+5u88qDSuuUQGu7Isk=; Received: from tor.source.kernel.org ([172.105.4.254]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1wZQP8-000520-MX for linux-f2fs-devel@lists.sourceforge.net; Tue, 16 Jun 2026 09:48:24 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 78D6F60132 for ; Tue, 16 Jun 2026 09:48:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C9831F000E9; Tue, 16 Jun 2026 09:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781603292; bh=b5AeoaNVGfAdnEbBqArUeJ2Koo25N1m9xuuEF8E6Vyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cZN9NMOQY8zoDZ/MUkBUxdww88fDwMwIX1sxhWp1htp7jhUrjsqZwSLgmWsGf+Tz3 FZMHHXrtSeoFkvH4/ivzqvTvVz00OfyxaFS3RVKxCPUt72YxmDCTlAdB5DqTW3fkPK vGjeTM8uEILPIioUJApYLIARcuiYaaz6/v9Vm0NS6RkKwMGh8e32KchGu70Mi2N/QN u6BQgVOROpXenvwYXNFTqItqTEQP2nC5b88r6Q27QnEYK1zJkeCsDlphQO3PxXZG/E 068ufapSXL4UN8kJ/Am70DHOQtUbaGp2tHy0OGJ8rZ64nGNqGkRZBbhwxoN5EysQ89 mYTQj9dlOAc+Q== To: jaegeuk@kernel.org Date: Tue, 16 Jun 2026 09:48:02 +0000 Message-ID: <20260616094802.3107281-2-chao@kernel.org> X-Mailer: git-send-email 2.54.0.1136.gdb2ca164c4-goog In-Reply-To: <20260616094802.3107281-1-chao@kernel.org> References: <20260616094802.3107281-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1wZQP8-000520-MX Subject: [f2fs-dev] [PATCH 2/2] fsck.f2fs: add bounds checking for orphan entry_count 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: , From: Chao Yu via Linux-f2fs-devel Reply-To: Chao Yu Cc: 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 In fsck_chk_orphan_node(), entry_count is read directly from the on-disk orphan block footer. If an attacker or corrupted filesystem sets this to an excessive value (e.g., 0xFFFFFFFF), it can cause a massive loop leading to out-of-bounds memory reads and out-of-bounds writes into the newly allocated orphan repair block. Fix this by ensuring entry_count does not exceed F2FS_ORPHANS_PER_BLOCK. If an invalid entry_count is encountered, safely reset it to 0 and write the repaired orphan block to disk when running with auto-fix enabled. Signed-off-by: Chao Yu --- fsck/fsck.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fsck/fsck.c b/fsck/fsck.c index e679357..66cc1c5 100644 --- a/fsck/fsck.c +++ b/fsck/fsck.c @@ -2275,6 +2275,17 @@ int fsck_chk_orphan_node(struct f2fs_sb_info *sbi) ASSERT(ret >= 0); entry_count = le32_to_cpu(F2FS_ORPHAN_BLOCK_FOOTER(orphan_blk)->entry_count); + if (entry_count > F2FS_ORPHANS_PER_BLOCK) { + ASSERT_MSG("wrong orphan entry_count: %u", entry_count); + entry_count = 0; + if (f2fs_dev_is_writable() && c.fix_on) { + FIX_MSG("reset orphan entry_count to 0"); + F2FS_ORPHAN_BLOCK_FOOTER(new_blk)->entry_count = 0; + ret = dev_write_block(new_blk, start_blk + i, + WRITE_LIFE_NONE); + ASSERT(ret >= 0); + } + } for (j = 0; j < entry_count; j++) { nid_t ino = le32_to_cpu(orphan_blk->ino[j]); -- 2.49.0 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel