[PATCH] fixup! scripts: Add common library functions
Ahmad Fatoum
a.fatoum at pengutronix.de
Tue Oct 26 23:01:50 PDT 2021
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 at 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
More information about the barebox
mailing list