linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org
Subject: [PATCH 32/31] libext2fs: initialize i_extra_isize when writing EAs
Date: Mon, 22 Dec 2014 10:53:51 -0800	[thread overview]
Message-ID: <20141222185351.GG5368@birch.djwong.org> (raw)
In-Reply-To: <20141220211640.25563.80596.stgit@birch.djwong.org>

If i_extra_isize is zero when we try to write extended attributes,
we'll end up writing the EA magic into the i_extra_isize field, which
causes a subsequent crash on big endian systems (when we try to write
0xEA02 bytes past the inode!).  Therefore when the field is zero, set
i_extra_isize to the desired extra_isize size, zero those bytes, and
write the EAs after the end of the extended inode.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 lib/ext2fs/ext_attr.c                    |   11 +++++++++++
 tests/f_write_ea_no_extra_isize/expect.1 |   12 ++++++++++++
 tests/f_write_ea_no_extra_isize/expect.2 |    7 +++++++
 tests/f_write_ea_no_extra_isize/image.gz |  Bin
 tests/f_write_ea_no_extra_isize/name     |    1 +
 5 files changed, 31 insertions(+)
 create mode 100644 tests/f_write_ea_no_extra_isize/expect.1
 create mode 100644 tests/f_write_ea_no_extra_isize/expect.2
 create mode 100644 tests/f_write_ea_no_extra_isize/image.gz
 create mode 100644 tests/f_write_ea_no_extra_isize/name

diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c
index 70bc3f9..551c1f2 100644
--- a/lib/ext2fs/ext_attr.c
+++ b/lib/ext2fs/ext_attr.c
@@ -519,6 +519,17 @@ errcode_t ext2fs_xattrs_write(struct ext2_xattr_handle *handle)
 	if (err)
 		goto out;
 
+	/* If extra_isize isn't set, we need to set it now */
+	if (inode->i_extra_isize == 0) {
+		char *p = (char *)inode;
+		size_t extra = handle->fs->super->s_want_extra_isize;
+
+		if (extra == 0)
+			extra = sizeof(inode->i_extra_isize);
+		memset(p + EXT2_GOOD_OLD_INODE_SIZE, 0, extra);
+		inode->i_extra_isize = extra;
+	}
+
 	move_inline_data_to_front(handle);
 
 	x = handle->attrs;
diff --git a/tests/f_write_ea_no_extra_isize/expect.1 b/tests/f_write_ea_no_extra_isize/expect.1
new file mode 100644
index 0000000..b7e7438
--- /dev/null
+++ b/tests/f_write_ea_no_extra_isize/expect.1
@@ -0,0 +1,12 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Directory inode 12, block #0, offset 4: directory corrupted
+Salvage? yes
+
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 12/128 files (0.0% non-contiguous), 17/512 blocks
+Exit status is 1
diff --git a/tests/f_write_ea_no_extra_isize/expect.2 b/tests/f_write_ea_no_extra_isize/expect.2
new file mode 100644
index 0000000..3b6073e
--- /dev/null
+++ b/tests/f_write_ea_no_extra_isize/expect.2
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 12/128 files (0.0% non-contiguous), 17/512 blocks
+Exit status is 0
diff --git a/tests/f_write_ea_no_extra_isize/image.gz b/tests/f_write_ea_no_extra_isize/image.gz
new file mode 100644
index 0000000000000000000000000000000000000000..928daff1f344824d357e816883a98b2cdfdaffb3
GIT binary patch
literal 2516
zcmb2|=3qFkI6Z`k`Ry&+Y!OEZh6m-}^`s^_@O3Vjpj4;eVQ?ceQSj)oL#Gnz1=cLm
zv~lFfFtI=2=98SCs6XwXQ}-6Ju%@X>9fI9126HxlZ#2Be**0UwlghsG_L*~cr<Q$x
zcJJ<Oj)e8Ibj2!<JPfHhr<Aq!+aA$gzRhQoDpTqfm88@ubyxlMdNpU)@t~~i`mk$S
zzoVyaURhCSpQJX`e|`A<yOq_6FK*5jUa#jL8+)&B<F~W5)<2(II(+ff@7nX~@@wXt
zO0r@5^laDG$2W8iznog0p}+h^;VVXl4ZK}{zBqI(?)|f0Y^ht>t&nbG@wbW$3=B7Z
zzWX-qadqb7_v@K~-2ZzY{r}&1;?u?qJ8lDkN;|V_HErb@zdo&eIeY8H?91Epe8gTW
z#qp>8%-!w_RG#4e@_o_Y_#Xxt|AD*%>jF1&gXpjJK#~;jC;IEb(o&#~gzJUuETrf}
zRok%tV=6ElWvesq%s;o>RW(Vqw|cASS<|O4a;NN_xHR?tb)Bt$LbgmbOZ<IUQ%o$p
zUwq@2A5YK3-Tr^z+swV;J`Rs%pZ#BB`ad`3|E{WQssEz?TR&NG;97*nr}>xXe%f!t
zxAoKf7Zd(Zk&?Xh?1}x|{r`U+Uwh*Jxur#4xBt=4FJGCGo%NMBXYuokNl*KaC%k*G
zu}tK){;6+2PXDfdYaO{ZbnaGE_m1*LLtr!nMnhmU1V%$(Gz6#@0(bv1g#8Yk!N8!v
F003fX5hwrv

literal 0
HcmV?d00001

diff --git a/tests/f_write_ea_no_extra_isize/name b/tests/f_write_ea_no_extra_isize/name
new file mode 100644
index 0000000..200e365
--- /dev/null
+++ b/tests/f_write_ea_no_extra_isize/name
@@ -0,0 +1 @@
+write EA when i_extra_size is zero

  parent reply	other threads:[~2014-12-22 18:53 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-20 21:16 [PATCH 00/31] e2fsprogs December 2014 patchbomb Darrick J. Wong
2014-12-20 21:16 ` [PATCH 01/31] misc: fix clang warnings and a resource leak Darrick J. Wong
2015-01-19 21:39   ` Theodore Ts'o
2014-12-20 21:16 ` [PATCH 02/31] debugfs: document new commands Darrick J. Wong
2014-12-20 21:17 ` [PATCH 03/31] libext2fs: zero blocks via FALLOC_FL_ZERO_RANGE in ext2fs_zero_blocks Darrick J. Wong
2014-12-20 21:17 ` [PATCH 04/31] libext2fs: ext2fs_new_block2() should call alloc_block hook Darrick J. Wong
2014-12-20 21:17 ` [PATCH 05/31] tune2fs: disable csum verification before resizing inode Darrick J. Wong
2014-12-20 21:17 ` [PATCH 06/31] e2fsck: clear i_block[] when there are too many bad mappings on a special inode Darrick J. Wong
2014-12-20 21:17 ` [PATCH 07/31] libext2fs/e2fsck: provide routines to read-ahead metadata Darrick J. Wong
2014-12-20 21:17 ` [PATCH 08/31] e2fsck: read-ahead metadata during passes 1, 2, and 4 Darrick J. Wong
2014-12-20 21:17 ` [PATCH 09/31] e2fsck: track directories to be rehashed with a bitmap Darrick J. Wong
2014-12-20 21:17 ` [PATCH 10/31] e2fsck: rebuild sparse extent trees/convert non-extent ext3 files Darrick J. Wong
2014-12-20 21:17 ` [PATCH 11/31] tests: verify proper rebuilding of sparse extent trees and block map file conversion Darrick J. Wong
2014-12-20 21:18 ` [PATCH 12/31] undo-io: add new calls to and speed up the undo io manager Darrick J. Wong
2014-12-20 21:18 ` [PATCH 13/31] undo-io: be more flexible about setting block size Darrick J. Wong
2014-12-20 21:18 ` [PATCH 14/31] undo-io: use a bitmap to track what we've already written Darrick J. Wong
2014-12-20 21:18 ` [PATCH 15/31] e2undo: fix memory leaks and tweak the error messages somewhat Darrick J. Wong
2014-12-20 21:18 ` [PATCH 16/31] e2undo: ditch tdb file, write everything to a flat file Darrick J. Wong
2015-01-08  1:36   ` Darrick J. Wong
2014-12-20 21:18 ` [PATCH 17/31] e2fsck: optionally create an undo file Darrick J. Wong
2014-12-20 21:18 ` [PATCH 18/31] resize2fs: optionally create " Darrick J. Wong
2014-12-20 21:18 ` [PATCH 19/31] tune2fs: " Darrick J. Wong
2014-12-20 21:19 ` [PATCH 20/31] mke2fs: " Darrick J. Wong
2014-12-20 21:19 ` [PATCH 21/31] debugfs: " Darrick J. Wong
2014-12-20 21:19 ` [PATCH 22/31] tests: test undo file creation in e2fsck/resize2fs/tune2fs/mke2fs Darrick J. Wong
2014-12-20 21:19 ` [PATCH 23/31] tests: test various features of the new e2undo format Darrick J. Wong
2014-12-20 21:19 ` [PATCH 24/31] libext2fs: support allocating uninit blocks in bmap2() Darrick J. Wong
2014-12-20 21:19 ` [PATCH 25/31] libext2fs: find/alloc a range of empty blocks Darrick J. Wong
2014-12-20 21:19 ` [PATCH 26/31] libext2fs: add new hooks to support large allocations Darrick J. Wong
2014-12-20 21:19 ` [PATCH 27/31] libext2fs: implement fallocate Darrick J. Wong
2014-12-20 21:19 ` [PATCH 28/31] libext2fs: use fallocate for creating journals and hugefiles Darrick J. Wong
2014-12-20 21:20 ` [PATCH 29/31] debugfs: implement fallocate Darrick J. Wong
2014-12-20 21:20 ` [PATCH 30/31] tests: test debugfs punch command Darrick J. Wong
2014-12-22 18:53 ` Darrick J. Wong [this message]
2014-12-22 22:22   ` [PATCH 32/31] libext2fs: initialize i_extra_isize when writing EAs Andreas Dilger
2014-12-22 22:32     ` Darrick J. Wong
2014-12-22 22:55   ` [PATCH v2 " Darrick J. Wong
2014-12-22 18:55 ` [PATCH 33/31] e2fsck: on read error, don't rewrite blocks past the end of the fs Darrick J. Wong
2014-12-22 18:55 ` [PATCH 34/31] e2fsck: fix the journal recreation message Darrick J. Wong
2014-12-22 18:57 ` [PATCH 35/31] libext2fs: avoid pointless EA block allocation Darrick J. Wong
2014-12-22 18:57 ` [PATCH 36/31] libext2fs: strengthen i_extra_isize checks when reading/writing xattrs Darrick J. Wong
2014-12-22 18:57 ` [PATCH 37/31] libext2fs: fix tdb.c mmap leak 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=20141222185351.GG5368@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).