Skip to contentSkip to conversation

ARC: Fix array-out-of-bounds issue in tlb overlap handler

PATCH In review Mischa Jonker 2 participants 2 messages Sep 26, 2013 Synopsys ARC architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARC: Fix array-out-of-bounds issue in tlb overlap handler

Even after fixing the issue, GCC 4.8 still complains with a warning, but with the fix, I think it's a false positive. Therefore I have also added a #pragma to ignore the warning.

---
 arch/arc/mm/tlb.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
arch/arc/mm/tlb.c +8 -1
index 129af50..5af7c98 100644
@@ -635,13 +635,20 @@ void do_tlb_overlap_fault(unsigned long cause, unsigned long address,
 			continue;
 
 		/* Scan the set for duplicate ways: needs a nested loop */
-		for (way = 0; way < mmu->ways; way++) {
+		for (way = 0; way < (mmu->ways - 1); way++) {
 			if (!pd0[way])
 				continue;
 
 			for (n = way + 1; n < mmu->ways; n++) {
+/*
+ * GCC 4.8 does not understand that way < (mmu->ways - 1), and as such
+ * n < mmu->ways. So, ignore the warning
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
 				if ((pd0[way] & PAGE_MASK) ==
 				    (pd0[n] & PAGE_MASK)) {
+#pragma GCC diagnostic pop
 
 					if (dup_pd_verbose) {
 						pr_info("Duplicate PD's @"
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 14 lines · Mischa Jonker

Even after fixing the issue, GCC 4.8 still complains with a warning, but with the fix, I think it's a false positive. Therefore I have also added a #pragma to ignore the warning.

---
 arch/arc/mm/tlb.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
arch/arc/mm/tlb.c +0 -0
index 129af50..5af7c98 100644

arch/arc/mm/tlb.c void do_tlb_overlap_fault(unsigned long cause, unsigned long address, · line 640

Quoted 7 lines
arch/arc/mm/tlb.c +1 -1
@@ -635,13 +635,20 @@ void do_tlb_overlap_fault(unsigned long cause, unsigned long address,
 			continue;
 
 		/* Scan the set for duplicate ways: needs a nested loop */
-		for (way = 0; way < mmu->ways; way++) {
+		for (way = 0; way < (mmu->ways - 1); way++) {
 			if (!pd0[way])
 				continue;

While the fix is correct, it's not fixing out-of-bound array access since that is not what was happening. For the last way, the nested loop will not enter at all - your fix prevents it from trying to do that - so please fix the changlog.

arch/arc/mm/tlb.c void do_tlb_overlap_fault(unsigned long cause, unsigned long address, · line 654

Quoted 13 lines
arch/arc/mm/tlb.c +7 -0
 			for (n = way + 1; n < mmu->ways; n++) {
+/*
+ * GCC 4.8 does not understand that way < (mmu->ways - 1), and as such
+ * n < mmu->ways. So, ignore the warning
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
 				if ((pd0[way] & PAGE_MASK) ==
 				    (pd0[n] & PAGE_MASK)) {
+#pragma GCC diagnostic pop
 
 					if (dup_pd_verbose) {
 						pr_info("Duplicate PD's @"

I'd prefer the following as it's less uglier.

- unsigned int pd0[4], pd1[4]; /* assume max 4 ways */

        unsigned long flags, is_valid;
        struct cpuinfo_arc_mmu *mmu = &cpuinfo_arc700[smp_processor_id()].mmu;

+ unsigned int pd0[mmu->ways], pd1[mmu->ways];

-Vineet