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: <20160629220611.GA13735@p183.telecom.by>
Date:	Thu, 30 Jun 2016 01:06:11 +0300
From:	Alexey Dobriyan <adobriyan@...il.com>
To:	zengzhaoxiu@....com
Cc:	linux-kernel@...r.kernel.org,
	Zhaoxiu Zeng <zhaoxiu.zeng@...il.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Kees Cook <keescook@...omium.org>
Subject: Re: [PATCH 2/2] lib: kstrtox: _parse_integer: use hex_to_bin instead
 local conversion, and reduce branches

On Thu, Jun 30, 2016 at 12:22:13AM +0800, zengzhaoxiu@....com wrote:
> --- a/lib/kstrtox.c
> +++ b/lib/kstrtox.c
> @@ -48,38 +48,26 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long
>  {
>  	unsigned long long res;
>  	unsigned int rv;
> -	int overflow;
> +	unsigned int overflow;
> +	unsigned int val;
>  
>  	res = 0;
>  	rv = 0;
>  	overflow = 0;
> -	while (*s) {
> -		unsigned int val;
> -
> -		if ('0' <= *s && *s <= '9')
> -			val = *s - '0';
> -		else if ('a' <= _tolower(*s) && _tolower(*s) <= 'f')
> -			val = _tolower(*s) - 'a' + 10;
> -		else
> -			break;
> -
> -		if (val >= base)
> -			break;
> +	while ((val = hex_to_bin(*s++)) < base) {

I hate this function. And it has a branch if your table patch doesn't
go it. And it is beartrap (unsigned int = -1 < base).

ACK *s++ bit, though. Should make code smaller in my experience.
Please, change to "unsigned char c; while ((c = *s++)".
This is about maximum code compression I can understand.

>  		/*
>  		 * Check for overflow only if we are within range of
>  		 * it in the max base we support (16)
>  		 */
>  		if (unlikely(res & (~0ull << 60))) {
>  			if (res > div_u64(ULLONG_MAX - val, base))
> -				overflow = 1;
> +				overflow = KSTRTOX_OVERFLOW;

Just do |= KSTRTOX_OVERFLOW here directly, it is the leftmost bit.

>  		}
>  		res = res * base + val;
>  		rv++;
> -		s++;
>  	}
>  	*p = res;
> -	if (overflow)
> -		rv |= KSTRTOX_OVERFLOW;
> +	rv |= overflow;
>  	return rv;
>  }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ