Skip to contentSkip to conversation

genirq/timings: prevent potential array overflow in __irq_timings_store()

PATCH Applied Ben Dai 2 participants 2 messages Apr 25, 2021 – Aug 10, 2021

Subsystems (2)
lore
Share & tools
lore

Ben Dai

author
#0 lore raw

PATCH 1/1 genirq/timings: prevent potential array overflow in __irq_timings_store()

From: Ben Dai <[email protected]>

When the interrupt interval is greater than 2 ^ PREDICTION_BUFFER_SIZE * PREDICTION_FACTOR us and less than 1s, the calculated index will be greater than the length of irqs->ema_time[]. Check the calculated index before using it to prevent array overflow.

---
 kernel/irq/timings.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/irq/timings.c +5 -0
index 773b6105c4ae..6990490fa67b 100644
@@ -453,6 +453,11 @@ static __always_inline void __irq_timings_store(int irq, struct irqt_stat *irqs,
 	 */
 	index = irq_timings_interval_index(interval);
 
+	if (index > PREDICTION_BUFFER_SIZE - 1) {
+		irqs->count = 0;
+		return;
+	}
+
 	/*
 	 * Store the index as an element of the pattern in another
 	 * circular array.
Signature · 1 line
2.25.1
merge bot Applied
#1 lore raw

[tip: irq/urgent] genirq/timings: Prevent potential array overflow in __irq_timings_store()

The following commit has been merged into the irq/urgent branch of tip:

The following commit has been merged into the irq/urgent branch of tip:

Commit-ID:     b9cc7d8a4656a6e815852c27ab50365009cb69c1
Gitweb:        https://git.kernel.org/tip/b9cc7d8a4656a6e815852c27ab50365009cb69c1
Author:        Ben Dai <[email protected]>
AuthorDate:    Sun, 25 Apr 2021 23:09:03 +08:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Tue, 10 Aug 2021 15:39:00 +02:00

genirq/timings: Prevent potential array overflow in __irq_timings_store()

When the interrupt interval is greater than 2 ^ PREDICTION_BUFFER_SIZE * PREDICTION_FACTOR us and less than 1s, the calculated index will be greater than the length of irqs->ema_time[]. Check the calculated index before using it to prevent array overflow.

Fixes 23aa3b9a6b7d ("genirq/timings: Encapsulate storing function")
---
 kernel/irq/timings.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/irq/timings.c +5 -0
index d309d6f..4d2a702 100644
@@ -453,6 +453,11 @@ static __always_inline void __irq_timings_store(int irq, struct irqt_stat *irqs,
 	 */
 	index = irq_timings_interval_index(interval);
 
+	if (index > PREDICTION_BUFFER_SIZE - 1) {
+		irqs->count = 0;
+		return;
+	}
+
 	/*
 	 * Store the index as an element of the pattern in another
 	 * circular array.