mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] regulator: bcm2835: register only on Raspberry Pi
@ 2026-01-12  8:56 Ahmad Fatoum
  2026-01-12  8:56 ` [PATCH 2/3] commands: md: fix OOB read when mmapping Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2026-01-12  8:56 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The device was registered whenever the driver was compiled, including in
multi-platform builds. Guard behind raspberrypi,bcm2835-firmware, until
this is turned into a "real" driver one day.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/regulator/bcm2835.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/bcm2835.c b/drivers/regulator/bcm2835.c
index fa9fc47207b4..9d2803baca24 100644
--- a/drivers/regulator/bcm2835.c
+++ b/drivers/regulator/bcm2835.c
@@ -138,8 +138,10 @@ postcore_platform_driver(regulator_bcm2835_driver);
 
 static int regulator_bcm2835_init(void)
 {
-	add_generic_device("regulator-bcm2835", DEVICE_ID_SINGLE, NULL,
-			   0, 0, 0, NULL);
+	if (of_get_compatible_child(of_get_root_node(),
+				    "raspberrypi,bcm2835-firmware"))
+		add_generic_device("regulator-bcm2835", DEVICE_ID_SINGLE, NULL,
+				   0, 0, 0, NULL);
 
 	return 0;
 }
-- 
2.47.3




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

* [PATCH 2/3] commands: md: fix OOB read when mmapping
  2026-01-12  8:56 [PATCH 1/3] regulator: bcm2835: register only on Raspberry Pi Ahmad Fatoum
@ 2026-01-12  8:56 ` Ahmad Fatoum
  2026-01-13 13:05   ` Sascha Hauer
  2026-01-12  8:56 ` [PATCH 3/3] pbl: decomp: report errors on PBL console as well Ahmad Fatoum
  2026-01-13 13:09 ` (subset) [PATCH 1/3] regulator: bcm2835: register only on Raspberry Pi Sascha Hauer
  2 siblings, 1 reply; 6+ messages in thread
From: Ahmad Fatoum @ 2026-01-12  8:56 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

md -s /dev/mmappable.device will read out-of-bounds if the byte count to
read exceeds the device size.

Limit the size read from the memmap to fix this.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 commands/md.c    | 4 ++++
 common/ratp/md.c | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/commands/md.c b/commands/md.c
index f3758f571fb2..401538d4d8be 100644
--- a/commands/md.c
+++ b/commands/md.c
@@ -25,6 +25,7 @@ static int do_mem_md(int argc, char *argv[])
 	loff_t	start = 0, size = 0x100;
 	int	r, now;
 	int	ret = 0;
+	struct stat st;
 	int fd;
 	char *filename = "/dev/mem";
 	int mode = O_RWSIZE_4;
@@ -54,6 +55,9 @@ static int do_mem_md(int argc, char *argv[])
 		return 1;
 	}
 
+	if (!fstat(fd, &st) && st.st_size != FILE_SIZE_STREAM)
+		size = min(size, st.st_size);
+
 	map = memmap(fd, PROT_READ);
 	if (map != MAP_FAILED) {
 		ret = memory_display(map + start, start, size,
diff --git a/common/ratp/md.c b/common/ratp/md.c
index 8221afaebc22..f3302dedafb7 100644
--- a/common/ratp/md.c
+++ b/common/ratp/md.c
@@ -61,6 +61,7 @@ static int do_ratp_mem_md(const char *filename,
 			  loff_t size,
 			  uint8_t *output)
 {
+	struct stat st;
 	int r, now, t;
 	int ret = 0;
 	int fd;
@@ -73,6 +74,9 @@ static int do_ratp_mem_md(const char *filename,
 		return -errno;
 	}
 
+	if (!fstat(fd, &st) && st.st_size != FILE_SIZE_STREAM)
+		size = min(size, st.st_size);
+
 	map = memmap(fd, PROT_READ);
 	if (map != MAP_FAILED) {
 		memcpy(output, (uint8_t *)(map + start), size);
-- 
2.47.3




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

* [PATCH 3/3] pbl: decomp: report errors on PBL console as well
  2026-01-12  8:56 [PATCH 1/3] regulator: bcm2835: register only on Raspberry Pi Ahmad Fatoum
  2026-01-12  8:56 ` [PATCH 2/3] commands: md: fix OOB read when mmapping Ahmad Fatoum
@ 2026-01-12  8:56 ` Ahmad Fatoum
  2026-01-13 13:09 ` (subset) [PATCH 1/3] regulator: bcm2835: register only on Raspberry Pi Sascha Hauer
  2 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2026-01-12  8:56 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Decompression errors without DEBUG_LL shouldn't result in a silent hang
when CONFIG_PBL_CONSOLE is enabled.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 include/pbl.h | 5 +++++
 pbl/decomp.c  | 8 ++++----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/include/pbl.h b/include/pbl.h
index b330010562c4..063cd15cf0ea 100644
--- a/include/pbl.h
+++ b/include/pbl.h
@@ -34,5 +34,10 @@ int pbl_barebox_verify(const void *compressed_start, unsigned int len,
 
 void __noreturn barebox_pbl_entry(ulong, ulong, void *);
 
+#ifdef CONFIG_PBL_CONSOLE
+#define pbl_puts	puts
+#else
+#define pbl_puts	puts_ll
+#endif
 
 #endif /* __PBL_H__ */
diff --git a/pbl/decomp.c b/pbl/decomp.c
index ebdf81ddfbe5..c314f4901a48 100644
--- a/pbl/decomp.c
+++ b/pbl/decomp.c
@@ -45,10 +45,10 @@ STATIC int decompress(u8 *input, int in_len,
 
 static void noinline errorfn(char *error)
 {
-	puts_ll("ERROR: ");
-	puts_ll(error);
-	puts_ll("\nHANG\n");
-	while (1);
+	pbl_puts("ERROR: ");
+	pbl_puts(error);
+	pbl_puts("\nHANG\n");
+	__hang();
 }
 
 extern unsigned char sha_sum[];
-- 
2.47.3




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

* Re: [PATCH 2/3] commands: md: fix OOB read when mmapping
  2026-01-12  8:56 ` [PATCH 2/3] commands: md: fix OOB read when mmapping Ahmad Fatoum
@ 2026-01-13 13:05   ` Sascha Hauer
  2026-01-13 13:08     ` Ahmad Fatoum
  0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2026-01-13 13:05 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Jan 12, 2026 at 09:56:05AM +0100, Ahmad Fatoum wrote:
> md -s /dev/mmappable.device will read out-of-bounds if the byte count to
> read exceeds the device size.
> 
> Limit the size read from the memmap to fix this.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
> ---
>  commands/md.c    | 4 ++++
>  common/ratp/md.c | 4 ++++
>  2 files changed, 8 insertions(+)
> 
> diff --git a/commands/md.c b/commands/md.c
> index f3758f571fb2..401538d4d8be 100644
> --- a/commands/md.c
> +++ b/commands/md.c
> @@ -25,6 +25,7 @@ static int do_mem_md(int argc, char *argv[])
>  	loff_t	start = 0, size = 0x100;
>  	int	r, now;
>  	int	ret = 0;
> +	struct stat st;
>  	int fd;
>  	char *filename = "/dev/mem";
>  	int mode = O_RWSIZE_4;
> @@ -54,6 +55,9 @@ static int do_mem_md(int argc, char *argv[])
>  		return 1;
>  	}
>  
> +	if (!fstat(fd, &st) && st.st_size != FILE_SIZE_STREAM)
> +		size = min(size, st.st_size);

This should take start into account.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

* Re: [PATCH 2/3] commands: md: fix OOB read when mmapping
  2026-01-13 13:05   ` Sascha Hauer
@ 2026-01-13 13:08     ` Ahmad Fatoum
  0 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2026-01-13 13:08 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox



On 1/13/26 2:05 PM, Sascha Hauer wrote:
> On Mon, Jan 12, 2026 at 09:56:05AM +0100, Ahmad Fatoum wrote:
>> md -s /dev/mmappable.device will read out-of-bounds if the byte count to
>> read exceeds the device size.
>>
>> Limit the size read from the memmap to fix this.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
>> ---
>>  commands/md.c    | 4 ++++
>>  common/ratp/md.c | 4 ++++
>>  2 files changed, 8 insertions(+)
>>
>> diff --git a/commands/md.c b/commands/md.c
>> index f3758f571fb2..401538d4d8be 100644
>> --- a/commands/md.c
>> +++ b/commands/md.c
>> @@ -25,6 +25,7 @@ static int do_mem_md(int argc, char *argv[])
>>  	loff_t	start = 0, size = 0x100;
>>  	int	r, now;
>>  	int	ret = 0;
>> +	struct stat st;
>>  	int fd;
>>  	char *filename = "/dev/mem";
>>  	int mode = O_RWSIZE_4;
>> @@ -54,6 +55,9 @@ static int do_mem_md(int argc, char *argv[])
>>  		return 1;
>>  	}
>>  
>> +	if (!fstat(fd, &st) && st.st_size != FILE_SIZE_STREAM)
>> +		size = min(size, st.st_size);
> 
> This should take start into account.

I will resend a v2 of this one patch. Feel free to pick the others if
you are ok with them.

> 
> Sascha
> 




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

* Re: (subset) [PATCH 1/3] regulator: bcm2835: register only on Raspberry Pi
  2026-01-12  8:56 [PATCH 1/3] regulator: bcm2835: register only on Raspberry Pi Ahmad Fatoum
  2026-01-12  8:56 ` [PATCH 2/3] commands: md: fix OOB read when mmapping Ahmad Fatoum
  2026-01-12  8:56 ` [PATCH 3/3] pbl: decomp: report errors on PBL console as well Ahmad Fatoum
@ 2026-01-13 13:09 ` Sascha Hauer
  2 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2026-01-13 13:09 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 12 Jan 2026 09:56:04 +0100, Ahmad Fatoum wrote:
> The device was registered whenever the driver was compiled, including in
> multi-platform builds. Guard behind raspberrypi,bcm2835-firmware, until
> this is turned into a "real" driver one day.
> 
> 

Applied, thanks!

[1/3] regulator: bcm2835: register only on Raspberry Pi
      https://git.pengutronix.de/cgit/barebox/commit/?id=3ee4d8927379 (link may not be stable)
[3/3] pbl: decomp: report errors on PBL console as well
      https://git.pengutronix.de/cgit/barebox/commit/?id=43efac5d6c79 (link may not be stable)

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




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

end of thread, other threads:[~2026-01-13 13:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-12  8:56 [PATCH 1/3] regulator: bcm2835: register only on Raspberry Pi Ahmad Fatoum
2026-01-12  8:56 ` [PATCH 2/3] commands: md: fix OOB read when mmapping Ahmad Fatoum
2026-01-13 13:05   ` Sascha Hauer
2026-01-13 13:08     ` Ahmad Fatoum
2026-01-12  8:56 ` [PATCH 3/3] pbl: decomp: report errors on PBL console as well Ahmad Fatoum
2026-01-13 13:09 ` (subset) [PATCH 1/3] regulator: bcm2835: register only on Raspberry Pi Sascha Hauer

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