Re: [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get

From: shenghui
Date: Wed Jul 21 2010 - 20:03:27 EST


2010/7/22 Jan Kara <jack@xxxxxxx>:
>> Hi,
>> Â Â Â ÂI walked through ext2_xattr_get, and felt that we can
>> do some optimization on it. For name_len check, it's done
>> after down xattr_sem and sb_read, both of which are time
>> consuming operation compared with strlen:
>> Â Â Â Â Âdown_read(&EXT2_I(inode)->xattr_sem);
>> Â...
>> Â Â Â Â Âbh = sb_bread(inode->i_sb, EXT2_I(inode)->i_file_acl);
>> Â...
>> Â Â Â Â Â/* find named attribute */
>> Â Â Â Â Âname_len = strlen(name);
>>
>> Â Â Â Â Âerror = -ERANGE;
>> Â Â Â Â Âif (name_len > 255)
>> Â Â Â Â Â Â Â Â Âgoto cleanup;
>>
>> Â Â Â ÂMost of the case, you'll get one valid block, but if the
>> name len > 255, then the xattr_sem down and sb_bread operation
>> can be seen as a waste of time. So I think we'd better do
>> name len check as early as possible.
>> Â Â Â ÂFollowing is my patch, and it's against 2.6.35-rc4.
>> Please check it.
>>
>> Signed-off-by: Wang Sheng-Hui <crosslonelyover@xxxxxxxxx>
>> ---
>> Âfs/ext2/xattr.c | Â 12 +++++++-----
>> Â1 files changed, 7 insertions(+), 5 deletions(-)
>>
>> diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
>> index 7c39157..0b94d61 100644
>> --- a/fs/ext2/xattr.c
>> +++ b/fs/ext2/xattr.c
>> @@ -161,6 +161,13 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
>>
>> Â Â Â if (name == NULL)
>> Â Â Â Â Â Â Â return -EINVAL;
>> +
>> + Â Â /* find named attribute */
>> + Â Â name_len = strlen(name);
>> + Â Â error = -ERANGE;
>> + Â Â if (name_len > 255)
>> + Â Â Â Â Â Â goto cleanup;
> ÂBut you cannot go to cleanup here because you don't hold xattr_sem...
>

Sorry, I'm a little confused by your words.
The patch just checks name_len, and it
doesn't need xattr_sem.



--


Thanks and Best Regards,
shenghui
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/