From 1ba7a2f2b6a9b152828a06443955a7fb1d139930 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 30 Jan 2004 01:48:06 -0500 Subject: [PATCH] Fix a byte swap bugs, including one which caused e2fsck to incorrectly treat as valid symlinks created with SE Linux (Debian bug #228723) as well as failing the f_journal test case on big endian systems due to the backup journal blocks not being swapped. --- e2fsck/ChangeLog | 6 ++++++ e2fsck/pass2.c | 3 +++ lib/ext2fs/ChangeLog | 12 ++++++++++++ lib/ext2fs/ext2_fs.h | 4 ++-- lib/ext2fs/swapfs.c | 11 ++++++++--- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index 754a688f..6adb24c1 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,3 +1,9 @@ +2004-01-30 Theodore Ts'o + + * pass2.c (deallocate_inode_block): Check to make sure the block + number is invalid before deallocating it, to avoid core + dumping e2fsck. + 2003-12-12 Theodore Ts'o * pass3.c (check_directory): When reconnecting a directory, we may diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c index c3858ab9..774294c0 100644 --- a/e2fsck/pass2.c +++ b/e2fsck/pass2.c @@ -1083,6 +1083,9 @@ static int deallocate_inode_block(ext2_filsys fs, if (HOLE_BLKADDR(*block_nr)) return 0; + if ((*block_nr < fs->super->s_first_data_block) || + (*block_nr >= fs->super->s_blocks_count)) + return 0; ext2fs_unmark_block_bitmap(ctx->block_found_map, *block_nr); ext2fs_block_alloc_stats(fs, *block_nr, -1); return 0; diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 586abc11..61a62f4f 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,15 @@ +2004-01-30 Theodore Ts'o + + * ext2_fs.h: Reserve an extra 4 bytes for the journal backup, + which we're using due to a typo in the e2fsck code. (Oops) + + * swapfs.c (ext2fs_swap_inode): Fix byte swap bug which causes SE + Linux created symlinks with mandatory attributes to fail + to be properly handled on big endian systems. (Addresses + Debian Bug #228723). + (ext2fs_swap_super): Byte swap some new fields in the + superblock, including the journal backup fields. + 2003-12-02 Theodore Ts'o * alloc.c, bb_inode.c, bitops.c, block.c, check_desc.c, closefs.c, diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h index f9f96b55..0313c3e6 100644 --- a/lib/ext2fs/ext2_fs.h +++ b/lib/ext2fs/ext2_fs.h @@ -446,8 +446,8 @@ struct ext2_super_block { __u32 s_default_mount_opts; __u32 s_first_meta_bg; /* First metablock group */ __u32 s_mkfs_time; /* When the filesystem was created */ - __u32 s_jnl_blocks[16]; /* Backup of the journal inode */ - __u32 s_reserved[173]; /* Padding to the end of the block */ + __u32 s_jnl_blocks[17]; /* Backup of the journal inode */ + __u32 s_reserved[172]; /* Padding to the end of the block */ }; /* diff --git a/lib/ext2fs/swapfs.c b/lib/ext2fs/swapfs.c index e375c63d..41e6fc3c 100644 --- a/lib/ext2fs/swapfs.c +++ b/lib/ext2fs/swapfs.c @@ -57,9 +57,14 @@ void ext2fs_swap_super(struct ext2_super_block * sb) sb->s_journal_inum = ext2fs_swab32(sb->s_journal_inum); sb->s_journal_dev = ext2fs_swab32(sb->s_journal_dev); sb->s_last_orphan = ext2fs_swab32(sb->s_last_orphan); + sb->s_default_mount_opts = ext2fs_swab32(sb->s_default_mount_opts); sb->s_first_meta_bg = ext2fs_swab32(sb->s_first_meta_bg); + sb->s_mkfs_time = ext2fs_swab32(sb->s_mkfs_time); for (i=0; i < 4; i++) sb->s_hash_seed[i] = ext2fs_swab32(sb->s_hash_seed[i]); + for (i=0; i < 17; i++) + sb->s_jnl_blocks[i] = ext2fs_swab32(sb->s_jnl_blocks[i]); + } void ext2fs_swap_group_desc(struct ext2_group_desc *gdp) @@ -93,7 +98,9 @@ void ext2fs_swap_inode(ext2_filsys fs, struct ext2_inode *t, t->i_links_count = ext2fs_swab16(f->i_links_count); t->i_blocks = ext2fs_swab32(f->i_blocks); t->i_flags = ext2fs_swab32(f->i_flags); - if (!islnk || f->i_blocks) { + t->i_file_acl = ext2fs_swab32(f->i_file_acl); + t->i_dir_acl = ext2fs_swab32(f->i_dir_acl); + if (!islnk || ext2fs_inode_data_blocks(fs, t)) { for (i = 0; i < EXT2_N_BLOCKS; i++) t->i_block[i] = ext2fs_swab32(f->i_block[i]); } else if (t != f) { @@ -101,8 +108,6 @@ void ext2fs_swap_inode(ext2_filsys fs, struct ext2_inode *t, t->i_block[i] = f->i_block[i]; } t->i_generation = ext2fs_swab32(f->i_generation); - t->i_file_acl = ext2fs_swab32(f->i_file_acl); - t->i_dir_acl = ext2fs_swab32(f->i_dir_acl); t->i_faddr = ext2fs_swab32(f->i_faddr); switch (fs->super->s_creator_os) { -- 2.11.0