Skip to contentSkip to conversation

mkimage: fix segfault on MacOS arm64

PATCH Superseded Sergey V. Lobanov 2 participants 4 messages Jan 16, 2022 – Jan 24, 2022

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mkimage: fix segfault on MacOS arm64

mkimage segfaults due ASLR mechasim on MacOS arm64

It is required to use _dyld_get_image_vmaddr_slide() to prevent segfault on MacOS arm64

This patch ased on the discussion
https://github.com/u-boot/u-boot/commit/3b142045e8a7f0ab17b6099e9226296af45967d0

Thanks to Ronny Kotzschmar and ptpt52 github user

---
 tools/imagetool.h | 2 ++
 1 file changed, 2 insertions(+)
tools/imagetool.h +2 -0
index e229a34ffc..a0985d93d2 100644
@@ -271,11 +271,13 @@ int rockchip_copy_image(int fd, struct image_tool_params *mparams);
  *  b) we need a API call to get the respective section symbols */
 #if defined(__MACH__)
 #include <mach-o/getsect.h>
+#include <mach-o/dyld.h>
 
 #define INIT_SECTION(name)  do {					\
 		unsigned long name ## _len;				\
 		char *__cat(pstart_, name) = getsectdata("__DATA",	\
 			#name, &__cat(name, _len));			\
+		__cat(pstart_, name) += _dyld_get_image_vmaddr_slide(0);\
 		char *__cat(pstop_, name) = __cat(pstart_, name) +	\
 			__cat(name, _len);				\
 		__cat(__start_, name) = (void *)__cat(pstart_, name);	\
Signature · 1 line
2.32.0 (Apple Git-132)
#1 lore raw
CC Jessica Clarke
Quoted 38 lines · Sergey V. Lobanov

mkimage segfaults due ASLR mechasim on MacOS arm64

It is required to use _dyld_get_image_vmaddr_slide() to prevent segfault on MacOS arm64

This patch ased on the discussion
https://github.com/u-boot/u-boot/commit/3b142045e8a7f0ab17b6099e9226296af45967d0

Thanks to Ronny Kotzschmar and ptpt52 github user

---
tools/imagetool.h | 2 ++

1 file changed, 2 insertions(+)
tools/imagetool.h +2 -0
index e229a34ffc..a0985d93d2 100644
@@ -271,11 +271,13 @@ int rockchip_copy_image(int fd, struct image_tool_params *mparams);
 *  b) we need a API call to get the respective section symbols */
 #if defined(__MACH__)
 #include <mach-o/getsect.h>
+#include <mach-o/dyld.h>
 
 #define INIT_SECTION(name)  do {					\
 		unsigned long name ## _len;				\
 		char *__cat(pstart_, name) = getsectdata("__DATA",	\
 			#name, &__cat(name, _len));			\
+		__cat(pstart_, name) += _dyld_get_image_vmaddr_slide(0);\
 		char *__cat(pstop_, name) = __cat(pstart_, name) +	\
 			__cat(name, _len);				\
 		__cat(__start_, name) = (void *)__cat(pstart_, name);	\
Signature · 1 line
2.32.0 (Apple Git-132)
Reviewed-by on v2 1/1
#2 lore raw
In reply to Sergey V. Lobanov
Quoted 23 lines · Sergey V. Lobanov

mkimage segfaults due ASLR mechasim on MacOS arm64

It is required to use _dyld_get_image_vmaddr_slide() to prevent segfault on MacOS arm64

This patch ased on the discussion
https://github.com/u-boot/u-boot/commit/3b142045e8a7f0ab17b6099e9226296af45967d0

Thanks to Ronny Kotzschmar and ptpt52 github user

---
 tools/imagetool.h | 2 ++
 1 file changed, 2 insertions(+)
tools/imagetool.h +0 -0
index e229a34ffc..a0985d93d2 100644
@@ -271,11 +271,13 @@ int rockchip_copy_image(int fd, struct image_tool_params *mparams);
  *  b) we need a API call to get the respective section symbols */
 #if defined(__MACH__)
 #include <mach-o/getsect.h>

tools/imagetool.h int rockchip_copy_image(int fd, struct image_tool_params *mparams); · line 283

Quoted 10 lines
tools/imagetool.h +2 -0
+#include <mach-o/dyld.h>
 
 #define INIT_SECTION(name)  do {					\
 		unsigned long name ## _len;				\
 		char *__cat(pstart_, name) = getsectdata("__DATA",	\
 			#name, &__cat(name, _len));			\
+		__cat(pstart_, name) += _dyld_get_image_vmaddr_slide(0);\
 		char *__cat(pstop_, name) = __cat(pstart_, name) +	\
 			__cat(name, _len);				\
 		__cat(__start_, name) = (void *)__cat(pstart_, name);	\

This now seems sensible to me, thanks for fixing my mess.

(though you may want to clean up your commit message; "ased" is missing the leading b and you're still missing the verb "is", plus "mechasim" should be "mechanism" and it should be "due to the", not just "due")

Jess

#3 lore raw

Thank you, Jessica.

I have rebased on current master, added Reviewed-by tag, fixed grammar/typos and sent v3

Quoted 46 lines · Jessica Clarke
Quoted 23 lines · Sergey V. Lobanov

mkimage segfaults due ASLR mechasim on MacOS arm64

It is required to use _dyld_get_image_vmaddr_slide() to prevent segfault on MacOS arm64

This patch ased on the discussion
https://github.com/u-boot/u-boot/commit/3b142045e8a7f0ab17b6099e9226296af45967d0

Thanks to Ronny Kotzschmar and ptpt52 github user

---
tools/imagetool.h | 2 ++

1 file changed, 2 insertions(+)
tools/imagetool.h +0 -0
index e229a34ffc..a0985d93d2 100644
@@ -271,11 +271,13 @@ int rockchip_copy_image(int fd, struct image_tool_params *mparams);
 *  b) we need a API call to get the respective section symbols */
 #if defined(__MACH__)
 #include <mach-o/getsect.h>

tools/imagetool.h int rockchip_copy_image(int fd, struct image_tool_params *mparams); · line 283

Quoted 10 lines
tools/imagetool.h +2 -0
+#include <mach-o/dyld.h>
 
 #define INIT_SECTION(name)  do {					\
 		unsigned long name ## _len;				\
 		char *__cat(pstart_, name) = getsectdata("__DATA",	\
 			#name, &__cat(name, _len));			\
+		__cat(pstart_, name) += _dyld_get_image_vmaddr_slide(0);\
 		char *__cat(pstop_, name) = __cat(pstart_, name) +	\
 			__cat(name, _len);				\
 		__cat(__start_, name) = (void *)__cat(pstart_, name);	\

This now seems sensible to me, thanks for fixing my mess.

(though you may want to clean up your commit message; "ased" is missing the leading b and you're still missing the verb "is", plus "mechasim" should be "mechanism" and it should be "due to the", not just "due")

Jess