* [PATCH] commands: md: don't leak heap memory with unaligned accesses
@ 2021-06-19 5:42 Ahmad Fatoum
2021-06-21 7:58 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2021-06-19 5:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Doing unaligned near file end returns bogus results:
barebox@Sandbox:/ md -s /dev/stickypage 4095
00000fff: 959ff8ff .
That 0x959ff8 is heap memory next to the buffer md had allocated.
Fix this by adding some zeroed padding after the buffer, so it instead
reads:
00000fff: 000000ff .
This is arguably better user experience.
This only applies to non-mappable fd's. For e.g. /dev/mem, unaligned
accesses will still be passed as-is.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
commands/md.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/commands/md.c b/commands/md.c
index ef6a1e1bc0b1..d80c7cca0ce4 100644
--- a/commands/md.c
+++ b/commands/md.c
@@ -59,7 +59,7 @@ static int do_mem_md(int argc, char *argv[])
goto out;
}
- buf = xmalloc(RW_BUF_SIZE);
+ buf = xzalloc(RW_BUF_SIZE + 7);
do {
now = min(size, (loff_t)RW_BUF_SIZE);
--
2.32.0.rc0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] commands: md: don't leak heap memory with unaligned accesses
2021-06-19 5:42 [PATCH] commands: md: don't leak heap memory with unaligned accesses Ahmad Fatoum
@ 2021-06-21 7:58 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2021-06-21 7:58 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Sat, Jun 19, 2021 at 07:42:17AM +0200, Ahmad Fatoum wrote:
> Doing unaligned near file end returns bogus results:
>
> barebox@Sandbox:/ md -s /dev/stickypage 4095
> 00000fff: 959ff8ff .
>
> That 0x959ff8 is heap memory next to the buffer md had allocated.
> Fix this by adding some zeroed padding after the buffer, so it instead
> reads:
>
> 00000fff: 000000ff .
>
> This is arguably better user experience.
> This only applies to non-mappable fd's. For e.g. /dev/mem, unaligned
> accesses will still be passed as-is.
>
> Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
> ---
> commands/md.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Applied, thanks
Sascha
>
> diff --git a/commands/md.c b/commands/md.c
> index ef6a1e1bc0b1..d80c7cca0ce4 100644
> --- a/commands/md.c
> +++ b/commands/md.c
> @@ -59,7 +59,7 @@ static int do_mem_md(int argc, char *argv[])
> goto out;
> }
>
> - buf = xmalloc(RW_BUF_SIZE);
> + buf = xzalloc(RW_BUF_SIZE + 7);
>
> do {
> now = min(size, (loff_t)RW_BUF_SIZE);
> --
> 2.32.0.rc0
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
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 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-06-21 7:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-19 5:42 [PATCH] commands: md: don't leak heap memory with unaligned accesses Ahmad Fatoum
2021-06-21 7:58 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox