Skip to content

Commit c2385ea

Browse files
eaugerchazy
authored andcommitted
KVM: arm/arm64: vgic-its: Check GITS_BASER Valid bit before saving tables
At the moment we don't properly check the GITS_BASER<n>.Valid bit before saving the collection and device tables. On vgic_its_save_collection_table() we use the GITS_BASER gpa field whereas the Valid bit should be used. On vgic_its_save_device_tables() there is no check. This can cause various bugs, among which a subsequent fault when accessing the table in guest memory. Let's systematically check the Valid bit before doing anything. We also uniformize the code between save and restore. Signed-off-by: Eric Auger <eric.auger@redhat.com> Reviewed-by: Andre Przywara <andre.przywara@arm.com> Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org> Reviewed-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
1 parent c9b51bb commit c2385ea

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

virt/kvm/arm/vgic/vgic-its.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,11 +2067,12 @@ static int vgic_its_device_cmp(void *priv, struct list_head *a,
20672067
static int vgic_its_save_device_tables(struct vgic_its *its)
20682068
{
20692069
const struct vgic_its_abi *abi = vgic_its_get_abi(its);
2070+
u64 baser = its->baser_device_table;
20702071
struct its_device *dev;
20712072
int dte_esz = abi->dte_esz;
2072-
u64 baser;
20732073

2074-
baser = its->baser_device_table;
2074+
if (!(baser & GITS_BASER_VALID))
2075+
return 0;
20752076

20762077
list_sort(NULL, &its->device_list, vgic_its_device_cmp);
20772078

@@ -2215,17 +2216,17 @@ static int vgic_its_restore_cte(struct vgic_its *its, gpa_t gpa, int esz)
22152216
static int vgic_its_save_collection_table(struct vgic_its *its)
22162217
{
22172218
const struct vgic_its_abi *abi = vgic_its_get_abi(its);
2219+
u64 baser = its->baser_coll_table;
2220+
gpa_t gpa = BASER_ADDRESS(baser);
22182221
struct its_collection *collection;
22192222
u64 val;
2220-
gpa_t gpa;
22212223
size_t max_size, filled = 0;
22222224
int ret, cte_esz = abi->cte_esz;
22232225

2224-
gpa = BASER_ADDRESS(its->baser_coll_table);
2225-
if (!gpa)
2226+
if (!(baser & GITS_BASER_VALID))
22262227
return 0;
22272228

2228-
max_size = GITS_BASER_NR_PAGES(its->baser_coll_table) * SZ_64K;
2229+
max_size = GITS_BASER_NR_PAGES(baser) * SZ_64K;
22292230

22302231
list_for_each_entry(collection, &its->collection_list, coll_list) {
22312232
ret = vgic_its_save_cte(its, collection, gpa, cte_esz);
@@ -2256,17 +2257,18 @@ static int vgic_its_save_collection_table(struct vgic_its *its)
22562257
static int vgic_its_restore_collection_table(struct vgic_its *its)
22572258
{
22582259
const struct vgic_its_abi *abi = vgic_its_get_abi(its);
2260+
u64 baser = its->baser_coll_table;
22592261
int cte_esz = abi->cte_esz;
22602262
size_t max_size, read = 0;
22612263
gpa_t gpa;
22622264
int ret;
22632265

2264-
if (!(its->baser_coll_table & GITS_BASER_VALID))
2266+
if (!(baser & GITS_BASER_VALID))
22652267
return 0;
22662268

2267-
gpa = BASER_ADDRESS(its->baser_coll_table);
2269+
gpa = BASER_ADDRESS(baser);
22682270

2269-
max_size = GITS_BASER_NR_PAGES(its->baser_coll_table) * SZ_64K;
2271+
max_size = GITS_BASER_NR_PAGES(baser) * SZ_64K;
22702272

22712273
while (read < max_size) {
22722274
ret = vgic_its_restore_cte(its, gpa, cte_esz);

0 commit comments

Comments
 (0)