All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get
@ 2010-07-12 14:29 ` crosslonelyover
  0 siblings, 0 replies; 20+ messages in thread
From: crosslonelyover @ 2010-07-12 14:29 UTC (permalink / raw)
  To: linux-ext4, linux-kernel, kernel-janitors

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@gmail.com>
---
 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;
+
 	down_read(&EXT2_I(inode)->xattr_sem);
 	error = -ENODATA;
 	if (!EXT2_I(inode)->i_file_acl)
@@ -181,12 +188,7 @@ bad_block:	ext2_error(inode->i_sb, "ext2_xattr_get",
 		error = -EIO;
 		goto cleanup;
 	}
-	/* find named attribute */
-	name_len = strlen(name);
 
-	error = -ERANGE;
-	if (name_len > 255)
-		goto cleanup;
 	entry = FIRST_ENTRY(bh);
 	while (!IS_LAST_ENTRY(entry)) {
 		struct ext2_xattr_entry *next =
-- 
1.7.1.1







^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get
@ 2010-07-12 14:29 ` crosslonelyover
  0 siblings, 0 replies; 20+ messages in thread
From: crosslonelyover @ 2010-07-12 14:29 UTC (permalink / raw)
  To: linux-ext4, linux-kernel, kernel-janitors

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@gmail.com>
---
 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;
+
 	down_read(&EXT2_I(inode)->xattr_sem);
 	error = -ENODATA;
 	if (!EXT2_I(inode)->i_file_acl)
@@ -181,12 +188,7 @@ bad_block:	ext2_error(inode->i_sb, "ext2_xattr_get",
 		error = -EIO;
 		goto cleanup;
 	}
-	/* find named attribute */
-	name_len = strlen(name);
 
-	error = -ERANGE;
-	if (name_len > 255)
-		goto cleanup;
 	entry = FIRST_ENTRY(bh);
 	while (!IS_LAST_ENTRY(entry)) {
 		struct ext2_xattr_entry *next -- 
1.7.1.1







^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get
  2010-07-12 14:29 ` crosslonelyover
  (?)
@ 2010-07-13 14:28   ` Wang Sheng-Hui
  -1 siblings, 0 replies; 20+ messages in thread
From: Wang Sheng-Hui @ 2010-07-13 14:28 UTC (permalink / raw)
  To: linux-ext4, linux-kernel, kernel-janitors, tytso, adilger, akpm

  于 2010-7-12 22:29, crosslonelyover 写道:
> 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@gmail.com>
> ---
>   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;
> +
>   	down_read(&EXT2_I(inode)->xattr_sem);
>   	error = -ENODATA;
>   	if (!EXT2_I(inode)->i_file_acl)
> @@ -181,12 +188,7 @@ bad_block:	ext2_error(inode->i_sb, "ext2_xattr_get",
>   		error = -EIO;
>   		goto cleanup;
>   	}
> -	/* find named attribute */
> -	name_len = strlen(name);
>
> -	error = -ERANGE;
> -	if (name_len>  255)
> -		goto cleanup;
>   	entry = FIRST_ENTRY(bh);
>   	while (!IS_LAST_ENTRY(entry)) {
>   		struct ext2_xattr_entry *next =
Hi, I noticed in ext2_xattr_set, name_len check is done
before
down_write(&EXT2_I(inode)->xattr_sem);
So I think ext2_xattr_get should do in the same way.

Please check this patch.

-- 
Thanks and Regards,
shenghui


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get
@ 2010-07-13 14:28   ` Wang Sheng-Hui
  0 siblings, 0 replies; 20+ messages in thread
From: Wang Sheng-Hui @ 2010-07-13 14:28 UTC (permalink / raw)
  To: linux-ext4, linux-kernel, kernel-janitors, tytso, adilger, akpm

  于 2010-7-12 22:29, crosslonelyover 写道:
> 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@gmail.com>
> ---
>   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;
> +
>   	down_read(&EXT2_I(inode)->xattr_sem);
>   	error = -ENODATA;
>   	if (!EXT2_I(inode)->i_file_acl)
> @@ -181,12 +188,7 @@ bad_block:	ext2_error(inode->i_sb, "ext2_xattr_get",
>   		error = -EIO;
>   		goto cleanup;
>   	}
> -	/* find named attribute */
> -	name_len = strlen(name);
>
> -	error = -ERANGE;
> -	if (name_len>  255)
> -		goto cleanup;
>   	entry = FIRST_ENTRY(bh);
>   	while (!IS_LAST_ENTRY(entry)) {
>   		struct ext2_xattr_entry *next =
Hi, I noticed in ext2_xattr_set, name_len check is done
before
down_write(&EXT2_I(inode)->xattr_sem);
So I think ext2_xattr_get should do in the same way.

Please check this patch.

-- 
Thanks and Regards,
shenghui

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read
@ 2010-07-13 14:28   ` Wang Sheng-Hui
  0 siblings, 0 replies; 20+ messages in thread
From: Wang Sheng-Hui @ 2010-07-13 14:28 UTC (permalink / raw)
  To: linux-ext4, linux-kernel, kernel-janitors, tytso, adilger, akpm

  于 2010-7-12 22:29, crosslonelyover 写道:
> 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@gmail.com>
> ---
>   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;
> +
>   	down_read(&EXT2_I(inode)->xattr_sem);
>   	error = -ENODATA;
>   	if (!EXT2_I(inode)->i_file_acl)
> @@ -181,12 +188,7 @@ bad_block:	ext2_error(inode->i_sb, "ext2_xattr_get",
>   		error = -EIO;
>   		goto cleanup;
>   	}
> -	/* find named attribute */
> -	name_len = strlen(name);
>
> -	error = -ERANGE;
> -	if (name_len>  255)
> -		goto cleanup;
>   	entry = FIRST_ENTRY(bh);
>   	while (!IS_LAST_ENTRY(entry)) {
>   		struct ext2_xattr_entry *next Hi, I noticed in ext2_xattr_set, name_len check is done
before
down_write(&EXT2_I(inode)->xattr_sem);
So I think ext2_xattr_get should do in the same way.

Please check this patch.

-- 
Thanks and Regards,
shenghui


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get
  2010-07-12 14:29 ` crosslonelyover
@ 2010-07-13 14:56   ` Dan Carpenter
  -1 siblings, 0 replies; 20+ messages in thread
From: Dan Carpenter @ 2010-07-13 14:56 UTC (permalink / raw)
  To: crosslonelyover; +Cc: linux-ext4, linux-kernel, kernel-janitors

On Mon, Jul 12, 2010 at 10:29:09PM +0800, crosslonelyover wrote:
> 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@gmail.com>
> ---
>  fs/ext2/xattr.c |   12 +++++++-----
>  1 files changed, 7 insertions(+), 5 deletions(-)

For what it's worth, this change looks OK to me.

Reviewed-by: Dan Carpenter <error27@gmail.com>

regards,
dan carpenter



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read
@ 2010-07-13 14:56   ` Dan Carpenter
  0 siblings, 0 replies; 20+ messages in thread
From: Dan Carpenter @ 2010-07-13 14:56 UTC (permalink / raw)
  To: crosslonelyover; +Cc: linux-ext4, linux-kernel, kernel-janitors

On Mon, Jul 12, 2010 at 10:29:09PM +0800, crosslonelyover wrote:
> 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@gmail.com>
> ---
>  fs/ext2/xattr.c |   12 +++++++-----
>  1 files changed, 7 insertions(+), 5 deletions(-)

For what it's worth, this change looks OK to me.

Reviewed-by: Dan Carpenter <error27@gmail.com>

regards,
dan carpenter



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get
  2010-07-12 14:29 ` crosslonelyover
@ 2010-07-21 17:44   ` Jan Kara
  -1 siblings, 0 replies; 20+ messages in thread
From: Jan Kara @ 2010-07-21 17:44 UTC (permalink / raw)
  To: crosslonelyover; +Cc: linux-ext4, linux-kernel, kernel-janitors

> 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@gmail.com>
> ---
>  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...

									Honza
> +
>  	down_read(&EXT2_I(inode)->xattr_sem);
>  	error = -ENODATA;
>  	if (!EXT2_I(inode)->i_file_acl)
-- 
Jan Kara <jack@suse.cz>
SuSE CR Labs

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read
@ 2010-07-21 17:44   ` Jan Kara
  0 siblings, 0 replies; 20+ messages in thread
From: Jan Kara @ 2010-07-21 17:44 UTC (permalink / raw)
  To: crosslonelyover; +Cc: linux-ext4, linux-kernel, kernel-janitors

> 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@gmail.com>
> ---
>  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...

									Honza
> +
>  	down_read(&EXT2_I(inode)->xattr_sem);
>  	error = -ENODATA;
>  	if (!EXT2_I(inode)->i_file_acl)
-- 
Jan Kara <jack@suse.cz>
SuSE CR Labs

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read in  ext2_xattr_get
  2010-07-21 17:44   ` [PATCH] check name_len before down_read xattr_sem and sb_read Jan Kara
  (?)
@ 2010-07-22  0:03     ` shenghui
  -1 siblings, 0 replies; 20+ messages in thread
From: shenghui @ 2010-07-22  0:03 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4, linux-kernel, kernel-janitors

2010/7/22 Jan Kara <jack@suse.cz>:
>> 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@gmail.com>
>> ---
>>  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

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get
@ 2010-07-22  0:03     ` shenghui
  0 siblings, 0 replies; 20+ messages in thread
From: shenghui @ 2010-07-22  0:03 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4, linux-kernel, kernel-janitors

2010/7/22 Jan Kara <jack@suse.cz>:
>> 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@gmail.com>
>> ---
>>  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-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read in
@ 2010-07-22  0:03     ` shenghui
  0 siblings, 0 replies; 20+ messages in thread
From: shenghui @ 2010-07-22  0:03 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4, linux-kernel, kernel-janitors

2010/7/22 Jan Kara <jack@suse.cz>:
>> 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@gmail.com>
>> ---
>>  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

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get
  2010-07-22  0:03     ` [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get shenghui
  (?)
@ 2010-07-23  8:37       ` Jan Kara
  -1 siblings, 0 replies; 20+ messages in thread
From: Jan Kara @ 2010-07-23  8:37 UTC (permalink / raw)
  To: shenghui; +Cc: Jan Kara, linux-ext4, linux-kernel, kernel-janitors

On Thu 22-07-10 08:03:18, shenghui wrote:
> 2010/7/22 Jan Kara <jack@suse.cz>:
> >> 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@gmail.com>
> >> ---
> >>  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.
  Checking of name_len is fine as you did it. But I wanted to point out
that if name_len is greater than 255, you then go to 'cleanup' label which
tries to do up_read(&EXT2_I(inode)->xattr_sem). But that's a bug because
after you moved the code, we don't hold xattr_sem at the moment we check
name_len.

								Honza
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get
@ 2010-07-23  8:37       ` Jan Kara
  0 siblings, 0 replies; 20+ messages in thread
From: Jan Kara @ 2010-07-23  8:37 UTC (permalink / raw)
  To: shenghui; +Cc: Jan Kara, linux-ext4, linux-kernel, kernel-janitors

On Thu 22-07-10 08:03:18, shenghui wrote:
> 2010/7/22 Jan Kara <jack@suse.cz>:
> >> 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@gmail.com>
> >> ---
> >>  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.
  Checking of name_len is fine as you did it. But I wanted to point out
that if name_len is greater than 255, you then go to 'cleanup' label which
tries to do up_read(&EXT2_I(inode)->xattr_sem). But that's a bug because
after you moved the code, we don't hold xattr_sem at the moment we check
name_len.

								Honza
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read
@ 2010-07-23  8:37       ` Jan Kara
  0 siblings, 0 replies; 20+ messages in thread
From: Jan Kara @ 2010-07-23  8:37 UTC (permalink / raw)
  To: shenghui; +Cc: Jan Kara, linux-ext4, linux-kernel, kernel-janitors

On Thu 22-07-10 08:03:18, shenghui wrote:
> 2010/7/22 Jan Kara <jack@suse.cz>:
> >> 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@gmail.com>
> >> ---
> >>  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.
  Checking of name_len is fine as you did it. But I wanted to point out
that if name_len is greater than 255, you then go to 'cleanup' label which
tries to do up_read(&EXT2_I(inode)->xattr_sem). But that's a bug because
after you moved the code, we don't hold xattr_sem at the moment we check
name_len.

								Honza
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get
  2010-07-23  8:37       ` [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get Jan Kara
@ 2010-07-23 12:46         ` Ted Ts'o
  -1 siblings, 0 replies; 20+ messages in thread
From: Ted Ts'o @ 2010-07-23 12:46 UTC (permalink / raw)
  To: Jan Kara; +Cc: shenghui, linux-ext4, linux-kernel, kernel-janitors

On Fri, Jul 23, 2010 at 10:37:59AM +0200, Jan Kara wrote:
>   Checking of name_len is fine as you did it. But I wanted to point out
> that if name_len is greater than 255, you then go to 'cleanup' label which
> tries to do up_read(&EXT2_I(inode)->xattr_sem). But that's a bug because
> after you moved the code, we don't hold xattr_sem at the moment we check
> name_len.

Yup, you could just return -ERANGE right there.

The simpler fix though might be to just delete the check altogether.
Neither ext3 nor ext4 checks for the length of the xattr name in their
_xattr_get() function.  Instead they'll just do the search, and then
return -ENODATA.  That seems legit; there can be no entries larger
than 255, so saying the extended attribute doesn't exist is quite
correct.  There is a check in the _xattr_set() functions for both ext3
and ext4, which is quite correct and proper.

Does that mean we'll end up doing a search before returning an error
--- yes, but I don't think that matters.  Why should we care about
optimizing an error case?  It's not like this is going to be in a
timing sensitive part of an application....  (of course the same
consideration could apply to your patch as well).

	      	    	     	  	- Ted

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read
@ 2010-07-23 12:46         ` Ted Ts'o
  0 siblings, 0 replies; 20+ messages in thread
From: Ted Ts'o @ 2010-07-23 12:46 UTC (permalink / raw)
  To: Jan Kara; +Cc: shenghui, linux-ext4, linux-kernel, kernel-janitors

On Fri, Jul 23, 2010 at 10:37:59AM +0200, Jan Kara wrote:
>   Checking of name_len is fine as you did it. But I wanted to point out
> that if name_len is greater than 255, you then go to 'cleanup' label which
> tries to do up_read(&EXT2_I(inode)->xattr_sem). But that's a bug because
> after you moved the code, we don't hold xattr_sem at the moment we check
> name_len.

Yup, you could just return -ERANGE right there.

The simpler fix though might be to just delete the check altogether.
Neither ext3 nor ext4 checks for the length of the xattr name in their
_xattr_get() function.  Instead they'll just do the search, and then
return -ENODATA.  That seems legit; there can be no entries larger
than 255, so saying the extended attribute doesn't exist is quite
correct.  There is a check in the _xattr_set() functions for both ext3
and ext4, which is quite correct and proper.

Does that mean we'll end up doing a search before returning an error
--- yes, but I don't think that matters.  Why should we care about
optimizing an error case?  It's not like this is going to be in a
timing sensitive part of an application....  (of course the same
consideration could apply to your patch as well).

	      	    	     	  	- Ted

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read in  ext2_xattr_get
  2010-07-23 12:46         ` [PATCH] check name_len before down_read xattr_sem and sb_read Ted Ts'o
  (?)
@ 2010-07-25 13:12           ` shenghui
  -1 siblings, 0 replies; 20+ messages in thread
From: shenghui @ 2010-07-25 13:12 UTC (permalink / raw)
  To: Ted Ts'o, Jan Kara, shenghui, linux-ext4, linux-kernel,
	kernel-janitors

Thanks for your instructions and explanation!


-- 


Thanks and Best Regards,
shenghui

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get
@ 2010-07-25 13:12           ` shenghui
  0 siblings, 0 replies; 20+ messages in thread
From: shenghui @ 2010-07-25 13:12 UTC (permalink / raw)
  To: Ted Ts'o, Jan Kara, shenghui, linux-ext4, linux-kernel, kerne

Thanks for your instructions and explanation!


-- 


Thanks and Best Regards,
shenghui

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] check name_len before down_read xattr_sem and sb_read in
@ 2010-07-25 13:12           ` shenghui
  0 siblings, 0 replies; 20+ messages in thread
From: shenghui @ 2010-07-25 13:12 UTC (permalink / raw)
  To: Ted Ts'o, Jan Kara, shenghui, linux-ext4, linux-kernel

Thanks for your instructions and explanation!


-- 


Thanks and Best Regards,
shenghui

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2010-07-25 13:12 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-12 14:29 [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get crosslonelyover
2010-07-12 14:29 ` crosslonelyover
2010-07-13 14:28 ` Wang Sheng-Hui
2010-07-13 14:28   ` [PATCH] check name_len before down_read xattr_sem and sb_read Wang Sheng-Hui
2010-07-13 14:28   ` [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get Wang Sheng-Hui
2010-07-13 14:56 ` Dan Carpenter
2010-07-13 14:56   ` [PATCH] check name_len before down_read xattr_sem and sb_read Dan Carpenter
2010-07-21 17:44 ` [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get Jan Kara
2010-07-21 17:44   ` [PATCH] check name_len before down_read xattr_sem and sb_read Jan Kara
2010-07-22  0:03   ` [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get shenghui
2010-07-22  0:03     ` [PATCH] check name_len before down_read xattr_sem and sb_read in shenghui
2010-07-22  0:03     ` [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get shenghui
2010-07-23  8:37     ` Jan Kara
2010-07-23  8:37       ` [PATCH] check name_len before down_read xattr_sem and sb_read Jan Kara
2010-07-23  8:37       ` [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get Jan Kara
2010-07-23 12:46       ` Ted Ts'o
2010-07-23 12:46         ` [PATCH] check name_len before down_read xattr_sem and sb_read Ted Ts'o
2010-07-25 13:12         ` [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get shenghui
2010-07-25 13:12           ` [PATCH] check name_len before down_read xattr_sem and sb_read in shenghui
2010-07-25 13:12           ` [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get shenghui

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.