Skip to content

Commit 9c9c68d

Browse files
konisgregkh
authored andcommitted
nilfs2: fix data corruption in dsync block recovery for small block sizes
commit 67b8bcb upstream. The helper function nilfs_recovery_copy_block() of nilfs_recovery_dsync_blocks(), which recovers data from logs created by data sync writes during a mount after an unclean shutdown, incorrectly calculates the on-page offset when copying repair data to the file's page cache. In environments where the block size is smaller than the page size, this flaw can cause data corruption and leak uninitialized memory bytes during the recovery process. Fix these issues by correcting this byte offset calculation on the page. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ryusuke Konishi <[email protected]> Tested-by: Ryusuke Konishi <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 35076e3 commit 9c9c68d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fs/nilfs2/recovery.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,17 +472,18 @@ static int nilfs_prepare_segment_for_recovery(struct the_nilfs *nilfs,
472472

473473
static int nilfs_recovery_copy_block(struct the_nilfs *nilfs,
474474
struct nilfs_recovery_block *rb,
475-
struct page *page)
475+
loff_t pos, struct page *page)
476476
{
477477
struct buffer_head *bh_org;
478+
size_t from = pos & ~PAGE_MASK;
478479
void *kaddr;
479480

480481
bh_org = __bread(nilfs->ns_bdev, rb->blocknr, nilfs->ns_blocksize);
481482
if (unlikely(!bh_org))
482483
return -EIO;
483484

484485
kaddr = kmap_atomic(page);
485-
memcpy(kaddr + bh_offset(bh_org), bh_org->b_data, bh_org->b_size);
486+
memcpy(kaddr + from, bh_org->b_data, bh_org->b_size);
486487
kunmap_atomic(kaddr);
487488
brelse(bh_org);
488489
return 0;
@@ -521,7 +522,7 @@ static int nilfs_recover_dsync_blocks(struct the_nilfs *nilfs,
521522
goto failed_inode;
522523
}
523524

524-
err = nilfs_recovery_copy_block(nilfs, rb, page);
525+
err = nilfs_recovery_copy_block(nilfs, rb, pos, page);
525526
if (unlikely(err))
526527
goto failed_page;
527528

0 commit comments

Comments
 (0)