linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Alejandro Colomar (man-pages)" <alx.manpages@gmail.com>
To: Jann Horn <jann@thejh.net>
Cc: Pavel Emelyanov <xemul@openvz.org>,
	Oleg Nesterov <oleg@tv-sign.ru>,
	Andrew Morton <akpm@linux-foundation.org>,
	Michael Kerrisk <mtk.manpages@gmail.com>,
	Kees Cook <keescook@chromium.org>,
	Ted Estes <ted@softwarecrafters.com>,
	linux-man <linux-man@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Jann Horn <jannh@google.com>
Subject: Re: [Bug 210655] ptrace.2: documentation is incorrect about access checking threads in same thread group
Date: Wed, 16 Dec 2020 00:25:13 +0100	[thread overview]
Message-ID: <d38c5e8b-1653-d89a-a0c8-b95cb1844fba@gmail.com> (raw)
In-Reply-To: <0e5189c0-9e9b-ac34-825c-619a9a6ef682@gmail.com>



On 12/16/20 12:23 AM, Alejandro Colomar (man-pages) wrote:
> Hi Jann,
> 
> On 12/16/20 12:07 AM, Jann Horn wrote:
>> Am Tue, Dec 15, 2020 at 06:01:25PM +0100 schrieb Alejandro Colomar (man-pages):
>>> Hi,
>>>
>>> There's a bug report: https://bugzilla.kernel.org/show_bug.cgi?id=210655
>>>
>>> [[
>>> Under "Ptrace access mode checking", the documentation states:
>>>   "1. If the calling thread and the target thread are in the same thread
>>> group, access is always allowed."
>>>
>>> This is incorrect. A thread may never attach to another in the same group.
>>
>> No, that is correct. ptrace-mode access checks do always short-circuit for
>> tasks in the same thread group:
>>
>> /* Returns 0 on success, -errno on denial. */
>> static int __ptrace_may_access(struct task_struct *task, unsigned int mode)
>> {
>> [...]
>>         /* May we inspect the given task?
>>          * This check is used both for attaching with ptrace
>>          * and for allowing access to sensitive information in /proc.
>>          *
>>          * ptrace_attach denies several cases that /proc allows
>>          * because setting up the necessary parent/child relationship
>>          * or halting the specified task is impossible.
>>          */
>>
>>         /* Don't let security modules deny introspection */
>>         if (same_thread_group(task, current))
>>                 return 0;
>> [...]
>> }
> 
> AFAICS, that code always returns non-zero,

Sorry, I should have said "that code never returns 0".

> at least when called from ptrace_attach().
> 
> As you can see below,
> __ptrace_may_access() is called some lines after
> the code pointed to by the bug report.
> 
> 
> static int ptrace_attach(struct task_struct *task, long request,
> 			 unsigned long addr,
> 			 unsigned long flags)
> {
> [...]
> 	if (same_thread_group(task, current))
> 		goto out;
> 
> 	/*
> 	 * Protect exec's credential calculations against our interference;
> 	 * SUID, SGID and LSM creds get determined differently
> 	 * under ptrace.
> 	 */
> 	retval = -ERESTARTNOINTR;
> 	if (mutex_lock_interruptible(&task->signal->cred_guard_mutex))
> 		goto out;
> 
> 	task_lock(task);
> 	retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH_REALCREDS);
> [...]
> }
> 
> 
> Thanks,
> 
> Alex
> 
>>
>> As the comment explains, you can't actually *attach*
>> to another task in the same thread group; but that's
>> not because of the ptrace-style access check rules,
>> but because specifically *attaching* to another task
>> in the same thread group doesn't work.
>>

  reply	other threads:[~2020-12-16  0:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-15 17:01 [Bug 210655] ptrace.2: documentation is incorrect about access checking threads in same thread group Alejandro Colomar (man-pages)
2020-12-15 18:31 ` Ted Estes
2020-12-15 18:34   ` Alejandro Colomar (man-pages)
2020-12-15 22:48     ` Alejandro Colomar (man-pages)
2020-12-16  0:55       ` Linus Torvalds
2020-12-16  7:34         ` Oleg Nesterov
2020-12-15 23:07 ` Jann Horn
2020-12-15 23:23   ` Alejandro Colomar (man-pages)
2020-12-15 23:25     ` Alejandro Colomar (man-pages) [this message]
2020-12-16  0:01       ` Jann Horn
2020-12-16  2:21         ` Ted Estes
2020-12-16  2:33           ` Jann Horn
2020-12-16  9:22             ` Alejandro Colomar (man-pages)
2020-12-17 18:45               ` Eric W. Biederman

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=d38c5e8b-1653-d89a-a0c8-b95cb1844fba@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=jann@thejh.net \
    --cc=jannh@google.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    --cc=oleg@tv-sign.ru \
    --cc=ted@softwarecrafters.com \
    --cc=xemul@openvz.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 NNTP newsgroup(s).