From 78c7ad88ffbfbd2b7a7269d863e5f4be7535b566 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Fri, 26 Nov 2021 21:47:15 +0000 Subject: [PATCH] kernel: add extra negative and power-of-two check to pcibarsize() --- sys/src/9/port/pci.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sys/src/9/port/pci.c b/sys/src/9/port/pci.c index a6fa3abfa..5ca42d5ac 100644 --- a/sys/src/9/port/pci.c +++ b/sys/src/9/port/pci.c @@ -190,16 +190,16 @@ pcibarsize(Pcidev *p, int rno) pcicfgrw32(p->tbdf, rno, v, 0); } } + size = -size; iunlock(&pcicfglock); - if(size > 0){ - print("pcibarsize: %T invalid bar rno %x mask %llux\n", - p->tbdf, rno, (uvlong)size); + if(size < 0 || (size & size-1) != 0){ + print("pcibarsize: %T invalid bar rno %#x size %#llux mask %#llux\n", + p->tbdf, rno, size, -size); return 0; } - - return -size; + return size; } void