* [PATCH v2] KVM: s390: selftest: memop: Fix undefined behavior
@ 2024-01-11 9:48 Nina Schoetterl-Glausch
2024-02-22 11:30 ` Janosch Frank
0 siblings, 1 reply; 2+ messages in thread
From: Nina Schoetterl-Glausch @ 2024-01-11 9:48 UTC (permalink / raw)
To: Janosch Frank, Claudio Imbrenda, Paolo Bonzini, Shuah Khan,
Christian Borntraeger
Cc: Nina Schoetterl-Glausch, David Hildenbrand, linux-kselftest,
linux-kernel, kvm
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.
Fixes: 0dd714bfd200 ("KVM: s390: selftest: memop: Add cmpxchg tests")
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
---
v1 -> v2:
use early return instead of modulus
tools/testing/selftests/kvm/s390x/memop.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/testing/selftests/kvm/s390x/memop.c b/tools/testing/selftests/kvm/s390x/memop.c
index bb3ca9a5d731..4ec8d0181e8d 100644
--- a/tools/testing/selftests/kvm/s390x/memop.c
+++ b/tools/testing/selftests/kvm/s390x/memop.c
@@ -489,6 +489,8 @@ static __uint128_t rotate(int size, __uint128_t val, int amount)
amount = (amount + bits) % bits;
val = cut_to_size(size, val);
+ if (!amount)
+ return val;
return (val << (bits - amount)) | (val >> amount);
}
base-commit: 305230142ae0637213bf6e04f6d9f10bbcb74af8
--
2.40.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] KVM: s390: selftest: memop: Fix undefined behavior
2024-01-11 9:48 [PATCH v2] KVM: s390: selftest: memop: Fix undefined behavior Nina Schoetterl-Glausch
@ 2024-02-22 11:30 ` Janosch Frank
0 siblings, 0 replies; 2+ messages in thread
From: Janosch Frank @ 2024-02-22 11:30 UTC (permalink / raw)
To: Nina Schoetterl-Glausch, Claudio Imbrenda, Paolo Bonzini,
Shuah Khan, Christian Borntraeger
Cc: David Hildenbrand, linux-kselftest, linux-kernel, kvm
On 1/11/24 10:48, Nina Schoetterl-Glausch 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.
>
> Fixes: 0dd714bfd200 ("KVM: s390: selftest: memop: Add cmpxchg tests")
> Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Acked-by: Janosch Frank <frankja@linux.ibm.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-22 11:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-11 9:48 [PATCH v2] KVM: s390: selftest: memop: Fix undefined behavior Nina Schoetterl-Glausch
2024-02-22 11:30 ` Janosch Frank
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®