public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "pedro at palves dot net" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug server/30453] gdbserver cannot set breakpoints when  /proc/pid/mem is not writable
Date: Tue, 16 May 2023 20:00:16 +0000	[thread overview]
Message-ID: <bug-30453-4717-VkWMKDKtuv@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-30453-4717@http.sourceware.org/bugzilla/>

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

--- Comment #4 from Pedro Alves <pedro at palves dot net> ---
So your kernel hardening has a bug, which you should fix.

Restricting /proc/pid/mem by default might make sense, but not if the thread
that opens the mem file has ptrace permissions over pid.  If the caller is
already ptracing the target process, then it already has access to all the
inferior's memory.  If you want to block ptrace, then that's a different story.

The kernel already has some connection between ptrace permissions and
/proc/pid/mem.  From man proc:

~~~
       /proc/[pid]/mem
              This file can be used to access the pages of a process's memory
through open(2), read(2), and lseek(2).

              Permission to access this file is governed by a ptrace access
mode PTRACE_MODE_ATTACH_FSCREDS check; see ptrace(2).
~~~

You would extend these checks to check whether the calling thread is a ptracer
of the target pid.  Somewhere in fs/proc/base.c:mem_open and friends.  

Actually, Mike's patch already touched exactly that code back then, doing:

 static ssize_t mem_write(struct file *file, const char __user *buf,
                         size_t count, loff_t *ppos)
 {
+#ifdef CONFIG_SECURITY_CHROMIUMOS_READONLY_PROC_SELF_MEM
+       return -EACCES;
+#else
        return mem_rw(file, (char __user*)buf, count, ppos, 1);
+#endif
 }

so you'd just tweak that -EACESS code to first check whether the caller is a
ptracer of the target, and if so, continue on with the mem_rw path.

In Mike's commit log, you've already admited "Getting this merged upstream
seems unlikely", so this is all local changes to you.

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

  parent reply	other threads:[~2023-05-16 20:00 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16 16:00 [Bug server/30453] New: " manojgupta at google dot com
2023-05-16 16:02 ` [Bug server/30453] " manojgupta at google dot com
2023-05-16 18:17 ` pedro at palves dot net
2023-05-16 18:24 ` manojgupta at google dot com
2023-05-16 20:00 ` pedro at palves dot net [this message]
2023-05-16 20:13 ` manojgupta at google dot com
2023-05-17 19:03 ` manojgupta at google dot com
2023-05-18 11:50 ` pedro at palves dot net
2024-02-15 19:06 ` adrian.ratiu at collabora dot com
2024-02-15 19:07 ` adrian.ratiu at collabora dot com
2024-02-15 19:07 ` adrian.ratiu at collabora dot com
2024-02-15 19:13 ` adrian.ratiu at collabora dot com
2024-02-15 20:09 ` pedro at palves dot net
2024-02-15 20:18 ` pedro at palves dot net
2024-02-15 20:18 ` pedro at palves dot net
2024-02-16  2:54 ` tromey at sourceware dot org
2024-02-16  5:29 ` adrian.ratiu at collabora dot com
2024-02-16  5:40 ` adrian.ratiu at collabora dot com
2024-02-16  9:47 ` adrian.ratiu at collabora dot com
2024-02-16 17:33 ` tromey at sourceware dot org
2024-02-16 17:53 ` pedro at palves dot net
2024-02-16 17:56 ` pedro at palves dot net
2024-02-16 18:10 ` adrian.ratiu at collabora dot com
2024-02-16 18:17 ` pedro at palves dot net
2024-02-16 20:53 ` mark at klomp dot org
2024-02-16 21:36 ` pedro at palves dot net
2024-02-16 21:38 ` pedro at palves dot net
2024-02-16 21:57 ` tromey at sourceware dot org
2024-02-22 13:28 ` adrian.ratiu at collabora dot com
2024-02-23 17:01 ` cvs-commit 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-30453-4717-VkWMKDKtuv@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).