KVM: s390/diag: fix racy access of physical cpu number in diag 9c handler
authorChristian Borntraeger <borntraeger@linux.ibm.com>
Mon, 15 May 2023 08:42:34 +0000 (10:42 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Jul 2023 14:21:57 +0000 (16:21 +0200)
commit86bfb18bad60fc468e5f112cbbd918462a8dd435
treec4b576aec3c8a05b34e49e7ec99c6a4bb18f5590
parentc78ad1060ce98e1c09b7964c254850962806ebde
KVM: s390/diag: fix racy access of physical cpu number in diag 9c handler

[ Upstream commit 0bc380beb78aa352eadbc21d934dd9606fcee808 ]

We do check for target CPU == -1, but this might change at the time we
are going to use it. Hold the physical target CPU in a local variable to
avoid out-of-bound accesses to the cpu arrays.

Cc: Pierre Morel <pmorel@linux.ibm.com>
Fixes: 87e28a15c42c ("KVM: s390: diag9c (directed yield) forwarding")
Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Nico Boehr <nrb@linux.ibm.com>
Reviewed-by: Pierre Morel <pmorel@linux.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/s390/kvm/diag.c