From: Kevin Buettner <kevinb@redhat.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: Re: [PATCH] Allocate buffer with proper size in amd64_pseudo_register_{read_value,write}
Date: Sun, 21 Oct 2018 21:43:00 -0000 [thread overview]
Message-ID: <20181021144305.4abb6e16@pinnacle.lan> (raw)
In-Reply-To: <20181021025948.24787-1-simon.marchi@polymtl.ca>
On Sat, 20 Oct 2018 22:59:48 -0400
Simon Marchi <simon.marchi@polymtl.ca> wrote:
> Running "maintenance selftest" on an amd64 build with AddressSanitizer
> enabled, I get this:
>
> ==18126==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffdf72397c1 at pc 0x7fb5f437b011 bp 0x7ffdf7239740 sp 0x7ffdf7238ee8
> WRITE of size 8 at 0x7ffdf72397c1 thread T0
> #0 0x7fb5f437b010 in __interceptor_memcpy /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:737
> #1 0x55a1f899c1b3 in readable_regcache::raw_read(int, unsigned char*) /home/simark/src/binutils-gdb/gdb/regcache.c:530
> #2 0x55a1f7db241b in amd64_pseudo_register_read_value /home/simark/src/binutils-gdb/gdb/amd64-tdep.c:384
> #3 0x55a1f8413a2e in gdbarch_pseudo_register_read_value(gdbarch*, readable_regcache*, int) /home/simark/src/binutils-gdb/gdb/gdbarch.c:1992
> #4 0x55a1f899c9d1 in readable_regcache::cooked_read(int, unsigned char*) /home/simark/src/binutils-gdb/gdb/regcache.c:636
> #5 0x55a1f89a2251 in cooked_read_test /home/simark/src/binutils-gdb/gdb/regcache.c:1649
>
> In amd64_pseudo_register_read_value, when we try to read the al
> register, for example, we need to read rax and extract al from it. We
> allocate a buffer of the size of al (1 byte):
>
> gdb_byte *raw_buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
>
> but read in it the whole rax value (8 bytes):
>
> status = regcache->raw_read (gpnum, raw_buf);
>
> Fix it by allocating a buffer correctly sized for the full register from
> which the smaller register is extracted. The
> amd64_pseudo_register_write function had the same problem.
>
> gdb/ChangeLog:
>
> * amd64-tdep.c (amd64_pseudo_register_read_value): Use
> correctly-sized buffer with raw_read.
> (amd64_pseudo_register_write): Use correctly-sized buffer for
> raw_read/raw_write.
Okay.
Kevin
next prev parent reply other threads:[~2018-10-21 21:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-21 2:59 Simon Marchi
2018-10-21 21:43 ` Kevin Buettner [this message]
2018-10-22 2:11 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181021144305.4abb6e16@pinnacle.lan \
--to=kevinb@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox