lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 31 Jul 2012 19:48:10 +0800
From:	Zheng Liu <gnehzuil.liu@...il.com>
To:	linux-ext4@...r.kernel.org
Cc:	Zheng Liu <wenqing.lz@...bao.com>
Subject: [PATCH 17/36 v4] debugfs: make mkdir cmd support inline data

From: Zheng Liu <wenqing.lz@...bao.com>

We need to reload inode in ext2fs_mkdir because inode with inline itself
data is modified in ext2fs_link.

Now we cannot create an empty dir with inline data because we need to do
a lot of works for maniluating xattr, and it brings a huge impacts for
e2fsprogs.

Signed-off-by: Zheng Liu <wenqing.lz@...bao.com>
---
 lib/ext2fs/mkdir.c |   33 +++++++++++++++++++++++++++++----
 1 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/lib/ext2fs/mkdir.c b/lib/ext2fs/mkdir.c
index 4a85439..3c226f3 100644
--- a/lib/ext2fs/mkdir.c
+++ b/lib/ext2fs/mkdir.c
@@ -41,6 +41,7 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
 	ext2_ino_t		scratch_ino;
 	blk64_t			blk;
 	char			*block = 0;
+	int			unmark_blk = 0;
 
 	EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
 
@@ -115,6 +116,14 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
 	}
 
 	/*
+	 * XXX: We need to update accouting before we mkdir successful because
+	 * in ext2fs_link it could allocate a new block when there is no space
+	 * to store a new dir entry in inline data.  If ext2fs_link failed, we
+	 * need to unmark this block.
+	 */
+	ext2fs_block_alloc_stats2(fs, blk, +1);
+
+	/*
 	 * Link the directory into the filesystem hierarchy
 	 */
 	if (name) {
@@ -123,32 +132,48 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
 		if (!retval) {
 			retval = EXT2_ET_DIR_EXISTS;
 			name = 0;
+			unmark_blk = 1;
 			goto cleanup;
 		}
-		if (retval != EXT2_ET_FILE_NOT_FOUND)
+		if (retval != EXT2_ET_FILE_NOT_FOUND) {
+			unmark_blk = 1;
 			goto cleanup;
+		}
 		retval = ext2fs_link(fs, parent, name, ino, EXT2_FT_DIR);
-		if (retval)
+		if (retval) {
+			unmark_blk = 1;
 			goto cleanup;
+		}
 	}
 
 	/*
 	 * Update parent inode's counts
 	 */
 	if (parent != ino) {
+		/* Reload parent inode */
+		retval = ext2fs_read_inode(fs, parent, &parent_inode);
+		if (retval) {
+			unmark_blk = 1;
+			goto cleanup;
+		}
 		parent_inode.i_links_count++;
 		retval = ext2fs_write_inode(fs, parent, &parent_inode);
-		if (retval)
+		if (retval) {
+			unmark_blk = 1;
 			goto cleanup;
+		}
 	}
 
 	/*
 	 * Update accounting....
 	 */
-	ext2fs_block_alloc_stats2(fs, blk, +1);
 	ext2fs_inode_alloc_stats2(fs, ino, +1, 1);
 
 cleanup:
+	/* Unmark block because mkdir failed */
+	if (unmark_blk)
+		ext2fs_block_alloc_stats2(fs, blk, -1);
+
 	if (block)
 		ext2fs_free_mem(&block);
 	return retval;
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ