Skip to content

Commit ef83274

Browse files
konisakpm00
authored andcommitted
nilfs2: initialize unused bytes in segment summary blocks
Syzbot still reports uninit-value in nilfs_add_checksums_on_logs() for KMSAN enabled kernels after applying commit 7397031 ("nilfs2: initialize "struct nilfs_binfo_dat"->bi_pad field"). This is because the unused bytes at the end of each block in segment summaries are not initialized. So this fixes the issue by padding the unused bytes with null bytes. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ryusuke Konishi <[email protected]> Tested-by: Ryusuke Konishi <[email protected]> Reported-by: [email protected] Link: https://syzkaller.appspot.com/bug?extid=048585f3f4227bb2b49b Cc: Alexander Potapenko <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 4d73ba5 commit ef83274

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

fs/nilfs2/segment.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,23 @@ static int nilfs_segctor_reset_segment_buffer(struct nilfs_sc_info *sci)
430430
return 0;
431431
}
432432

433+
/**
434+
* nilfs_segctor_zeropad_segsum - zero pad the rest of the segment summary area
435+
* @sci: segment constructor object
436+
*
437+
* nilfs_segctor_zeropad_segsum() zero-fills unallocated space at the end of
438+
* the current segment summary block.
439+
*/
440+
static void nilfs_segctor_zeropad_segsum(struct nilfs_sc_info *sci)
441+
{
442+
struct nilfs_segsum_pointer *ssp;
443+
444+
ssp = sci->sc_blk_cnt > 0 ? &sci->sc_binfo_ptr : &sci->sc_finfo_ptr;
445+
if (ssp->offset < ssp->bh->b_size)
446+
memset(ssp->bh->b_data + ssp->offset, 0,
447+
ssp->bh->b_size - ssp->offset);
448+
}
449+
433450
static int nilfs_segctor_feed_segment(struct nilfs_sc_info *sci)
434451
{
435452
sci->sc_nblk_this_inc += sci->sc_curseg->sb_sum.nblocks;
@@ -438,6 +455,7 @@ static int nilfs_segctor_feed_segment(struct nilfs_sc_info *sci)
438455
* The current segment is filled up
439456
* (internal code)
440457
*/
458+
nilfs_segctor_zeropad_segsum(sci);
441459
sci->sc_curseg = NILFS_NEXT_SEGBUF(sci->sc_curseg);
442460
return nilfs_segctor_reset_segment_buffer(sci);
443461
}
@@ -542,6 +560,7 @@ static int nilfs_segctor_add_file_block(struct nilfs_sc_info *sci,
542560
goto retry;
543561
}
544562
if (unlikely(required)) {
563+
nilfs_segctor_zeropad_segsum(sci);
545564
err = nilfs_segbuf_extend_segsum(segbuf);
546565
if (unlikely(err))
547566
goto failed;
@@ -1533,6 +1552,7 @@ static int nilfs_segctor_collect(struct nilfs_sc_info *sci,
15331552
nadd = min_t(int, nadd << 1, SC_MAX_SEGDELTA);
15341553
sci->sc_stage = prev_stage;
15351554
}
1555+
nilfs_segctor_zeropad_segsum(sci);
15361556
nilfs_segctor_truncate_segments(sci, sci->sc_curseg, nilfs->ns_sufile);
15371557
return 0;
15381558

0 commit comments

Comments
 (0)