public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "vries at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug gdb/31528] New: [gdb, kernel.yama.ptrace_scope=1] FAIL: gdb.base/attach-deleted-exec.exp: attach to process with deleted executable
Date: Fri, 22 Mar 2024 10:15:57 +0000	[thread overview]
Message-ID: <bug-31528-4717@http.sourceware.org/bugzilla/> (raw)

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

            Bug ID: 31528
           Summary: [gdb, kernel.yama.ptrace_scope=1] FAIL:
                    gdb.base/attach-deleted-exec.exp: attach to process
                    with deleted executable
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

When kernel.yama.ptrace_scope is set to 1, we have limited ptrace attach
capability, and run into:
...
(gdb) attach 27383^M
Attaching to process 27383^M
ptrace: Operation not permitted.^M
(gdb) FAIL: gdb.base/attach-deleted-exec.exp: attach to process with deleted
executable
...

We need to be either root or use some special commands to acquire ptrace
capability (see PR31520).

With root, we have:
...
(gdb) attach 28678^M
Attaching to process 28678^M
Reading symbols from /proc/28678/exe...^M
Reading symbols from /lib64/libm.so.6...^M
(No debugging symbols found in /lib64/libm.so.6)^M
Reading symbols from /lib64/libc.so.6...^M
(No debugging symbols found in /lib64/libc.so.6)^M
Reading symbols from /lib64/ld-linux-x86-64.so.2...^M
(No debugging symbols found in /lib64/ld-linux-x86-64.so.2)^M
0x00007fc13de420ca in clock_nanosleep@GLIBC_2.2.5 () from /lib64/libc.so.6^M
(gdb) PASS: gdb.base/attach-deleted-exec.exp: attach to process with deleted
executable
...

But with the script from PR31520, we run into:
...
(gdb) attach 29113^M
Attaching to process 29113^M
No executable file now.^M
warning: Could not load vsyscall page because no executable was specified^M
0x00007f92f00ae0ca in ?? ()^M
(gdb) FAIL: gdb.base/attach-deleted-exec.exp: attach to process with deleted
executable
...
because:
...
access("/proc/29113/exe", R_OK)         = -1 EACCES (Permission denied)
...

If we modify the code to skip the access check:
...
diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c
index b17e3120792..2b890ce1387 100644
--- a/gdb/nat/linux-procfs.c
+++ b/gdb/nat/linux-procfs.c
@@ -352,9 +352,8 @@ linux_proc_pid_to_exec_file (int pid)
   else
     buf[len] = '\0';

-  /* Use /proc/PID/exe if the actual file can't be read, but /proc/PID/exe
-     can be.  */
-  if (access (buf, R_OK) != 0 && access (name, R_OK) == 0)
+  /* Use /proc/PID/exe if the actual file can't be read.  */
+  if (access (buf, R_OK) != 0)
     strcpy (buf, name);

   return buf;
...
the test passes:
...
(gdb) attach 29927^M
Attaching to process 29927^M
Reading symbols from /proc/29927/exe...^M
Reading symbols from /lib64/libm.so.6...^M
(No debugging symbols found in /lib64/libm.so.6)^M
Reading symbols from /lib64/libc.so.6...^M
(No debugging symbols found in /lib64/libc.so.6)^M
Reading symbols from /lib64/ld-linux-x86-64.so.2...^M
(No debugging symbols found in /lib64/ld-linux-x86-64.so.2)^M
0x00007f686bb670ca in clock_nanosleep@GLIBC_2.2.5 () from /lib64/libc.so.6^M
(gdb) PASS: gdb.base/attach-deleted-exec.exp: attach to process with deleted
executable
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2024-03-22 10:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22 10:15 vries at gcc dot gnu.org [this message]
2024-03-22 14:15 ` [Bug gdb/31528] " vries at gcc dot gnu.org
2024-03-22 14:21 ` vries at gcc dot gnu.org
2024-03-22 14:26 ` vries at gcc dot gnu.org
2024-03-25 13:47 ` vries at gcc dot gnu.org
2024-03-25 13:48 ` vries at gcc dot gnu.org

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=bug-31528-4717@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@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).