Skip to content

Commit a1d032a

Browse files
davidhildenbrandborntraeger
authored andcommitted
KVM: s390: vsie: Fix region 1 ASCE sanity shadow address checks
In case we have a region 1 the following calculation (31 + ((gmap->asce & _ASCE_TYPE_MASK) >> 2)*11) results in 64. As shifts beyond the size are undefined the compiler is free to use instructions like sllg. sllg will only use 6 bits of the shift value (here 64) resulting in no shift at all. That means that ALL addresses will be rejected. The can result in endless loops, e.g. when prefix cannot get mapped. Fixes: 4be130a ("s390/mm: add shadow gmap support") Tested-by: Janosch Frank <[email protected]> Reported-by: Janosch Frank <[email protected]> Cc: <[email protected]> # v4.8+ Signed-off-by: David Hildenbrand <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Claudio Imbrenda <[email protected]> Reviewed-by: Christian Borntraeger <[email protected]> [[email protected]: fix patch description, remove WARN_ON_ONCE] Signed-off-by: Christian Borntraeger <[email protected]>
1 parent 8c1b724 commit a1d032a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

arch/s390/mm/gmap.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,14 +787,18 @@ static void gmap_call_notifier(struct gmap *gmap, unsigned long start,
787787
static inline unsigned long *gmap_table_walk(struct gmap *gmap,
788788
unsigned long gaddr, int level)
789789
{
790+
const int asce_type = gmap->asce & _ASCE_TYPE_MASK;
790791
unsigned long *table;
791792

792793
if ((gmap->asce & _ASCE_TYPE_MASK) + 4 < (level * 4))
793794
return NULL;
794795
if (gmap_is_shadow(gmap) && gmap->removed)
795796
return NULL;
796-
if (gaddr & (-1UL << (31 + ((gmap->asce & _ASCE_TYPE_MASK) >> 2)*11)))
797+
798+
if (asce_type != _ASCE_TYPE_REGION1 &&
799+
gaddr & (-1UL << (31 + (asce_type >> 2) * 11)))
797800
return NULL;
801+
798802
table = gmap->table;
799803
switch (gmap->asce & _ASCE_TYPE_MASK) {
800804
case _ASCE_TYPE_REGION1:

0 commit comments

Comments
 (0)