* [PATCH] f2fs: fix to do sanity check in update_sit_entry
@ 2024-02-28 11:59 Zhiguo Niu
2024-03-01 1:15 ` Chao Yu
2024-03-04 18:20 ` [f2fs-dev] " patchwork-bot+f2fs
0 siblings, 2 replies; 3+ messages in thread
From: Zhiguo Niu @ 2024-02-28 11:59 UTC (permalink / raw)
To: jaegeuk, chao
Cc: linux-f2fs-devel, linux-kernel, niuzhiguo84, zhiguo.niu, ke.wang,
hongyu.jin
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>
---
fs/f2fs/segment.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index c616e7a..f8a823f 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2407,6 +2407,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;
@@ -3504,8 +3506,7 @@ int 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 the current segment is full, flush it out and replace it with a
--
1.9.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] f2fs: fix to do sanity check in update_sit_entry
2024-02-28 11:59 [PATCH] f2fs: fix to do sanity check in update_sit_entry Zhiguo Niu
@ 2024-03-01 1:15 ` Chao Yu
2024-03-04 18:20 ` [f2fs-dev] " patchwork-bot+f2fs
1 sibling, 0 replies; 3+ messages in thread
From: Chao Yu @ 2024-03-01 1:15 UTC (permalink / raw)
To: Zhiguo Niu, jaegeuk
Cc: linux-f2fs-devel, linux-kernel, niuzhiguo84, ke.wang, hongyu.jin
On 2024/2/28 19:59, Zhiguo Niu wrote:
> 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>
Thanks,
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: fix to do sanity check in update_sit_entry
2024-02-28 11:59 [PATCH] f2fs: fix to do sanity check in update_sit_entry Zhiguo Niu
2024-03-01 1:15 ` Chao Yu
@ 2024-03-04 18:20 ` patchwork-bot+f2fs
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+f2fs @ 2024-03-04 18:20 UTC (permalink / raw)
To: Zhiguo Niu
Cc: jaegeuk, chao, ke.wang, linux-kernel, linux-f2fs-devel,
hongyu.jin, niuzhiguo84
Hello:
This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:
On Wed, 28 Feb 2024 19:59:54 +0800 you wrote:
> 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.
>
> [...]
Here is the summary with links:
- [f2fs-dev] f2fs: fix to do sanity check in update_sit_entry
https://git.kernel.org/jaegeuk/f2fs/c/36959d18c3cf
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-04 18:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-28 11:59 [PATCH] f2fs: fix to do sanity check in update_sit_entry Zhiguo Niu
2024-03-01 1:15 ` Chao Yu
2024-03-04 18:20 ` [f2fs-dev] " patchwork-bot+f2fs
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®