Skip to content

Commit 243b1f6

Browse files
Ricardo KollerMarc Zyngier
authored andcommitted
KVM: arm64: vgic: Add more checks when restoring ITS tables
Try to improve the predictability of ITS save/restores (and debuggability of failed ITS saves) by failing early on restore when trying to read corrupted tables. Restoring the ITS tables does some checks for corrupted tables, but not as many as in a save: an overflowing device ID will be detected on save but not on restore. The consequence is that restoring a corrupted table won't be detected until the next save; including the ITS not working as expected after the restore. As an example, if the guest sets tables overlapping each other, which would most likely result in some corrupted table, this is what we would see from the host point of view: guest sets base addresses that overlap each other save ioctl restore ioctl save ioctl (fails) Ideally, we would like the first save to fail, but overlapping tables could actually be intended by the guest. So, let's at least fail on the restore with some checks: like checking that device and event IDs don't overflow their tables. Signed-off-by: Ricardo Koller <ricarkol@google.com> Reviewed-by: Oliver Upton <oupton@google.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20220510001633.552496-3-ricarkol@google.com
1 parent cafe7e5 commit 243b1f6

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

arch/arm64/kvm/vgic/vgic-its.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,9 @@ static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id,
21982198
if (!collection)
21992199
return -EINVAL;
22002200

2201+
if (!vgic_its_check_event_id(its, dev, event_id))
2202+
return -EINVAL;
2203+
22012204
ite = vgic_its_alloc_ite(dev, collection, event_id);
22022205
if (IS_ERR(ite))
22032206
return PTR_ERR(ite);
@@ -2319,6 +2322,7 @@ static int vgic_its_restore_dte(struct vgic_its *its, u32 id,
23192322
void *ptr, void *opaque)
23202323
{
23212324
struct its_device *dev;
2325+
u64 baser = its->baser_device_table;
23222326
gpa_t itt_addr;
23232327
u8 num_eventid_bits;
23242328
u64 entry = *(u64 *)ptr;
@@ -2339,6 +2343,9 @@ static int vgic_its_restore_dte(struct vgic_its *its, u32 id,
23392343
/* dte entry is valid */
23402344
offset = (entry & KVM_ITS_DTE_NEXT_MASK) >> KVM_ITS_DTE_NEXT_SHIFT;
23412345

2346+
if (!vgic_its_check_id(its, baser, id, NULL))
2347+
return -EINVAL;
2348+
23422349
dev = vgic_its_alloc_device(its, id, itt_addr, num_eventid_bits);
23432350
if (IS_ERR(dev))
23442351
return PTR_ERR(dev);

0 commit comments

Comments
 (0)