Skip to content

Commit 2f393c2

Browse files
Claudio Imbrendahcahca
authored andcommitted
KVM: s390: Fix gmap_helper_zap_one_page() again
A few checks were missing in gmap_helper_zap_one_page(), which can lead to memory corruption in the guest under specific circumstances. Add the missing checks. Fixes: 5deafa2 ("KVM: s390: Fix to clear PTE when discarding a swapped page") Cc: stable@vger.kernel.org Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com> Tested-by: Marc Hartmayer <mhartmay@linux.ibm.com> Acked-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent f770950 commit 2f393c2

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

arch/s390/mm/gmap_helpers.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static void ptep_zap_softleaf_entry(struct mm_struct *mm, softleaf_t entry)
4747
void gmap_helper_zap_one_page(struct mm_struct *mm, unsigned long vmaddr)
4848
{
4949
struct vm_area_struct *vma;
50+
unsigned long pgstev;
5051
spinlock_t *ptl;
5152
pgste_t pgste;
5253
pte_t *ptep;
@@ -65,9 +66,13 @@ void gmap_helper_zap_one_page(struct mm_struct *mm, unsigned long vmaddr)
6566
if (pte_swap(*ptep)) {
6667
preempt_disable();
6768
pgste = pgste_get_lock(ptep);
69+
pgstev = pgste_val(pgste);
6870

69-
ptep_zap_softleaf_entry(mm, softleaf_from_pte(*ptep));
70-
pte_clear(mm, vmaddr, ptep);
71+
if ((pgstev & _PGSTE_GPS_USAGE_MASK) == _PGSTE_GPS_USAGE_UNUSED ||
72+
(pgstev & _PGSTE_GPS_ZERO)) {
73+
ptep_zap_softleaf_entry(mm, softleaf_from_pte(*ptep));
74+
pte_clear(mm, vmaddr, ptep);
75+
}
7176

7277
pgste_set_unlock(ptep, pgste);
7378
preempt_enable();

0 commit comments

Comments
 (0)