]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
f2fs: fix to do sanity check in update_sit_entry
authorZhiguo Niu <zhiguo.niu@unisoc.com>
Wed, 28 Feb 2024 11:59:54 +0000 (19:59 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Sep 2024 11:17:37 +0000 (13:17 +0200)
[ Upstream commit 36959d18c3cf09b3c12157c6950e18652067de77 ]

If GET_SEGNO return NULL_SEGNO for some unecpected case,
update_sit_entry will access invalid memory address,
cause system crash. It is better to do sanity check about
GET_SEGNO just like update_segment_mtime & locate_dirty_segment.

Also remove some redundant judgment code.

Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/f2fs/segment.c

index 134a78179e6ff8092f322c9f838669be98a507bd..6fcc83637b153cff247c4d76a6808f663d49868c 100644 (file)
@@ -2215,6 +2215,8 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
 #endif
 
        segno = GET_SEGNO(sbi, blkaddr);
+       if (segno == NULL_SEGNO)
+               return;
 
        se = get_seg_entry(sbi, segno);
        new_vblocks = se->valid_blocks + del;
@@ -3391,8 +3393,7 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
         * since SSR needs latest valid block information.
         */
        update_sit_entry(sbi, *new_blkaddr, 1);
-       if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO)
-               update_sit_entry(sbi, old_blkaddr, -1);
+       update_sit_entry(sbi, old_blkaddr, -1);
 
        if (!__has_curseg_space(sbi, curseg)) {
                if (from_gc)