Skip to content

Commit 2162faf

Browse files
davidhildenbrandhuth
authored andcommitted
hw/s390x/s390-skeys: check if an address is valid before dumping the key
Let's validate the given address and report a proper error in case it's not. All call paths now properly check the validity of the given GFN. Remove the TODO. The errors inside the getter and setter should only trigger if something really goes wrong now, for example, with a broken migration stream. Or when we forget to update the storage key allocation with memory hotplug. Signed-off-by: David Hildenbrand <[email protected]> Acked-by: Thomas Huth <[email protected]> Message-Id: <[email protected]> Signed-off-by: Thomas Huth <[email protected]>
1 parent 78eedc6 commit 2162faf

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

hw/s390x/s390-skeys.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qapi/qmp/qdict.h"
1919
#include "qemu/error-report.h"
2020
#include "sysemu/memory_mapping.h"
21+
#include "exec/address-spaces.h"
2122
#include "sysemu/kvm.h"
2223
#include "migration/qemu-file-types.h"
2324
#include "migration/register.h"
@@ -86,6 +87,13 @@ void hmp_info_skeys(Monitor *mon, const QDict *qdict)
8687
return;
8788
}
8889

90+
if (!address_space_access_valid(&address_space_memory,
91+
addr & TARGET_PAGE_MASK, TARGET_PAGE_SIZE,
92+
false, MEMTXATTRS_UNSPECIFIED)) {
93+
monitor_printf(mon, "Error: The given address is not valid\n");
94+
return;
95+
}
96+
8997
r = skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key);
9098
if (r < 0) {
9199
monitor_printf(mon, "Error: %s\n", strerror(-r));
@@ -197,11 +205,6 @@ static int qemu_s390_skeys_enabled(S390SKeysState *ss)
197205
return 1;
198206
}
199207

200-
/*
201-
* TODO: for memory hotplug support qemu_s390_skeys_set and qemu_s390_skeys_get
202-
* will have to make sure that the given gfn belongs to a memory region and not
203-
* a memory hole.
204-
*/
205208
static int qemu_s390_skeys_set(S390SKeysState *ss, uint64_t start_gfn,
206209
uint64_t count, uint8_t *keys)
207210
{

0 commit comments

Comments
 (0)