[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190416213351.28999-1-xiyou.wangcong@gmail.com>
Date: Tue, 16 Apr 2019 14:33:50 -0700
From: Cong Wang <xiyou.wangcong@...il.com>
To: linux-kernel@...r.kernel.org
Cc: linux-edac@...r.kernel.org, Cong Wang <xiyou.wangcong@...il.com>,
Tony Luck <tony.luck@...el.com>,
Borislav Petkov <bp@...en8.de>,
Thomas Gleixner <tglx@...utronix.de>
Subject: [PATCH v2 1/2] ras: fix an off-by-one error in __find_elem()
ce_arr.array[] is always within the range [0, ce_arr.n-1].
However, the binary search code in __find_elem() uses ce_arr.n
as the maximum index, which could lead to an off-by-one
out-of-bound access right after the while loop. In this case,
we should not even read it, just return -ENOKEY instead.
Note, this could cause a kernel crash if ce_arr.n is exactly
MAX_ELEMS.
Fixes: 011d82611172 ("RAS: Add a Corrected Errors Collector")
Cc: Tony Luck <tony.luck@...el.com>
Cc: Borislav Petkov <bp@...en8.de>
Cc: Thomas Gleixner <tglx@...utronix.de>
Signed-off-by: Cong Wang <xiyou.wangcong@...il.com>
---
drivers/ras/cec.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/ras/cec.c b/drivers/ras/cec.c
index 2d9ec378a8bc..a4ff54e50673 100644
--- a/drivers/ras/cec.c
+++ b/drivers/ras/cec.c
@@ -204,10 +204,11 @@ static int __find_elem(struct ce_array *ca, u64 pfn, unsigned int *to)
if (to)
*to = min;
- this_pfn = PFN(ca->array[min]);
-
- if (this_pfn == pfn)
- return min;
+ if (min < ca->n) {
+ this_pfn = PFN(ca->array[min]);
+ if (this_pfn == pfn)
+ return min;
+ }
return -ENOKEY;
}
--
2.20.1
Powered by blists - more mailing lists