Currently Cygwin does not support the High Entropy Virtual Addressing
feature, also known as IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA and
64-bit Address Space Layout Randomization in Windows.

Whereas on systems running on the x86_64 architecture this feature is
already disabled by default in the toolchain during the build process,
the AArch64 version of the toolchain leaves it enabled, even though it
is not mandatory to use it on Windows on Arm. Only the normal ASLR flag
IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE is mandatory, which this patch
does not address.

Therefore, this patch manually introduces the addition of High Entropy
VA disabling flags into several places in various Makefile.am files.
This should prevent memory overlap bugs on AArch64.

Tests fixed on AArch64:
winsup.api/ltp/fork06.exe
winsup.api/ltp/fork07.exe
winsup.api/ltp/fork11.exe

Signed-off-by: Igor Podgainoi <[email protected]>
---
 winsup/cygserver/Makefile.am | 2 +-
 winsup/cygwin/Makefile.am    | 2 +-
 winsup/testsuite/Makefile.am | 2 +-
 winsup/utils/Makefile.am     | 4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/winsup/cygserver/Makefile.am b/winsup/cygserver/Makefile.am
index efb578e53..9954ebe5d 100644
--- a/winsup/cygserver/Makefile.am
+++ b/winsup/cygserver/Makefile.am
@@ -38,7 +38,7 @@ cygserver_SOURCES = \
 
 cygserver_CXXFLAGS = $(cygserver_flags) -D__OUTSIDE_CYGWIN__
 cygserver_LDADD = -lntdll
-cygserver_LDFLAGS = -static -static-libgcc
+cygserver_LDFLAGS = -static -static-libgcc -Wl,--disable-high-entropy-va
 
 # Note: the objects in libcygserver are built without -D__OUTSIDE_CYGWIN__,
 # unlike cygserver.exe
diff --git a/winsup/cygwin/Makefile.am b/winsup/cygwin/Makefile.am
index 90a7332a8..5f5fdc5ab 100644
--- a/winsup/cygwin/Makefile.am
+++ b/winsup/cygwin/Makefile.am
@@ -620,7 +620,7 @@ $(NEW_DLL_NAME): $(LDSCRIPT) libdll.a $(VERSION_OFILES) 
$(LIBSERVER)\
        $(AM_V_CXXLD)$(CXX) $(CXXFLAGS) \
        -mno-use-libstdc-wrappers \
        -Wl,--gc-sections -nostdlib -Wl,-T$(LDSCRIPT) \
-       -Wl,--dynamicbase -static \
+       -Wl,--dynamicbase -Wl,--disable-high-entropy-va -static \
        $${SOURCE_DATE_EPOCH:+-Wl,--no-insert-timestamp} \
        -Wl,--heap=0 -Wl,--out-implib,cygdll.a -shared -o $@ \
        -e @DLL_ENTRY@ $(DEF_FILE) \
diff --git a/winsup/testsuite/Makefile.am b/winsup/testsuite/Makefile.am
index 0ff23d041..529853849 100644
--- a/winsup/testsuite/Makefile.am
+++ b/winsup/testsuite/Makefile.am
@@ -328,7 +328,7 @@ LDADD_FOR_TESTDLL = $(builddir)/../cygwin/libcygwin.a -lgcc 
-lkernel32 -luser32
 
 # flags for test executables
 AM_CPPFLAGS = -I$(srcdir)/libltp/include
-AM_LDFLAGS = $(LDFLAGS_FOR_TESTDLL)
+AM_LDFLAGS = $(LDFLAGS_FOR_TESTDLL) -Wl,--disable-high-entropy-va
 LDADD = $(builddir)/libltp.a $(builddir)/../cygwin/binmode.o 
$(LDADD_FOR_TESTDLL)
 
 # additional flags for specific test executables
diff --git a/winsup/utils/Makefile.am b/winsup/utils/Makefile.am
index 4a7936a6e..e44079a41 100644
--- a/winsup/utils/Makefile.am
+++ b/winsup/utils/Makefile.am
@@ -73,14 +73,14 @@ tzmap.h:
 
 BUILT_SOURCES = tzmap.h
 
-AM_LDFLAGS = -static -Wl,--enable-auto-import
+AM_LDFLAGS = -static -Wl,--enable-auto-import -Wl,--disable-high-entropy-va
 LDADD = -lnetapi32
 
 cygpath_CXXFLAGS = -fno-threadsafe-statics $(AM_CXXFLAGS)
 cygpath_LDADD = $(LDADD) -luserenv -lntdll
 dumper_CXXFLAGS = -I$(top_srcdir)/../include $(AM_CXXFLAGS)
 dumper_LDADD = $(LDADD) -lpsapi -lntdll -lbfd @BFD_LIBS@
-dumper_LDFLAGS =
+dumper_LDFLAGS = -Wl,--disable-high-entropy-va
 ldd_LDADD = $(LDADD) -lpsapi -lntdll
 mount_CXXFLAGS = -DFSTAB_ONLY $(AM_CXXFLAGS)
 minidumper_LDADD = $(LDADD) -ldbghelp
-- 
2.43.0

Reply via email to