From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <ahmad@a3f.at>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] commands: md: don't leak heap memory with unaligned accesses
Date: Mon, 21 Jun 2021 09:58:09 +0200 [thread overview]
Message-ID: <20210621075809.GP9782@pengutronix.de> (raw)
In-Reply-To: <20210619054217.499815-1-ahmad@a3f.at>
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
prev parent reply other threads:[~2021-06-21 7:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 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=20210621075809.GP9782@pengutronix.de \
--to=sha@pengutronix.de \
--cc=ahmad@a3f.at \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.