From: David Howells <dhowells@redhat.com>
To: "Serge E. Hallyn" <serue@us.ibm.com>,
"Andrew G. Morgan" <morgan@kernel.org>
Cc: dhowells@redhat.com, Andrew Morton <akpm@linux-foundation.org>,
Linux Security Modules List
<linux-security-module@vger.kernel.org>,
lkml <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/4] security: filesystem capabilities bugfix2
Date: Mon, 30 Jun 2008 15:53:24 +0100 [thread overview]
Message-ID: <7852.1214837604@redhat.com> (raw)
In-Reply-To: <20080627205905.GB17415@us.ibm.com>
Serge E. Hallyn <serue@us.ibm.com> wrote:
> If I understand this right, then LSM_UNSAFE_PTRACE_CAP will only be set
> if the tracer didn't have CAP_SYS_PTRACE. So this seems sane to me.
Erm... Firstly:
int ptrace_attach(struct task_struct *task)
{
...
if (capable(CAP_SYS_PTRACE))
task->ptrace |= PT_PTRACE_CAP;
...
}
Then:
static int unsafe_exec(struct task_struct *p)
{
int unsafe = 0;
if (p->ptrace & PT_PTRACED) {
if (p->ptrace & PT_PTRACE_CAP)
unsafe |= LSM_UNSAFE_PTRACE_CAP;
else
unsafe |= LSM_UNSAFE_PTRACE;
}
if (atomic_read(&p->fs->count) > 1 ||
atomic_read(&p->files->count) > 1 ||
atomic_read(&p->sighand->count) > 1)
unsafe |= LSM_UNSAFE_SHARE;
return unsafe;
}
So LSM_UNSAFE_PTRACE_CAP will only be set if the tracer _does_ have
CAP_SYS_PTRACE. That will be irrelevant, however, if any of fs, files or
sighand are shared.
And finally:
void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
{
...
if (bprm->e_uid != current->uid ||
bprm->e_gid != current->gid ||
!cap_issubset (new_permitted, current->cap_permitted)) {
...
if (unsafe & ~LSM_UNSAFE_PTRACE_CAP) {
if (!capable(CAP_SETUID)) {
bprm->e_uid = current->uid;
bprm->e_gid = current->gid;
}
if (!capable (CAP_SETPCAP)) {
new_permitted = cap_intersect(
new_permitted,
current->cap_permitted);
}
}
...
}
So if it's a 'set-privilege' binary, then if the tracer _doesn't_ have
CAP_SYS_PTRACE, we look at downgrading the privileges of the process.
Without Andrew's patch, we only downgrade the capabilities if we don't have
CAP_SETPCAP (and aren't sharing inheritables).
With Andrew's patch, capabilities are downgraded regardless of whether we have
CAP_SETPCAP or not. I guess that means that if you're tracing a binary whose
filecaps say that it wants CAP_SETPCAP, then it retains CAP_SETPCAP.
I wonder if the tracing task should be examined here, and any capability the
tracer isn't permitted should be denied the process doing the exec.
Anyway, in my commoncap.c prettification patch, I've dressed the limiter
function up as follows:
/*
* Determine whether a exec'ing process's new permitted capabilities
* should be limited to just what it already has.
*
* This prevents processes that are being ptraced from gaining access
* to CAP_SETPCAP, unless the process they're tracing already has it,
* and the binary they're executing has filecaps that elevate it.
*
* Returns 1 if they should be limited, 0 if they are not.
*/
static inline int cap_limit_ptraced_target(void)
{
#ifndef CONFIG_SECURITY_FILE_CAPABILITIES
if (capable(CAP_SETPCAP))
return 0;
#endif
return 1;
}
David
next prev parent reply other threads:[~2008-06-30 14:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-26 8:48 [PATCH 2/4] security: filesystem capabilities bugfix2 Andrew G. Morgan
2008-06-27 20:59 ` Serge E. Hallyn
2008-06-30 14:53 ` David Howells [this message]
2008-06-30 18:53 ` Serge E. Hallyn
2008-06-30 19:10 ` David Howells
2008-06-30 19:49 ` Serge E. Hallyn
2008-06-27 23:04 ` David Howells
2008-06-30 5:41 ` Andrew G. Morgan
2008-06-30 9:45 ` David Howells
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=7852.1214837604@redhat.com \
--to=dhowells@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=morgan@kernel.org \
--cc=serue@us.ibm.com \
/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