f2fs: avoid out-of-range memory access
PATCH v3 1/1 f2fs: avoid out-of-range memory access
blk_off might over 512 due to fs corrupt and should be checked before being used.
Use ENTRIES_IN_SUM to protect invalid memory access.
--
v2:
- fix typo
v3:
- check blk_off before being used
--
Signed-off-by Ocean Chen <[email protected]>
--- fs/f2fs/segment.c | 3 +++ 1 file changed, 3 insertions(+)
fs/f2fs/segment.c +3 -0
@@ -3401,6 +3401,9 @@ static int read_compacted_summaries(struct f2fs_sb_info *sbi)if (seg_i->alloc_type ==SSR ) blk_off = sbi->blocks_per_seg; +if (blk_off >=ENTRIES_IN_SUM ) +return -EFAULT ; +for (j =0 ; j < blk_off; j++) {struct f2fs_summary *s; s = (struct f2fs_summary *)(kaddr + offset);
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
Quoted 20 lines · Ocean Chen
blk_offmight over 512 due to fs corrupt and should be checked before being used.
UseENTRIES_IN_SUMto protect invalid memory access.--
v2:
- fix typo
v3:
- checkblk_offbefore being used
--Signed-off-by Ocean Chen <[email protected]>--- fs/f2fs/segment.c | 3 +++ 1 file changed, 3 insertions(+)fs/f2fs/segment.c +0
-0
fs/f2fs/segment.c static int read_compacted_summaries(struct f2fs_sb_info *sbi) · line 3405
Quoted 5 lines
fs/f2fs/segment.c +2
-0@@ -3401,6 +3401,9 @@ static int read_compacted_summaries(struct f2fs_sb_info *sbi)if (seg_i->alloc_type ==SSR ) blk_off = sbi->blocks_per_seg; +if (blk_off >=ENTRIES_IN_SUM ) +return -EFAULT ;
- scripts/checkpatch.pl will complain such format.
- miss to call f2fs_put_page(page, 1) before return.
Thanks,
Quoted 5 lines
fs/f2fs/segment.c +1
-0+for (j =0 ; j < blk_off; j++) {struct f2fs_summary *s; s = (struct f2fs_summary *)(kaddr + offset);