public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 0/2] [gdb] Fix segfault in for_each_block
Date: Sat,  4 Nov 2023 16:57:55 +0100	[thread overview]
Message-ID: <20231104155757.16649-1-tdevries@suse.de> (raw)

This patch series fixes PR gdb/30547, a segfault when running test-case
gdb.base/vfork-follow-parent.exp on powerpc64 (likewise on s390x).

There are two patches, each of them by themselves sufficient to no longer
trigger the segfault.

The root cause of the problem is that linux_is_uclinux, and consequently
gdbarch_has_shared_address_space returns an incorrect value.

The first patch makes gdb more robust against gdbarch_has_shared_address_space
returning incorrect values, by eliminating a call to it.

The second patch addresses the root cause.

Tested on top of trunk on x86_64-linux and ppc64le-linux.
Tested on top of gdb-14-branch on ppc64-linux.

[ I used gdb-14-branch for ppc64-linux, because I can't build trunk anymore
with system gcc 4.8.5 (CentOS-7), due to the recent c++17 requirement (and
just before that, some gcc bug in atomic support), and that's all I have
readily available on that machine. ]

There is still scope to fix things further.

When I started to investigate, I noticed that I only ran into the segfault on
ppc64 and s390x, two big-endian architectures, so I sort of expected to find an
endian-related problem.

Instead, the problem was ppc_linux_target_wordsize returning 4 instead of 8,
which causes gdb to interpret the 8-byte entry auxv vector using 4-byte
words, causing an incorrect linux_is_uclinux == true.

The same problem happens on ppc64le (ppc_linux_target_wordsize returns 4),
it's just that the incorrect word size doesn't change the outcome of:
- target_auxv_search (AT_NULL, &dummy) == 1, and
- target_auxv_search (AT_PAGESZ, &dummy) == 1
so linux_is_uclinux returns false, as it should.

This suggest a too forgiving parsing of the auxv vector, which should be made
more strict.

Finally, it should be fixed that ppc_linux_target_wordsize returns 4 in a
process with wordsize == 8.

I added an assert that PTRACE_PEEKUSER doesn't fail (errno != 0) and ran into
it in test-case gdb.base/access-mem-running.exp, during trying to "set a
breakpoint while the process is running".  It's clear that it's quite common
for this to happen, and it's surprising that this doesn't cause more problems.

I'll eventually file PRs for these two issues, for now my interest is to
backport at least one, possibly both patches from this series to fix this PR
on the gdb 14 release branch (and the 13.2 based distro packages I maintain).

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30547

Tom de Vries (2):
  [gdb] Fix segfault in for_each_block, part 1
  [gdb] Fix segfault in for_each_block, part 2

 gdb/infrun.c    | 12 +++++++++++-
 gdb/progspace.c | 37 +++++++++++++++++++++++++++----------
 gdb/progspace.h | 11 ++++++++++-
 3 files changed, 48 insertions(+), 12 deletions(-)


base-commit: de2efa143e3652d69c278dd1eb10a856593917c0
-- 
2.35.3


             reply	other threads:[~2023-11-04 15:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-04 15:57 Tom de Vries [this message]
2023-11-04 15:57 ` [PATCH 1/2] [gdb] Fix segfault in for_each_block, part 1 Tom de Vries
2023-11-06 15:24   ` Andrew Burgess
2023-11-07 13:28     ` Tom de Vries
2023-11-06 17:05   ` Simon Marchi
2023-11-07 11:16     ` Andrew Burgess
2023-11-07 13:32     ` Tom de Vries
2023-11-04 15:57 ` [PATCH 2/2] [gdb] Fix segfault in for_each_block, part 2 Tom de Vries

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=20231104155757.16649-1-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).