Skip to content

Commit 682dbf4

Browse files
Nina Schoetterl-Glauschfrankjaa
authored andcommitted
KVM: s390: vsie: Fix length of facility list shadowed
The length of the facility list accessed when interpretively executing STFLE is the same as the hosts facility list (in case of format-0) The memory following the facility list doesn't need to be accessible. The current VSIE implementation accesses a fixed length that exceeds the guest/host facility list length and can therefore wrongly inject a validity intercept. Instead, find out the host facility list length by running STFLE and copy only as much as necessary when shadowing. Acked-by: David Hildenbrand <david@redhat.com> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Acked-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com> Reviewed-by: Janosch Frank <frankja@linux.ibm.com> Link: https://lore.kernel.org/r/20231219140854.1042599-3-nsg@linux.ibm.com Signed-off-by: Janosch Frank <frankja@linux.ibm.com> Message-ID: <20231219140854.1042599-3-nsg@linux.ibm.com>
1 parent 2731d60 commit 682dbf4

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

arch/s390/include/asm/facility.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,10 @@ static inline void stfle(u64 *stfle_fac_list, int size)
111111
preempt_enable();
112112
}
113113

114+
/**
115+
* stfle_size - Actual size of the facility list as specified by stfle
116+
* (number of double words)
117+
*/
118+
unsigned int stfle_size(void);
119+
114120
#endif /* __ASM_FACILITY_H */

arch/s390/kernel/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ obj-y += sysinfo.o lgr.o os_info.o ctlreg.o
4141
obj-y += runtime_instr.o cache.o fpu.o dumpstack.o guarded_storage.o sthyi.o
4242
obj-y += entry.o reipl.o kdebugfs.o alternative.o
4343
obj-y += nospec-branch.o ipl_vmparm.o machine_kexec_reloc.o unwind_bc.o
44-
obj-y += smp.o text_amode31.o stacktrace.o abs_lowcore.o
44+
obj-y += smp.o text_amode31.o stacktrace.o abs_lowcore.o facility.o
4545

4646
extra-y += vmlinux.lds
4747

arch/s390/kernel/facility.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright IBM Corp. 2023
4+
*/
5+
6+
#include <asm/facility.h>
7+
8+
unsigned int stfle_size(void)
9+
{
10+
static unsigned int size;
11+
unsigned int r;
12+
u64 dummy;
13+
14+
r = READ_ONCE(size);
15+
if (!r) {
16+
r = __stfle_asm(&dummy, 1) + 1;
17+
WRITE_ONCE(size, r);
18+
}
19+
return r;
20+
}
21+
EXPORT_SYMBOL(stfle_size);

arch/s390/kvm/vsie.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <asm/nmi.h>
2020
#include <asm/dis.h>
2121
#include <asm/fpu/api.h>
22+
#include <asm/facility.h>
2223
#include "kvm-s390.h"
2324
#include "gaccess.h"
2425

@@ -990,15 +991,24 @@ static int handle_stfle(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
990991
struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
991992
__u32 fac = READ_ONCE(vsie_page->scb_o->fac);
992993

994+
/*
995+
* Alternate-STFLE-Interpretive-Execution facilities are not supported
996+
* -> format-0 flcb
997+
*/
993998
if (fac && test_kvm_facility(vcpu->kvm, 7)) {
994999
retry_vsie_icpt(vsie_page);
9951000
/*
9961001
* The facility list origin (FLO) is in bits 1 - 28 of the FLD
9971002
* so we need to mask here before reading.
9981003
*/
9991004
fac = fac & 0x7ffffff8U;
1005+
/*
1006+
* format-0 -> size of nested guest's facility list == guest's size
1007+
* guest's size == host's size, since STFLE is interpretatively executed
1008+
* using a format-0 for the guest, too.
1009+
*/
10001010
if (read_guest_real(vcpu, fac, &vsie_page->fac,
1001-
sizeof(vsie_page->fac)))
1011+
stfle_size() * sizeof(u64)))
10021012
return set_validity_icpt(scb_s, 0x1090U);
10031013
scb_s->fac = (__u32)(__u64) &vsie_page->fac;
10041014
}

0 commit comments

Comments
 (0)