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]
Message-ID: <20190523144612.GA18841@quack2.suse.cz>
Date:   Thu, 23 May 2019 16:46:12 +0200
From:   Jan Kara <jack@...e.cz>
To:     Chengguang Xu <cgxu519@...o.com.cn>
Cc:     jack@...e.com, linux-ext4@...r.kernel.org
Subject: Re: [PATCH] ext2: optimize ext2_xattr_get()

On Tue 21-05-19 16:21:39, Chengguang Xu wrote:
> Since xattr entry names are sorted, we don't have
> to continue when current entry name is greater than
> target.
> 
> Signed-off-by: Chengguang Xu <cgxu519@...o.com.cn>

Thanks for the patch! If we are going to do these comparisons in multiple
places, then please create a helper function to do the comparison (so that
we have the same comparison in every place). Something like:

int ext2_xattr_cmp(int name_index, size_t name_len, const char *name,
		   struct ext2_xattr_entry *entry)

Thanks!

								Honza
> ---
>  fs/ext2/xattr.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
> index d21dbf297b74..f1f857b83b45 100644
> --- a/fs/ext2/xattr.c
> +++ b/fs/ext2/xattr.c
> @@ -178,7 +178,7 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
>  	struct ext2_xattr_entry *entry;
>  	size_t name_len, size;
>  	char *end;
> -	int error;
> +	int error, not_found;
>  	struct mb_cache *ea_block_cache = EA_BLOCK_CACHE(inode);
>  
>  	ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
> @@ -220,10 +220,18 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
>  			goto bad_block;
>  		if (!ext2_xattr_entry_valid(entry, inode->i_sb->s_blocksize))
>  			goto bad_block;
> -		if (name_index == entry->e_name_index &&
> -		    name_len == entry->e_name_len &&
> -		    memcmp(name, entry->e_name, name_len) == 0)
> +
> +		not_found = name_index - entry->e_name_index;
> +		if (!not_found)
> +			not_found = name_len - entry->e_name_len;
> +		if (!not_found)
> +			not_found = memcmp(name, entry->e_name,
> +						   name_len);
> +		if (!not_found)
>  			goto found;
> +		if (not_found < 0)
> +			break;
> +
>  		entry = next;
>  	}
>  	if (ext2_xattr_cache_insert(ea_block_cache, bh))
> -- 
> 2.20.1
> 
> 
> 
> 
-- 
Jan Kara <jack@...e.com>
SUSE Labs, CR

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ