-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Bugfix for strace, and CAP_SETPCAP, in the case that filesystem capabilities are supported. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (GNU/Linux) iD8DBQFIY1fr+bHCR3gb8jsRAph7AKDOlmeveIpQs1jhIs0TJxjCdMAS5ACgsml6 7UYR+FZpW2XdmG8PkiZzemU= =+Ko+ -----END PGP SIGNATURE-----
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 ...I don't understand where that last sentence comes from. Why would it That sounds reasonable on its own, but it opens up a dangerous ability for the partially-privileged tracer to manipulate the capability set for the traced task. Note that (as of recently) we do not allow the execution of a file with partial privileges in its pE', precisely because it is dangerous to allow pick-and-choosing of capabilities in a capability-unaware binary. So frankly I wonder whether the existing downgrade is really safe... --
It seems I missed a bit out. It should've read: I guess that means that if you're tracing a binary that has CAP_SETPCAP already, and whose filecaps say that it wants CAP_SETPCAP, then it retains CAP_SETPCAP. If the debugger has CAP_SYS_PTRACE, then it can attach to a binary that has Does it, though? It would only reduce the capabilities of the inferior process; it wouldn't allow the inferior process or the debugger to get additional capabilities, apart from what's available under CAP_SETPCAP. David --
And the uids won't change unless capable(CAP_SETUID)... so I think you're right, it does sound safe. thanks, -serge --
Calling it cap_limit_ptraced_target() would probably be better. David --
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
David Howells wrote:
| Andrew G. Morgan <morgan@kernel.org> wrote:
|
|> +static inline int cap_limit_straced_target(void) { return 1; }
|
| Calling it cap_limit_ptraced_target() would probably be better.
You are right. Fix-up patch attached.
Cheers
Andrew
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
iD8DBQFIaHH8+bHCR3gb8jsRAgKHAJ4uu7Xd6PZObvIwzvJPSA6lGBpY1QCfUb20
bw1vY5cX8qW7UBMel6qgi5I=
=iacs
-----END PGP SIGNATURE-----
Acked-by: David Howells <dhowells@redhat.com> --
| Greg KH | Og dreams of kernels |
| Jens Axboe | [PATCH 31/33] Fusion: sg chaining support |
| Arnd Bergmann | Re: finding your own dead "CONFIG_" variables |
| Mark Brown | [PATCH 2/2] Subject: natsemi: Allow users to disable workaround for DspCfg reset |
| Tony Breeds | [LGUEST] Look in object dir for .config |
git: | |
| Brian Downing | Re: Git in a Nutshell guide |
| John Benes | Re: master has some toys |
| Matthias Lederhofer | [PATCH 4/7] introduce GIT_WORK_TREE to specify the work tree |
| Alexander Sulfrian | [RFC/PATCH] RE: git calls SSH_ASKPASS even if DISPLAY is not set |
| Junio C Hamano | Re: Rss produced by git is not valid xml? |
| Linux Kernel Mailing List | iSeries: fix section mismatch in iseries_veth |
