mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <ahmad@a3f.at>
Subject: [PATCH] commands: md: don't leak heap memory with unaligned accesses
Date: Sat, 19 Jun 2021 07:42:17 +0200	[thread overview]
Message-ID: <20210619054217.499815-1-ahmad@a3f.at> (raw)

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


             reply	other threads:[~2021-06-19  5:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-19  5:42 Ahmad Fatoum [this message]
2021-06-21  7:58 ` 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=20210619054217.499815-1-ahmad@a3f.at \
    --to=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox