Skip to contentSkip to conversation

x86/Hyper-V: Fix overflow issue in the fill_gva_list()

PATCH In review [email protected] 2 participants 2 messages Sep 2, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/Hyper-V: Fix overflow issue in the fill_gva_list()

From: Tianyu Lan <[email protected]>

When the 'start' parameter is >= 0xFF000000 on 32-bit systems, or >= 0xFFFFFFFF'FF000000 on 64-bit systems, fill_gva_list gets into an infinite loop. With such inputs, 'cur' overflows after adding HV_TLB_FLUSH_UNIT and always compares as less than end. Memory is filled with guest virtual addresses until the system crashes

Fix this by never incrementing 'cur' to be larger than 'end'.

Fixes 2ffd9e33ce4a ("x86/hyper-v: Use hypercall for remote TLB flush")

---
Change since v1:
- Simply the commit message

 arch/x86/hyperv/mmu.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/x86/hyperv/mmu.c +5 -3
index e65d7fe6489f..5208ba49c89a 100644
@@ -37,12 +37,14 @@ static inline int fill_gva_list(u64 gva_list[], int offset,
 		 * Lower 12 bits encode the number of additional
 		 * pages to flush (in addition to the 'cur' page).
 		 */
-		if (diff >= HV_TLB_FLUSH_UNIT)
+		if (diff >= HV_TLB_FLUSH_UNIT) {
 			gva_list[gva_n] |= ~PAGE_MASK;
-		else if (diff)
+			cur += HV_TLB_FLUSH_UNIT;
+		}  else if (diff) {
 			gva_list[gva_n] |= (diff - 1) >> PAGE_SHIFT;
+			cur = end;
+		}
 
-		cur += HV_TLB_FLUSH_UNIT;
 		gva_n++;
 
 	} while (cur < end);
Signature · 1 line
2.14.5
Reviewed-by on v2 1/1
#1 lore raw

From: Tianyu Lan <[email protected]> Sent: Monday, September 2, 2019 5:42 AM

Quoted 43 lines

When the 'start' parameter is >= 0xFF000000 on 32-bit systems, or >= 0xFFFFFFFF'FF000000 on 64-bit systems, fill_gva_list gets into an infinite loop. With such inputs, 'cur' overflows after adding HV_TLB_FLUSH_UNIT and always compares as less than end. Memory is filled with guest virtual addresses until the system crashes

Fix this by never incrementing 'cur' to be larger than 'end'.

Fixes 2ffd9e33ce4a ("x86/hyper-v: Use hypercall for remote TLB flush")

---
Change since v1:
- Simply the commit message

 arch/x86/hyperv/mmu.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/x86/hyperv/mmu.c +5 -4
index e65d7fe6489f..5208ba49c89a 100644
@@ -37,12 +37,14 @@ static inline int fill_gva_list(u64 gva_list[], int offset,
 		 * Lower 12 bits encode the number of additional
 		 * pages to flush (in addition to the 'cur' page).
 		 */
-		if (diff >= HV_TLB_FLUSH_UNIT)
+		if (diff >= HV_TLB_FLUSH_UNIT) {
 			gva_list[gva_n] |= ~PAGE_MASK;
-		else if (diff)
+			cur += HV_TLB_FLUSH_UNIT;
+		}  else if (diff) {
 			gva_list[gva_n] |= (diff - 1) >> PAGE_SHIFT;
+			cur = end;
+		}
 
-		cur += HV_TLB_FLUSH_UNIT;
 		gva_n++;
 
 	} while (cur < end);
--
Quoted 1 line

2.14.5