Skip to contentSkip to conversation

Fix ea-in-inode default ACL creation

PATCH Andreas Gruenbacher 4 participants 8 messages Jan 20, 2005 – Jan 21, 2005

lore
Share & tools
lore
#0 lore raw

Hello,

here is another nastiness.

When a new inode is created, ext3_new_inode sets the EXT3_STATE_NEW flag, which tells ext3_do_update_inode to zero out the inode before filling in the inode's data. When a file is created in a directory with a default acl, the new inode inherits the directory's default acl; this generates attributes. The attributes are created before ext3_do_update_inode is called to write out the inode. In case of in-inode attributes, the new inode's attributes are written, and then zeroed out again by ext3_do_update_inode. Bad thing.

Fix this by recognizing the EXT3_STATE_NEW case in ext3_xattr_set_handle, and zeroing out the inode there already when necessary.

fs/ext3/xattr.c +7 -0
Index: linux-2.6.11-latest/fs/ext3/xattr.c
===================================================================
@@ -954,6 +954,13 @@ ext3_xattr_set_handle(handle_t *handle, 
 	error = ext3_get_inode_loc(inode, &is.iloc);
 	if (error)
 		goto cleanup;
+
+	if (EXT3_I(inode)->i_state & EXT3_STATE_NEW) {
+		struct ext3_inode *raw_inode = ext3_raw_inode(&is.iloc);
+		memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size);
+		EXT3_I(inode)->i_state &= ~EXT3_STATE_NEW;
+	}
+
 	error = ext3_xattr_ibody_find(inode, &i, &is);
 	if (error)
 		goto cleanup;
Signature · 2 lines
Andreas Gruenbacher <[email protected]>
SUSE Labs, SUSE LINUX GMBH
#1 lore raw
Quoted 23 lines · Andreas Gruenbacher

When a new inode is created, ext3_new_inode sets the EXT3_STATE_NEW flag, which tells ext3_do_update_inode to zero out the inode before filling in the inode's data. When a file is created in a directory with a default acl, the new inode inherits the directory's default acl; this generates attributes. The attributes are created before ext3_do_update_inode is called to write out the inode. In case of in-inode attributes, the new inode's attributes are written, and then zeroed out again by ext3_do_update_inode. Bad thing.

Fix this by recognizing the EXT3_STATE_NEW case in ext3_xattr_set_handle, and zeroing out the inode there already when necessary.

Index: linux-2.6.11-latest/fs/ext3/xattr.c
===================================================================

fs/ext3/xattr.c +0 -0
@@ -954,6 +954,13 @@ ext3_xattr_set_handle(handle_t *handle, 
 	error = ext3_get_inode_loc(inode, &is.iloc);
 	if (error)
 		goto cleanup;

fs/ext3/xattr.c ext3_xattr_set_handle(handle_t *handle, · line 966

Quoted 10 lines
fs/ext3/xattr.c +7 -0
+
+	if (EXT3_I(inode)->i_state & EXT3_STATE_NEW) {
+		struct ext3_inode *raw_inode = ext3_raw_inode(&is.iloc);
+		memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size);
+		EXT3_I(inode)->i_state &= ~EXT3_STATE_NEW;
+	}
+
 	error = ext3_xattr_ibody_find(inode, &i, &is);
 	if (error)
 		goto cleanup;

Maybe I'm a total idiot, but I'm failing to see how adding *another* zero operation (although quite likely needed at that point) is going to help the fact that we zero something out after we've stored data we want to keep in it. Is there a missing hunk that *removes* the too-late memset-to-zero in ext3_do_update_inode?

#2 lore raw
Quoted 16 lines · On Jan 20, 2005 13:56 -0500, [email protected] wrote:

fs/ext3/xattr.c ext3_xattr_set_handle(handle_t *handle, · line 958

Quoted 9 lines · Andreas Gruenbacher

===================================================================

fs/ext3/xattr.c +5 -0
@@ -954,6 +954,13 @@ ext3_xattr_set_handle(handle_t *handle, 
+	if (EXT3_I(inode)->i_state & EXT3_STATE_NEW) {
+		struct ext3_inode *raw_inode = ext3_raw_inode(&is.iloc);
+		memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size);
+		EXT3_I(inode)->i_state &= ~EXT3_STATE_NEW;
+	}

Maybe I'm a total idiot, but I'm failing to see how adding *another* zero operation (although quite likely needed at that point) is going to help the fact that we zero something out after we've stored data we want to keep in it. Is there a missing hunk that *removes* the too-late memset-to-zero in ext3_do_update_inode?

Yes, as you can see above the EXT3_STATE_NEW flag is cleared so the later check in ext3_new_inode() will not again zero the inode

Cheers, Andreas
--
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://members.shaw.ca/adilger/ http://members.shaw.ca/golinux/

#3 lore raw
In reply to [email protected]
Quoted 2 lines · On Thu, 2005-01-20 at 19:56, [email protected] wrote:

[...] I'm failing to see how adding *another* zero operation [...] is going to help the fact [...]

It's an ancient kernel hackers trick: ;)

fs/ext3/xattr.c ext3_xattr_set_handle(handle_t *handle, · line 961

Quoted 1 line
fs/ext3/xattr.c +1 -0
+		EXT3_I(inode)->i_state &= ~EXT3_STATE_NEW;

Regards,

Signature · 2 lines
Andreas Gruenbacher <[email protected]>
SUSE Labs, SUSE LINUX GMBH
#4 lore raw
Quoted 6 lines · Andreas Gruenbacher
Quoted 2 lines · On Thu, 2005-01-20 at 19:56, [email protected] wrote:

[...] I'm failing to see how adding *another* zero operation [...] is going to help the fact [...]

It's an ancient kernel hackers trick: ;)

fs/ext3/xattr.c ext3_xattr_set_handle(handle_t *handle, · line 961

Quoted 1 line
fs/ext3/xattr.c +1 -0
+		EXT3_I(inode)->i_state &= ~EXT3_STATE_NEW;

Damn. I saw every *other* line of the patch but that one. Literally.

(Make note to self - if a cold is making your eyes water and itch too much to wear your contacts, you probably can't see well enough to read code ;)

#5 lore raw
In reply to Andreas Gruenbacher

Hi,

Quoted 9 lines · Andreas Gruenbacher

When a new inode is created, ext3_new_inode sets the EXT3_STATE_NEW flag, which tells ext3_do_update_inode to zero out the inode before filling in the inode's data. When a file is created in a directory with a default acl, the new inode inherits the directory's default acl; this generates attributes. The attributes are created before ext3_do_update_inode is called to write out the inode. In case of in-inode attributes, the new inode's attributes are written, and then zeroed out again by ext3_do_update_inode. Bad thing.

Quoted 3 lines

Fix this by recognizing the EXT3_STATE_NEW case in ext3_xattr_set_handle, and zeroing out the inode there already when necessary.

Ugh. It feels horrible to have to do this, but we _do_ want to clear the raw inode, and we only want to do it once, and we have to do it on first access to the on-disk structures. I can't see an easy way round it that doesn't add more overhead.

Looks reasonable to me.

--Stephen

#6 lore raw
Quoted 4 lines · Stephen C. Tweedie

Ugh. It feels horrible to have to do this, but we _do_ want to clear the raw inode, and we only want to do it once, and we have to do it on first access to the on-disk structures. I can't see an easy way round it that doesn't add more overhead.

Well, we could split EXT3_STATE_NEW into a "GOOD_OLD_NEW" flag for the first 128 bytes and a "BIG_INODE_NEW" flag for the rest, and only initialize the rest in the xattr code when necessary. Not any better it I suppose. Note that this change has no effect except with default ACLs anyway.

-- Andreas.

#7 lore raw

Hi,

Quoted 4 lines · Andreas Gruenbacher

Well, we could split EXT3_STATE_NEW into a "GOOD_OLD_NEW" flag for the first 128 bytes and a "BIG_INODE_NEW" flag for the rest, and only initialize the rest in the xattr code when necessary. Not any better it I suppose.

Agreed. :-)

--Stephen