From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] fixup! scripts: Add common library functions
Date: Wed, 27 Oct 2021 08:01:50 +0200 [thread overview]
Message-ID: <20211027060150.28184-1-a.fatoum@pengutronix.de> (raw)
scripts: common: mmap mutable memory in read_file_2
imx-usb-loader expects the file buffer contents to be mutable as it
will patch out references to plugin and DCD segments.
With the consolidation of the different file read helpers, the
buffer is no longer always malloc'd, but a read-only shared
mapping is attempted first and if it succeeds, imx-usb-loader
will seg fault during fixups.
As we don't want to modify the underlying file, switch to a writable
private mapping to remedy this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/common.c b/scripts/common.c
index bff08b0810c2..b780b099419c 100644
--- a/scripts/common.c
+++ b/scripts/common.c
@@ -46,7 +46,7 @@ int read_file_2(const char *filename, size_t *size, void **outbuf, size_t max_si
goto close;
}
- buf = mmap(NULL, max_size, PROT_READ, MAP_SHARED, fd, 0);
+ buf = mmap(NULL, max_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
if (buf == MAP_FAILED ) {
buf = malloc(max_size);
if (!buf) {
--
2.30.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2021-10-27 6:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-27 6:01 Ahmad Fatoum [this message]
2021-11-01 9:04 ` 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=20211027060150.28184-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--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