Subject: Re: Is there an API to remove ALSR in Cygwin 3.4.0?
From: Corinna Vinschen <[email-masked]>
To: [email-masked]
Cc: Christian Jullien <[email-masked]>
Date: Sat, 12 Nov 2022 15:50:28 +0100
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>

On Nov 12 12:28, Christian Jullien wrote:
> Hello Cygwin team,
> 
>  
> 
> First, I would like to thank you for your efforts on Cygwin all of these
> years.
> 
>  
> 
> I'm asking if there will be an API to remove ASLR with an API as on Linux:

Please note that, for the time being, ASLR will only be enabled on the
Cygwin DLL itself.  All other DLLs as well as the Cygwin executables are
still non-ASLRed.  We're looking into introducing ASLR step by step.

Right now the Cygwin toolchain creates non-ASLRed EXEs and DLLs by
default.  This is supposed to change in a while.  Also, we might change
the auto-rebase mechanism (basically the script running as post-install
script when setup-x86_64 finishes up) to enable ASLR on DLLs.  EXEs are
not so important from my POV, but as soon as we tweaked the toolchain,
more and more EXEs will be ASLRed automagically as well.

One thing we can only use partially, because it's bound to break
Cygwin's fork and exec, is High Entropy ASLR.  Naturally, this would
only work for executables which never fork or exec other processes.

Having said that, there's no API for this yet in Cygwin.  There is an
API in Windows to control (among others) the ASLR setting of a process
at creation time, see
https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-updateprocthreadattribute
settings called

  PROCESS_CREATION_MITIGATION_POLICY_BOTTOM_UP_ASLR_ALWAYS_ON
  PROCESS_CREATION_MITIGATION_POLICY_BOTTOM_UP_ASLR_ALWAYS_OFF

and

  PROCESS_CREATION_MITIGATION_POLICY_HIGH_ENTROPY_ASLR_ALWAYS_ON
  PROCESS_CREATION_MITIGATION_POLICY_HIGH_ENTROPY_ASLR_ALWAYS_OFF

However, we don't have an API for that, yet. We could add it to Cygwin
at one point.  I'd prefer the Linux-personality call, too, but funny
enough, ADDR_NO_RANDOMIZE would be the only flag we could support.

What we *do* have already is the peflags tool from the rebase package:

  $ peflags -d0 -e0 foo.exe

This example would disable ASLR on the foo.exe executable.  Maybe that's
a workaround for the time being.

Corinna

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple