# \[PATCH 5.13 126/151\] genirq/timings: Prevent potential array overflow in \_\_irq\_timings\_store()

- From: Greg Kroah-Hartman \<gregkh@linuxfoundation.org\>
- Date: 2021-08-16 13:30:03 
- List: stable
- Page: https://ratatoskr.run/stable/2021/08/1479187
- Thread: https://ratatoskr.run/stable/2021/08/1479087/t/2.md

```text
From: Ben Dai <redacted>

commit b9cc7d8a4656a6e815852c27ab50365009cb69c1 upstream.

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")
Signed-off-by: Ben Dai <redacted>
Signed-off-by: Thomas Gleixner <redacted>
Cc: <redacted>
Link: https://lore.kernel.org/r/20210425150903.25456-1-ben.dai9703@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 kernel/irq/timings.c |    5 +++++
 1 file changed, 5 insertions(+)

--- a/kernel/irq/timings.c
+++ b/kernel/irq/timings.c
@@ -453,6 +453,11 @@ static __always_inline void __irq_timing
 	 */
 	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.


```
