Skip to content

Commit a1ccfd6

Browse files
Ricardo KollerMarc Zyngier
authored andcommitted
KVM: arm64: vgic: Do not ignore vgic_its_restore_cte failures
Restoring a corrupted collection entry (like an out of range ID) is being ignored and treated as success. More specifically, a vgic_its_restore_cte failure is treated as success by vgic_its_restore_collection_table. vgic_its_restore_cte uses positive and negative numbers to return error, and +1 to return success. The caller then uses "ret > 0" to check for success. Fix this by having vgic_its_restore_cte only return negative numbers on error. Do this by changing alloc_collection return codes to only return negative numbers on error. 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-4-ricarkol@google.com
1 parent 243b1f6 commit a1ccfd6

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -999,15 +999,16 @@ static bool vgic_its_check_event_id(struct vgic_its *its, struct its_device *dev
999999
return __is_visible_gfn_locked(its, gpa);
10001000
}
10011001

1002+
/*
1003+
* Add a new collection into the ITS collection table.
1004+
* Returns 0 on success, and a negative error value for generic errors.
1005+
*/
10021006
static int vgic_its_alloc_collection(struct vgic_its *its,
10031007
struct its_collection **colp,
10041008
u32 coll_id)
10051009
{
10061010
struct its_collection *collection;
10071011

1008-
if (!vgic_its_check_id(its, its->baser_coll_table, coll_id, NULL))
1009-
return E_ITS_MAPC_COLLECTION_OOR;
1010-
10111012
collection = kzalloc(sizeof(*collection), GFP_KERNEL_ACCOUNT);
10121013
if (!collection)
10131014
return -ENOMEM;
@@ -1101,7 +1102,12 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its,
11011102

11021103
collection = find_collection(its, coll_id);
11031104
if (!collection) {
1104-
int ret = vgic_its_alloc_collection(its, &collection, coll_id);
1105+
int ret;
1106+
1107+
if (!vgic_its_check_id(its, its->baser_coll_table, coll_id, NULL))
1108+
return E_ITS_MAPC_COLLECTION_OOR;
1109+
1110+
ret = vgic_its_alloc_collection(its, &collection, coll_id);
11051111
if (ret)
11061112
return ret;
11071113
new_coll = collection;
@@ -1256,6 +1262,10 @@ static int vgic_its_cmd_handle_mapc(struct kvm *kvm, struct vgic_its *its,
12561262
if (!collection) {
12571263
int ret;
12581264

1265+
if (!vgic_its_check_id(its, its->baser_coll_table,
1266+
coll_id, NULL))
1267+
return E_ITS_MAPC_COLLECTION_OOR;
1268+
12591269
ret = vgic_its_alloc_collection(its, &collection,
12601270
coll_id);
12611271
if (ret)
@@ -2491,6 +2501,11 @@ static int vgic_its_save_cte(struct vgic_its *its,
24912501
return kvm_write_guest_lock(its->dev->kvm, gpa, &val, esz);
24922502
}
24932503

2504+
/*
2505+
* Restore a collection entry into the ITS collection table.
2506+
* Return +1 on success, 0 if the entry was invalid (which should be
2507+
* interpreted as end-of-table), and a negative error value for generic errors.
2508+
*/
24942509
static int vgic_its_restore_cte(struct vgic_its *its, gpa_t gpa, int esz)
24952510
{
24962511
struct its_collection *collection;
@@ -2517,6 +2532,10 @@ static int vgic_its_restore_cte(struct vgic_its *its, gpa_t gpa, int esz)
25172532
collection = find_collection(its, coll_id);
25182533
if (collection)
25192534
return -EEXIST;
2535+
2536+
if (!vgic_its_check_id(its, its->baser_coll_table, coll_id, NULL))
2537+
return -EINVAL;
2538+
25202539
ret = vgic_its_alloc_collection(its, &collection, coll_id);
25212540
if (ret)
25222541
return ret;

0 commit comments

Comments
 (0)