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]
Date: Fri, 15 Dec 2023 18:02:06 +0100
From: Claudio Imbrenda <imbrenda@...ux.ibm.com>
To: Nina Schoetterl-Glausch <nsg@...ux.ibm.com>
Cc: Paolo Bonzini <pbonzini@...hat.com>, Shuah Khan <shuah@...nel.org>,
        Janosch Frank <frankja@...ux.ibm.com>,
        Christian Borntraeger
 <borntraeger@...ux.ibm.com>,
        kvm@...r.kernel.org, linux-kselftest@...r.kernel.org,
        David Hildenbrand <david@...hat.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] KVM: s390: selftest: memop: Fix undefined behavior

On Fri, 15 Dec 2023 17:11:25 +0100
Nina Schoetterl-Glausch <nsg@...ux.ibm.com> wrote:

> If an integer's type has x bits, shifting the integer left by x or more
> is undefined behavior.
> This can happen in the rotate function when attempting to do a rotation
> of the whole value by 0.

is 0 the only problematic value? because in that case... 

> 
> Fixes: 0dd714bfd200 ("KVM: s390: selftest: memop: Add cmpxchg tests")
> Signed-off-by: Nina Schoetterl-Glausch <nsg@...ux.ibm.com>
> ---
>  tools/testing/selftests/kvm/s390x/memop.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/s390x/memop.c b/tools/testing/selftests/kvm/s390x/memop.c
> index bb3ca9a5d731..2eba9575828e 100644
> --- a/tools/testing/selftests/kvm/s390x/memop.c
> +++ b/tools/testing/selftests/kvm/s390x/memop.c
> @@ -485,11 +485,13 @@ static bool popcount_eq(__uint128_t a, __uint128_t b)
>  
>  static __uint128_t rotate(int size, __uint128_t val, int amount)
>  {
> -	unsigned int bits = size * 8;
> +	unsigned int left, right, bits = size * 8;
>  

...why not just:

if (!amount)
	return val;

?

> -	amount = (amount + bits) % bits;
> +	right = (amount + bits) % bits;
> +	/* % 128 prevents left shift UB if size == 16 && right == 0 */
> +	left = (bits - right) % 128;
>  	val = cut_to_size(size, val);
> -	return (val << (bits - amount)) | (val >> amount);
> +	return (val << left) | (val >> right);
>  }
>  
>  const unsigned int max_block = 16;
> 
> base-commit: 305230142ae0637213bf6e04f6d9f10bbcb74af8


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ