Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Fix size of register buffer
       [not found] <20241028175239.314-1-ssbssa.ref@yahoo.de>
@ 2024-10-28 17:52 ` Hannes Domani
  2024-10-28 19:44   ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Hannes Domani @ 2024-10-28 17:52 UTC (permalink / raw)
  To: gdb-patches

When calling a function with double arguments, I get this asan error:

==7920==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x0053131ece38 at pc 0x7ff79697a68f bp 0x0053131ec790 sp 0x0053131ebf40
READ of size 16 at 0x0053131ece38 thread T0
    #0 0x7ff79697a68e in MemcmpInterceptorCommon(void*, int (*)(void const*, void const*, unsigned long long), void const*, void const*, unsigned long long) C:/gcc/src/gcc-14.2.0/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:814
    #1 0x7ff79697aebd in memcmp C:/gcc/src/gcc-14.2.0/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:845
    #2 0x7ff79697aebd in memcmp C:/gcc/src/gcc-14.2.0/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:840
    #3 0x7ff7927e237f in regcache::raw_write(int, gdb::array_view<unsigned char const>) C:/gdb/src/gdb.git/gdb/regcache.c:874
    #4 0x7ff7927e3c85 in regcache::cooked_write(int, gdb::array_view<unsigned char const>) C:/gdb/src/gdb.git/gdb/regcache.c:914
    #5 0x7ff7927e5d89 in regcache::cooked_write(int, unsigned char const*) C:/gdb/src/gdb.git/gdb/regcache.c:933
    #6 0x7ff7911d5965 in amd64_windows_store_arg_in_reg C:/gdb/src/gdb.git/gdb/amd64-windows-tdep.c:216

Address 0x0053131ece38 is located in stack of thread T0 at offset 40 in frame
    #0 0x7ff7911d565f in amd64_windows_store_arg_in_reg C:/gdb/src/gdb.git/gdb/amd64-windows-tdep.c:208

  This frame has 4 object(s):
    [32, 40) 'buf' (line 211) <== Memory access at offset 40 overflows this variable

It's because the first 4 double arguments are passed via XMM registers,
and they need a buffer of 16 bytes, even if we only use 8 bytes of them.
---
 gdb/amd64-windows-tdep.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
index 555e225219d..70390fcaf22 100644
--- a/gdb/amd64-windows-tdep.c
+++ b/gdb/amd64-windows-tdep.c
@@ -208,7 +208,8 @@ amd64_windows_store_arg_in_reg (struct regcache *regcache,
 {
   struct type *type = arg->type ();
   const gdb_byte *valbuf = arg->contents ().data ();
-  gdb_byte buf[8];
+  /* We only set 8 bytes, buf if it's a XMM register, 16 bytes are read.  */
+  gdb_byte buf[16];
 
   gdb_assert (type->length () <= 8);
   memset (buf, 0, sizeof buf);
-- 
2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix size of register buffer
  2024-10-28 17:52 ` [PATCH] Fix size of register buffer Hannes Domani
@ 2024-10-28 19:44   ` Tom Tromey
  2024-10-28 20:02     ` Hannes Domani
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2024-10-28 19:44 UTC (permalink / raw)
  To: Hannes Domani; +Cc: gdb-patches

>>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:

Hannes> It's because the first 4 double arguments are passed via XMM registers,
Hannes> and they need a buffer of 16 bytes, even if we only use 8 bytes of them.

Thanks, this is ok.
Approved-By: Tom Tromey <tom@tromey.com>

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix size of register buffer
  2024-10-28 19:44   ` Tom Tromey
@ 2024-10-28 20:02     ` Hannes Domani
  2024-10-29 11:55       ` Tom de Vries
  0 siblings, 1 reply; 4+ messages in thread
From: Hannes Domani @ 2024-10-28 20:02 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

 Am Montag, 28. Oktober 2024 um 20:44:32 MEZ hat Tom Tromey <tom@tromey.com> Folgendes geschrieben:

> >>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:
>
> Hannes> It's because the first 4 double arguments are passed via XMM registers,
> Hannes> and they need a buffer of 16 bytes, even if we only use 8 bytes of them.

Pushed, thanks.


Hannes

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix size of register buffer
  2024-10-28 20:02     ` Hannes Domani
@ 2024-10-29 11:55       ` Tom de Vries
  0 siblings, 0 replies; 4+ messages in thread
From: Tom de Vries @ 2024-10-29 11:55 UTC (permalink / raw)
  To: Hannes Domani, Tom Tromey; +Cc: gdb-patches

On 10/28/24 21:02, Hannes Domani wrote:
>   Am Montag, 28. Oktober 2024 um 20:44:32 MEZ hat Tom Tromey <tom@tromey.com> Folgendes geschrieben:
> 
>>>>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:
>>
>> Hannes> It's because the first 4 double arguments are passed via XMM registers,
>> Hannes> and they need a buffer of 16 bytes, even if we only use 8 bytes of them.
> 
> Pushed, thanks.

Hi Hannes,

I had a question about what we could do to detect this problem without 
address sanitizer, and ended up writing a patch ( 
https://sourceware.org/pipermail/gdb-patches/2024-October/212723.html ) 
which unfortunately I cannot test.

It would be great if you or anybody else with a windows setup could test 
that patch.

Thanks,
- Tom


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-10-30  8:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20241028175239.314-1-ssbssa.ref@yahoo.de>
2024-10-28 17:52 ` [PATCH] Fix size of register buffer Hannes Domani
2024-10-28 19:44   ` Tom Tromey
2024-10-28 20:02     ` Hannes Domani
2024-10-29 11:55       ` Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox