Re: [PATCH 3/3] Cygwin: Add loaded module base address list to stackdump

2022-11-03 Thread Jon Turney

On 29/10/2022 09:32, Corinna Vinschen wrote:

On Oct 28 16:05, Jon Turney wrote:

This adds an extra section to the stackdump, which lists the loaded
modules and their base address.  This is perhaps useful as it makes it
immediately clear if RandomCrashInjectedDll.dll is loaded...

XXX: It seems like the 'InMemoryOrder' part of 'InMemoryOrderModuleList' is a 
lie?


Probably just an alternative fact...


Yeah.  I did stared a bit at the code wondering if the structure layouts 
were incorrect so we were somehow traversing one of the other module 
lists with a different ordering, but everything looks correct.


The attached might be a good idea, then, to ensure that module+offset is 
calculated correctly.
From ea47826047e8bb175b1b0e0286d7d7b8cf15c7fe Mon Sep 17 00:00:00 2001
From: Jon Turney 
Date: Tue, 1 Nov 2022 14:01:08 +
Subject: [PATCH] Cygwin: Handle out of order modules for module offsets in
 stackdump

Improve address to module+offset conversion, to work correctly in the
presence of out-of-order elements in InMemoryOrderModuleList.

Fixes: d59651d4
---
 winsup/cygwin/exceptions.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index 8cc454c90..c3433ab94 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -342,11 +342,13 @@ prettyprint_va (PVOID func_va)
 {
   PLDR_DATA_TABLE_ENTRY mod = CONTAINING_RECORD (x, LDR_DATA_TABLE_ENTRY,
 InMemoryOrderLinks);
-  if (mod->DllBase > func_va)
+  if ((func_va < mod->DllBase) ||
+ (func_va > (PVOID)((DWORD_PTR)mod->DllBase + mod->SizeOfImage)))
continue;
 
   __small_sprintf (buf, "%S+0x%x", &mod->BaseDllName,
   (DWORD_PTR)func_va - (DWORD_PTR)mod->DllBase);
+  break;
 }
 
   return buf;
-- 
2.38.1



[PATCH] Cygwin: Improve FAQ on early breakpoint for ASLR

2022-11-03 Thread Jon Turney
gdb supports 'set disable-randomization off' on Windows since [1]
(included in gdb 13).

https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=bcb9251f029da8dcf360a4f5acfa3b4211c87bb0;hp=8fea1a81c7d9279a6f91e49ebacfb61e0f8ce008
---
 winsup/doc/faq-programming.xml | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/winsup/doc/faq-programming.xml b/winsup/doc/faq-programming.xml
index 7945b6b88..41cd5e423 100644
--- a/winsup/doc/faq-programming.xml
+++ b/winsup/doc/faq-programming.xml
@@ -844,6 +844,12 @@ Guide here: https://cygwin.com/cygwin-ug-net/dll.html"/>.
   Note that the DllMain entrypoints for linked DLLs will have been executed
   before this breakpoint is hit.
 
+
+
+  (It may be necessary to use the gdb command set
+  disable-randomization off to turn off ASLR for the debugee to
+  prevent the base address getting randomized.)
+
 
 
 
-- 
2.38.1



Re: [PATCH] Cygwin: Improve FAQ on early breakpoint for ASLR

2022-11-03 Thread Jeremy Drake via Cygwin-patches
On Thu, 3 Nov 2022, Jon Turney wrote:

> gdb supports 'set disable-randomization off' on Windows since [1]
> (included in gdb 13).
>
> https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=bcb9251f029da8dcf360a4f5acfa3b4211c87bb0;hp=8fea1a81c7d9279a6f91e49ebacfb61e0f8ce008

Is it really *disable*-randomization *off*?  The double-negative seems to
suggest that in that case ASLR would be left *on*.