public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Kalpak Shah <kalpak@clusterfs.com>
To: linux-ext4 <linux-ext4@vger.kernel.org>
Cc: TheodoreTso <tytso@mit.edu>, Andreas Dilger <adilger@clusterfs.com>
Subject: [PATCH] Endianness bugs in e2fsck
Date: Wed, 20 Jun 2007 15:03:08 +0530	[thread overview]
Message-ID: <1182331988.9772.7.camel@garfield> (raw)

In ext2fs_swap_inode_full() if to and from inodes are not the same (which is the case when called from e2fsck_get_next_inode_full), then e2fsck cannot recognize any in-inode EAs since the un-swabbed i_extra_isize was being used. So corrected that to use swabbed values all the time.

Also in ext2fs_read_inode_full(), ext2fs_swap_inode_full() should be called with bufsize instead of with length argument. length was coming out to be 128 even with 512 byte inodes thus leaving the rest of the inode unswabbed.

On big-endian machines, ext2fs_get_next_inode_full() calls this for copying the inode:
ext2fs_swap_inode_full(scan->fs,
		       (struct ext2_inode_large *) inode,
		       (struct ext2_inode_large *) scan->ptr,
			0, bufsize);
In ext2fs_swap_inode_full() only the first (GOOD_OLD_INODE_SIZE + i_extra_isize)bytes are copied into inode. The rest of the inode is not zeroed. So memset the inode to zero if swapfs is enabled. On little endian machines, memcpy(inode, scan->ptr, bufsize); is executed thereby hiding this error.

Signed-off-by: Kalpak Shah <kalpak@clusterfs.com>

Index: e2fsprogs-1.39/lib/ext2fs/swapfs.c
===================================================================
--- e2fsprogs-1.39.orig/lib/ext2fs/swapfs.c     2007-06-19 22:31:20.000000000 -0700
+++ e2fsprogs-1.39/lib/ext2fs/swapfs.c  2007-06-19 22:41:43.628732192 -0700
@@ -261,13 +261,13 @@ void ext2fs_swap_inode_full(ext2_filsys
                return; /* no space for EA magic */

        eaf = (__u32 *) (((char *) f) + sizeof(struct ext2_inode) +
-                                       f->i_extra_isize);
+                                       t->i_extra_isize);

        if (ext2fs_swab32(*eaf) != EXT2_EXT_ATTR_MAGIC)
                return; /* it seems no magic here */

        eat = (__u32 *) (((char *) t) + sizeof(struct ext2_inode) +
-                                       f->i_extra_isize);
+                                       t->i_extra_isize);
        *eat = ext2fs_swab32(*eaf);

        /* convert EA(s) */
Index: e2fsprogs-1.39/lib/ext2fs/inode.c
===================================================================
--- e2fsprogs-1.39.orig/lib/ext2fs/inode.c      2007-06-19 22:31:21.000000000 -0700
+++ e2fsprogs-1.39/lib/ext2fs/inode.c   2007-06-20 01:06:18.017788976 -0700
@@ -471,6 +471,7 @@ errcode_t ext2fs_get_next_inode_full(ext
                scan->bytes_left -= scan->inode_size - extra_bytes;

 #ifdef EXT2FS_ENABLE_SWAPFS
+               memset(inode, 0, bufsize);
                if ((scan->fs->flags & EXT2_FLAG_SWAP_BYTES) ||
                    (scan->fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
                        ext2fs_swap_inode_full(scan->fs,
@@ -485,6 +486,7 @@ errcode_t ext2fs_get_next_inode_full(ext
                scan->scan_flags &= ~EXT2_SF_BAD_EXTRA_BYTES;
        } else {
 #ifdef EXT2FS_ENABLE_SWAPFS
+               memset(inode, 0, bufsize);
                if ((scan->fs->flags & EXT2_FLAG_SWAP_BYTES) ||
                    (scan->fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
                        ext2fs_swap_inode_full(scan->fs,
@@ -603,7 +605,7 @@ errcode_t ext2fs_read_inode_full(ext2_fi
            (fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
                ext2fs_swap_inode_full(fs, (struct ext2_inode_large *) inode,
                                       (struct ext2_inode_large *) inode,
-                                      0, length);
+                                      0, bufsize);
 #endif

        /* Update the inode cache */

             reply	other threads:[~2007-06-20  9:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-20  9:33 Kalpak Shah [this message]
2007-06-20 15:09 ` [PATCH] Endianness bugs in e2fsck Theodore Tso
2007-06-20 19:36   ` Kalpak Shah
2007-06-22 22:20 ` Theodore Tso
2007-06-22 23:54   ` Theodore Tso
2007-06-23  2:34     ` Theodore Tso
2007-06-23  0:36 ` Theodore Tso
2007-06-25  8:13   ` Kalpak Shah
2007-07-17 21:19 ` Eric Sandeen
2007-07-18  1:40   ` Eric Sandeen
2007-07-18  7:04     ` Kalpak Shah

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1182331988.9772.7.camel@garfield \
    --to=kalpak@clusterfs.com \
    --cc=adilger@clusterfs.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox