Commit 39fd33933b0209e4b6254743f2cede07c5ad4c52

Authored by Serge E. Hallyn
Committed by Linus Torvalds
1 parent bb96a6f50b

userns: allow killing tasks in your own or child userns

Changelog:
	Dec  8: Fixed bug in my check_kill_permission pointed out by
	        Eric Biederman.
	Dec 13: Apply Eric's suggestion to pass target task into kill_ok_by_cred()
	        for clarity
	Dec 31: address comment by Eric Biederman:
		don't need cred/tcred in check_kill_permission.
	Jan  1: use const cred struct.
	Jan 11: Per Bastian Blank's advice, clean up kill_ok_by_cred().
	Feb 16: kill_ok_by_cred: fix bad parentheses
	Feb 23: per akpm, let compiler inline kill_ok_by_cred

Signed-off-by: Serge E. Hallyn <serge.hallyn@canonical.com>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Acked-by: Daniel Lezcano <daniel.lezcano@free.fr>
Acked-by: David Howells <dhowells@redhat.com>
Cc: James Morris <jmorris@namei.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 22 additions and 8 deletions Side-by-side Diff

... ... @@ -636,13 +636,33 @@
636 636 }
637 637  
638 638 /*
  639 + * called with RCU read lock from check_kill_permission()
  640 + */
  641 +static int kill_ok_by_cred(struct task_struct *t)
  642 +{
  643 + const struct cred *cred = current_cred();
  644 + const struct cred *tcred = __task_cred(t);
  645 +
  646 + if (cred->user->user_ns == tcred->user->user_ns &&
  647 + (cred->euid == tcred->suid ||
  648 + cred->euid == tcred->uid ||
  649 + cred->uid == tcred->suid ||
  650 + cred->uid == tcred->uid))
  651 + return 1;
  652 +
  653 + if (ns_capable(tcred->user->user_ns, CAP_KILL))
  654 + return 1;
  655 +
  656 + return 0;
  657 +}
  658 +
  659 +/*
639 660 * Bad permissions for sending the signal
640 661 * - the caller must hold the RCU read lock
641 662 */
642 663 static int check_kill_permission(int sig, struct siginfo *info,
643 664 struct task_struct *t)
644 665 {
645   - const struct cred *cred, *tcred;
646 666 struct pid *sid;
647 667 int error;
648 668  
649 669  
... ... @@ -656,14 +676,8 @@
656 676 if (error)
657 677 return error;
658 678  
659   - cred = current_cred();
660   - tcred = __task_cred(t);
661 679 if (!same_thread_group(current, t) &&
662   - (cred->euid ^ tcred->suid) &&
663   - (cred->euid ^ tcred->uid) &&
664   - (cred->uid ^ tcred->suid) &&
665   - (cred->uid ^ tcred->uid) &&
666   - !capable(CAP_KILL)) {
  680 + !kill_ok_by_cred(t)) {
667 681 switch (sig) {
668 682 case SIGCONT:
669 683 sid = task_session(t);