mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] genirq/timings: prevent potential array overflow in __irq_timings_store()
@ 2021-04-25 15:09 Ben Dai
  2021-08-10 13:41 ` [tip: irq/urgent] genirq/timings: Prevent " tip-bot2 for Ben Dai
  0 siblings, 1 reply; 2+ messages in thread
From: Ben Dai @ 2021-04-25 15:09 UTC (permalink / raw)
  To: tglx; +Cc: linux-kernel, Ben Dai

From: Ben Dai <ben.dai@unisoc.com>

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.

Signed-off-by: Ben Dai <ben.dai@unisoc.com>
---
 kernel/irq/timings.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/irq/timings.c b/kernel/irq/timings.c
index 773b6105c4ae..6990490fa67b 100644
--- a/kernel/irq/timings.c
+++ b/kernel/irq/timings.c
@@ -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.
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-10 13:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-25 15:09 [PATCH] genirq/timings: prevent potential array overflow in __irq_timings_store() Ben Dai
2021-08-10 13:41 ` [tip: irq/urgent] genirq/timings: Prevent " tip-bot2 for Ben Dai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®