From: Christian Melki <christian.melki@t2data.com>
To: barebox@lists.infradead.org
Subject: [PATCH] habv4: Fix parsing of unresonable events.
Date: Mon, 18 Dec 2023 21:25:44 +0100 [thread overview]
Message-ID: <20231218202544.3952838-1-christian.melki@t2data.com> (raw)
An unknown root cause made data look like events (0xdb)
with very long event lengths. This was causing
very long printouts of bogus stuff in the console.
While the root cause needs to be found and fixed,
there is no need of parsing events with abnormal lengths.
Also stop parsing if length exceeds the end of scope.
Signed-off-by: Christian Melki <christian.melki@t2data.com>
---
drivers/hab/habv4.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/hab/habv4.c b/drivers/hab/habv4.c
index f74de009fc..1a55a3e448 100644
--- a/drivers/hab/habv4.c
+++ b/drivers/hab/habv4.c
@@ -203,6 +203,8 @@ static uint32_t hab_sip_get_version(void)
return (uint32_t)res.a0;
}
+#define HABV4_EVENT_MAX_LEN 0x80
+
#define IMX8MQ_ROM_OCRAM_ADDRESS 0x9061C0
#define IMX8MM_ROM_OCRAM_ADDRESS 0x908040
#define IMX8MN_ROM_OCRAM_ADDRESS 0x908040
@@ -217,6 +219,7 @@ static enum hab_status imx8m_read_sram_events(enum hab_status status,
char *sram;
int i = 0;
int internal_index = 0;
+ uint16_t ev_len;
char *end = 0;
struct hab_event_record *search;
@@ -236,13 +239,21 @@ static enum hab_status imx8m_read_sram_events(enum hab_status status,
* recommends the address and size, however errors are usually contained
* within the first bytes. Scan only the first few bytes to rule out
* lots of false positives.
+ * The max event length is just a sanity check.
*/
- end = sram + 0x1a0;
+ end = sram + 0x1a0;
while (sram < end) {
if (*sram == 0xdb) {
search = (void *)sram;
- sram = sram + be16_to_cpu(search->hdr.len);
+ ev_len = be16_to_cpu(search->hdr.len);
+ if (ev_len > HABV4_EVENT_MAX_LEN) {
+ break;
+ }
+ sram += ev_len;
+ if (sram > end) {
+ break;
+ }
events[num_events] = search;
num_events++;
} else {
--
2.34.1
next reply other threads:[~2023-12-18 20:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-18 20:25 Christian Melki [this message]
2024-01-02 11:46 ` Sascha Hauer
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=20231218202544.3952838-1-christian.melki@t2data.com \
--to=christian.melki@t2data.com \
--cc=barebox@lists.infradead.org \
/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