mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Christian Melki <christian.melki@t2data.com>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 2/2] hab: habv4: warn if more than 10 HAB events are found
Date: Thu, 11 Jan 2024 13:12:19 +0100	[thread overview]
Message-ID: <20240111121219.1505025-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240111121219.1505025-1-a.fatoum@pengutronix.de>

The function has space for up to 10 HAB events. On the off-chance that
there are more found, it will scribble them over stack memory.

Fix this by only collecting up to 10 events and printing a warning if
that's exceeded. Once we have reports that this issue manifests, we can
consider extending the array or dynamically allocating it.

Reported-by: Christian Melki <christian.melki@t2data.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/hab/habv4.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/hab/habv4.c b/drivers/hab/habv4.c
index 4db1e7cc0f3a..66caa875835d 100644
--- a/drivers/hab/habv4.c
+++ b/drivers/hab/habv4.c
@@ -255,7 +255,10 @@ static enum hab_status imx8m_read_sram_events(enum hab_status status,
 				break;
 
 			events[num_events] = search;
-			num_events++;
+			if (num_events < ARRAY_SIZE(events))
+				num_events++;
+			else
+				pr_warn("Discarding excess event\n");
 		} else {
 			sram++;
 		}
-- 
2.39.2




      reply	other threads:[~2024-01-11 12:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-11 12:12 [PATCH master 1/2] hab: habv4: use explicitly unsigned types for pointers into SRAM Ahmad Fatoum
2024-01-11 12:12 ` Ahmad Fatoum [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240111121219.1505025-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=christian.melki@t2data.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox