linux-kernel.vger.kernel.org archive mirror
 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 related	[flat|nested] 2+ messages in thread

* [tip: irq/urgent] genirq/timings: Prevent potential array overflow in __irq_timings_store()
  2021-04-25 15:09 [PATCH] genirq/timings: prevent potential array overflow in __irq_timings_store() Ben Dai
@ 2021-08-10 13:41 ` tip-bot2 for Ben Dai
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Ben Dai @ 2021-08-10 13:41 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Ben Dai, Thomas Gleixner, stable, x86, linux-kernel, maz

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 <ben.dai@unisoc.com>
AuthorDate:    Sun, 25 Apr 2021 23:09:03 +08:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
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")
Signed-off-by: Ben Dai <ben.dai@unisoc.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20210425150903.25456-1-ben.dai9703@gmail.com

---
 kernel/irq/timings.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/irq/timings.c b/kernel/irq/timings.c
index d309d6f..4d2a702 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.

^ permalink raw reply related	[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;
as well as URLs for NNTP newsgroup(s).