shithub: riscv

Download patch

ref: ba7b07d51ad65d9a2d38e08799525c7716c77825
parent: 4f2cdcf74bddc52179e205ac98774c4a6d194ed0
author: cinap_lenrek <[email protected]>
date: Sat Sep 8 21:41:35 EDT 2018

devarch: restrict i/o port access to 64K, disallow msr 32-bit wrap arround (thanks aiju)

--- a/sys/src/9/pc/devarch.c
+++ b/sys/src/9/pc/devarch.c
@@ -309,8 +309,11 @@
 }
 
 static void
-checkport(int start, int end)
+checkport(uint start, uint end)
 {
+	if(end < start || end > 0x10000)
+		error(Ebadarg);
+
 	/* standard vga regs are OK */
 	if(start >= 0x2b0 && end <= 0x2df+1)
 		return;
@@ -356,12 +359,12 @@
 {
 	char buf[32], *p;
 	uint port, end;
-	int i;
 	ushort *sp;
 	ulong *lp;
 	vlong *vp;
 	IOMap *m;
 	Rdwrfn *fn;
+	int i;
 
 	port = offset;
 	end = port+n;
@@ -394,6 +397,8 @@
 	case Qmsr:
 		if(n & 7)
 			error(Ebadarg);
+		if((uint)n/8 > -port)
+			error(Ebadarg);
 		end = port+(n/8);
 		for(vp = a; port < end; port++)
 			if(rdmsr(port, vp++) < 0)
@@ -464,6 +469,8 @@
 
 	case Qmsr:
 		if(n & 7)
+			error(Ebadarg);
+		if((uint)n/8 > -port)
 			error(Ebadarg);
 		end = port+(n/8);
 		for(vp = a; port < end; port++)