mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master v2 1/2] hab: habv4: use explicitly unsigned types for pointers into SRAM
@ 2024-01-11 13:00 Ahmad Fatoum
  2024-01-11 13:00 ` [PATCH master v2 2/2] hab: habv4: warn if more than 10 HAB events are found Ahmad Fatoum
  2024-01-11 15:15 ` [PATCH master v2 1/2] hab: habv4: use explicitly unsigned types for pointers into SRAM Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-01-11 13:00 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

char is generally unsigned on ARM, but we shouldn't rely on that. HAB
code does though and compare a char against 0xdb, which would never
succeed if chars were signed. Switch to an explicitly unsigned type to
fix this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - no change
---
 drivers/hab/habv4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hab/habv4.c b/drivers/hab/habv4.c
index 974158fd0c01..4db1e7cc0f3a 100644
--- a/drivers/hab/habv4.c
+++ b/drivers/hab/habv4.c
@@ -216,11 +216,11 @@ static enum hab_status imx8m_read_sram_events(enum hab_status status,
 {
 	struct hab_event_record *events[10];
 	int num_events = 0;
-	char *sram;
+	u8 *sram;
 	int i = 0;
 	int internal_index = 0;
 	uint16_t ev_len;
-	char *end = 0;
+	u8 *end = 0;
 	struct hab_event_record *search;
 
 	if (cpu_is_mx8mq())
-- 
2.39.2




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

* [PATCH master v2 2/2] hab: habv4: warn if more than 10 HAB events are found
  2024-01-11 13:00 [PATCH master v2 1/2] hab: habv4: use explicitly unsigned types for pointers into SRAM Ahmad Fatoum
@ 2024-01-11 13:00 ` Ahmad Fatoum
  2024-01-11 15:15 ` [PATCH master v2 1/2] hab: habv4: use explicitly unsigned types for pointers into SRAM Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-01-11 13:00 UTC (permalink / raw)
  To: barebox; +Cc: Christian Melki, Ahmad Fatoum

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>
---
v1 -> v2:
  - keep first 10 events found
---
 drivers/hab/habv4.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/hab/habv4.c b/drivers/hab/habv4.c
index 4db1e7cc0f3a..ed6d4db77c16 100644
--- a/drivers/hab/habv4.c
+++ b/drivers/hab/habv4.c
@@ -254,6 +254,11 @@ static enum hab_status imx8m_read_sram_events(enum hab_status status,
 			if (sram > end)
 				break;
 
+			if (num_events == ARRAY_SIZE(events)) {
+				pr_warn("Discarding excess event\n");
+				continue;
+			}
+
 			events[num_events] = search;
 			num_events++;
 		} else {
-- 
2.39.2




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

* Re: [PATCH master v2 1/2] hab: habv4: use explicitly unsigned types for pointers into SRAM
  2024-01-11 13:00 [PATCH master v2 1/2] hab: habv4: use explicitly unsigned types for pointers into SRAM Ahmad Fatoum
  2024-01-11 13:00 ` [PATCH master v2 2/2] hab: habv4: warn if more than 10 HAB events are found Ahmad Fatoum
@ 2024-01-11 15:15 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-01-11 15:15 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Thu, 11 Jan 2024 14:00:14 +0100, Ahmad Fatoum wrote:
> char is generally unsigned on ARM, but we shouldn't rely on that. HAB
> code does though and compare a char against 0xdb, which would never
> succeed if chars were signed. Switch to an explicitly unsigned type to
> fix this.
> 
> 

Applied, thanks!

[1/2] hab: habv4: use explicitly unsigned types for pointers into SRAM
      https://git.pengutronix.de/cgit/barebox/commit/?id=225368d37470 (link may not be stable)
[2/2] hab: habv4: warn if more than 10 HAB events are found
      https://git.pengutronix.de/cgit/barebox/commit/?id=f90d6e70bce6 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

end of thread, other threads:[~2024-01-11 15:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-11 13:00 [PATCH master v2 1/2] hab: habv4: use explicitly unsigned types for pointers into SRAM Ahmad Fatoum
2024-01-11 13:00 ` [PATCH master v2 2/2] hab: habv4: warn if more than 10 HAB events are found Ahmad Fatoum
2024-01-11 15:15 ` [PATCH master v2 1/2] hab: habv4: use explicitly unsigned types for pointers into SRAM Sascha Hauer

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