linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: tytso@mit.edu, darrick.wong@oracle.com
Cc: linux-ext4@vger.kernel.org
Subject: [PATCH 05/21] misc: fix various endianness problems with inline_data
Date: Mon, 04 Aug 2014 18:05:30 -0700	[thread overview]
Message-ID: <20140805010530.2611.80567.stgit@birch.djwong.org> (raw)
In-Reply-To: <20140805010457.2611.89813.stgit@birch.djwong.org>

The inline data code fails to perform endianness conversions correctly
or at all in a number of places, so fix this so that big-endian
machines function properly.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 e2fsck/pass2.c           |   25 +++++++++++++++++++++++--
 lib/ext2fs/inline_data.c |    5 ++++-
 lib/ext2fs/newdir.c      |    9 +++++++++
 3 files changed, 36 insertions(+), 3 deletions(-)


diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c
index e968831..38bf37a 100644
--- a/e2fsck/pass2.c
+++ b/e2fsck/pass2.c
@@ -870,11 +870,21 @@ static int check_dir_block(ext2_filsys fs,
 #endif
 
 	ehandler_operation(_("reading directory block"));
-	if (inline_data_size)
+	if (inline_data_size) {
 		cd->pctx.errcode = ext2fs_inline_data_get(fs, ino, 0, buf, 0);
-	else
+		if (cd->pctx.errcode)
+			goto inline_read_fail;
+#ifdef WORDS_BIGENDIAN
+		*((__u32 *)buf) = ext2fs_le32_to_cpu(*((__u32 *)buf));
+		cd->pctx.errcode = ext2fs_dirent_swab_in2(fs,
+				buf + EXT4_INLINE_DATA_DOTDOT_SIZE,
+				inline_data_size - EXT4_INLINE_DATA_DOTDOT_SIZE,
+				0);
+#endif
+	} else
 		cd->pctx.errcode = ext2fs_read_dir_block4(fs, block_nr,
 							  buf, 0, ino);
+inline_read_fail:
 	ehandler_operation(0);
 	if (cd->pctx.errcode == EXT2_ET_DIR_CORRUPTED)
 		cd->pctx.errcode = 0; /* We'll handle this ourselves */
@@ -1311,6 +1321,17 @@ write_and_fix:
 			ctx->fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
 		}
 		if (inline_data_size) {
+#ifdef WORDS_BIGENDIAN
+			*((__u32 *)buf) = ext2fs_le32_to_cpu(*((__u32 *)buf));
+			cd->pctx.errcode = ext2fs_dirent_swab_out2(fs,
+					buf + EXT4_INLINE_DATA_DOTDOT_SIZE,
+					inline_data_size -
+					EXT4_INLINE_DATA_DOTDOT_SIZE,
+					0);
+			if (cd->pctx.errcode &&
+			    !fix_problem(ctx, PR_2_WRITE_DIRBLOCK, &cd->pctx))
+				goto abort_free_dict;
+#endif
 			cd->pctx.errcode =
 				ext2fs_inline_data_set(fs, ino, 0, buf,
 						       inline_data_size);
diff --git a/lib/ext2fs/inline_data.c b/lib/ext2fs/inline_data.c
index 19248a0..c188d75 100644
--- a/lib/ext2fs/inline_data.c
+++ b/lib/ext2fs/inline_data.c
@@ -361,13 +361,16 @@ ext2fs_inline_data_dir_expand(ext2_filsys fs, ext2_ino_t ino,
 		return retval;
 
 #ifdef WORDS_BIGENDIAN
-	retval = ext2fs_dirent_swab_in2(fs, buf, size, 0);
+	retval = ext2fs_dirent_swab_in2(fs, buf + EXT4_INLINE_DATA_DOTDOT_SIZE,
+					size, 0);
 	if (retval)
 		goto errout;
 #endif
 
 	/* Adjust the rec_len */
 	retval = ext2fs_inline_data_convert_dir(fs, ino, blk_buf, buf, size);
+	if (retval)
+		goto errout;
 	/* Allocate a new block */
 	retval = ext2fs_new_block2(fs, 0, 0, &blk);
 	if (retval)
diff --git a/lib/ext2fs/newdir.c b/lib/ext2fs/newdir.c
index cd32d0a..506d609 100644
--- a/lib/ext2fs/newdir.c
+++ b/lib/ext2fs/newdir.c
@@ -115,6 +115,15 @@ errcode_t ext2fs_new_dir_inline_data(ext2_filsys fs, ext2_ino_t dir_ino,
 	dir->inode = 0;
 	rec_len = EXT4_MIN_INLINE_DATA_SIZE - EXT4_INLINE_DATA_DOTDOT_SIZE;
 	retval = ext2fs_set_rec_len(fs, rec_len, dir);
+	if (retval)
+		goto errout;
+
+#ifdef WORDS_BIGENDIAN
+	retval = ext2fs_dirent_swab_out2(fs, (char *)dir, rec_len, 0);
+	if (retval)
+		goto errout;
+#endif
 
+errout:
 	return retval;
 }


  parent reply	other threads:[~2014-08-05  1:05 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-05  1:04 [PATCH 00/21] e2fsprogs Summer 2014 patchbomb, part 3 Darrick J. Wong
2014-08-05  1:05 ` [PATCH 01/21] e2fuzz: fix build problems on macosx and i386 linux Darrick J. Wong
2014-08-10 22:16   ` Theodore Ts'o
2014-08-05  1:05 ` [PATCH 02/21] e2fsck: convert 'delete files' warning to a proper fix_problem error Darrick J. Wong
2014-08-10 22:16   ` Theodore Ts'o
2014-08-05  1:05 ` [PATCH 03/21] libext2fs: check EA value offset Darrick J. Wong
2014-08-10 22:21   ` Theodore Ts'o
2014-08-05  1:05 ` [PATCH 04/21] libext2fs/e2fsck: don't run off the end of the EA block Darrick J. Wong
2014-08-10 22:22   ` Theodore Ts'o
2014-08-05  1:05 ` Darrick J. Wong [this message]
2014-08-10 22:23   ` [PATCH 05/21] misc: fix various endianness problems with inline_data Theodore Ts'o
2014-08-05  1:05 ` [PATCH 06/21] libext2fs: strict inline data overwrite should not return ENOSPC Darrick J. Wong
2014-08-10 22:27   ` Theodore Ts'o
2014-08-05  1:05 ` [PATCH 07/21] libext2fs: remove EA when inline data is less than 60 bytes Darrick J. Wong
2014-08-08 22:46   ` [PATCH v2 07/21] libext2fs: don't fail inline data operations if there's no EA Darrick J. Wong
2014-08-10 22:31     ` Theodore Ts'o
2014-08-05  1:05 ` [PATCH 08/21] libext2fs: fix memory leak when failing to iterate inline_data directory Darrick J. Wong
2014-08-10 22:32   ` Theodore Ts'o
2014-08-05  1:05 ` [PATCH 09/21] e2fsck: check ea-in-inode regions for overlap Darrick J. Wong
2014-08-08 22:43   ` [PATCH v2 " Darrick J. Wong
2014-08-10 22:35     ` Theodore Ts'o
2014-08-05  1:06 ` [PATCH 10/21] e2fsck: clear inline_data inode flag if EA missing Darrick J. Wong
2014-08-08 22:44   ` [PATCH v2 " Darrick J. Wong
2014-08-10 22:37     ` Theodore Ts'o
2014-08-05  1:06 ` [PATCH 11/21] e2fsck: handle inline data symlinks Darrick J. Wong
2014-08-10 22:38   ` Theodore Ts'o
2014-08-05  1:06 ` [PATCH 12/21] e2fsck: check inline directory data "block" first Darrick J. Wong
2014-08-10 22:40   ` Theodore Ts'o
2014-08-05  1:06 ` [PATCH 13/21] e2fsck: don't try to iterate blocks of an inline_data inode when deallocating it Darrick J. Wong
2014-08-10 22:40   ` Theodore Ts'o
2014-08-05  1:06 ` [PATCH 14/21] e2fsck: clear extents and inline_data flags from fifo/socket/device inodes Darrick J. Wong
2014-08-10 22:41   ` Theodore Ts'o
2014-08-05  1:06 ` [PATCH 15/21] e2fsck: fix conflicting extents|inlinedata inode flags Darrick J. Wong
2014-08-08 16:24   ` [PATCH v2 " Darrick J. Wong
2014-08-10 22:43     ` Theodore Ts'o
2014-08-05  1:06 ` [PATCH 16/21] e2fsck: do a better job of fixing i_size of inline directories Darrick J. Wong
2014-08-10 22:44   ` Theodore Ts'o
2014-08-05  1:06 ` [PATCH 17/21] e2fsck: use the correct block size when salvaging directories Darrick J. Wong
2014-08-10 22:45   ` Theodore Ts'o
2014-08-05  1:06 ` [PATCH 18/21] e2fsck: check inline dir size is a multiple of 4 Darrick J. Wong
2014-08-10 22:47   ` Theodore Ts'o
2014-08-05  1:07 ` [PATCH 19/21] e2fsck: be more careful in assuming inline_data inodes are directories Darrick J. Wong
2014-08-08 16:22   ` [PATCH v2 " Darrick J. Wong
2014-08-10 22:49     ` Theodore Ts'o
2014-08-05  1:07 ` [PATCH 20/21] e2fsck: don't set prev after processing '..' on an inline dir Darrick J. Wong
2014-08-10 22:50   ` Theodore Ts'o
2014-08-05  1:07 ` [PATCH 21/21] tests: add regression tests for inlinedata fixes Darrick J. Wong
2014-08-08 22:47   ` [PATCH v2 " Darrick J. Wong

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=20140805010530.2611.80567.stgit@birch.djwong.org \
    --to=darrick.wong@oracle.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;
as well as URLs for NNTP newsgroup(s).