All of lore.kernel.org
 help / color / mirror / Atom feed
From: yangshukui <yangshukui@huawei.com>
To: <selinux@tycho.nsa.gov>, <linux-security-module@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>,
	"Guohanjun (Hanjun Guo)" <guohanjun@huawei.com>,
	"'Qiang Huang'" <h.huangqiang@huawei.com>,
	Lizefan <lizefan@huawei.com>, "miaoxie (A)" <miaoxie@huawei.com>,
	Zhangdianfang <zhangdianfang@huawei.com>, <paul@paul-moore.com>,
	<sds@tycho.nsa.gov>, <eparis@parisplace.org>,
	<james.l.morris@oracle.com>, <oleg@redhat.com>,
	<ebiederm@xmission.com>, <serge.hallyn@ubuntu.com>
Subject: SELinux lead to soft lockup when pid 1 proceess reap child
Date: Mon, 9 Jan 2017 18:51:26 +0800	[thread overview]
Message-ID: <58736B2E.90201@huawei.com> (raw)
In-Reply-To: <b7f75f65-592a-5102-0ac5-4d3aa43f0b55@huawei.com>

[-- Attachment #1: Type: text/plain, Size: 2686 bytes --]

Pid 1 process (with init_t)  have the right to reap child in host, but 
pid 1 process (such as spc_t, docker use spc_t as container's default type)
may not have the right to reap child in container, if this condition 
occur, it will lead to soft lock up. The following will produce it,

docker run -ti --rm -v /sys/fs/selinux:/sys/fs/selinux fedora:20 bash
[root@b755018fb526 /]# yum install selinux-policy-targeted 
selinux-policy-devel perl-Test-Harness gcc libselinux-devel net-tools 
netlabel_tools iptables git cpan
[root@b755018fb526 /]# git clone 
https://github.com/SELinuxProject/selinux-testsuite.git
[root@b755018fb526 /]# setenforce 0
[root@b755018fb526 /]# runcon -t unconfined_t bash
[root@b755018fb526 /]# genhomedircon
[root@b755018fb526 /]# restorecon -R /
[root@b755018fb526 /]# setenforce 1
[root@b755018fb526 /]# cd /root/selinux-testsuite/
[root@b755018fb526 selinux-testsuite]# make -C policy load
[root@b755018fb526 selinux-testsuite]# make -C tests test
[root@b755018fb526 selinux-testsuite]# exit  #this will lead to soft lockup

before exiting the container, we can also see some zombies:
[root@b755018fb526 selinux-testsuite]# ps -eafZ
LABEL                           UID        PID  PPID  C STIME 
TTY          TIME CMD
...
unconfined_u:unconfined_r:test_fdreceive_server_t:s0 root 215 1  0 05:35 
pts/0 00:00:00 [server] <defunct>
unconfined_u:unconfined_r:test_ptrace_traced_t:s0 root 291 1  0 05:35 
pts/0 00:00:00 [wait] <defunct>
unconfined_u:unconfined_r:test_setnice_set_t:s0 root 374 1  0 05:35 
pts/0 00:00:00 [child] <defunct>

in kernel code,
zap_pid_ns_processes {
       ...
       /* Firstly reap the EXIT_ZOMBIE children we may have. */
       do {
           clear_thread_flag(TIF_SIGPENDING);
           rc = sys_wait4(-1, NULL, __WALL, NULL);
           //sys_wait4 -> do_wait-> 
wait_consider_task->security_task_wait->selinux_task_wait->avc_has_perm_flags->avc_has_perm_noaudit->avc_denied
the return value is -EACCES, unable to return to the expected -ECHILD, 
and leading to the dead cycle.
     } while (rc != -ECHILD);
}

I have a hack like this,
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 57a2020..c10c58c 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3596,6 +3596,9 @@ static int selinux_task_kill(struct task_struct 
*p, struct siginfo *info,

  static int selinux_task_wait(struct task_struct *p)
  {
+       if (pid_vnr(task_tgid(current)) == 1){
+                return 0;
+       }
         return task_has_perm(p, current, PROCESS__SIGCHLD);
  }
It work but it permit pid 1 process to reap child without selinux check. 
Can we have a better way to handle this problem?

[-- Attachment #2: Type: text/html, Size: 3877 bytes --]

       reply	other threads:[~2017-01-09 10:51 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <58732BCF.4090908@huawei.com>
     [not found] ` <58734284.1060504@huawei.com>
     [not found]   ` <b7f75f65-592a-5102-0ac5-4d3aa43f0b55@huawei.com>
2017-01-09 10:51     ` yangshukui [this message]
2017-01-09 18:12       ` SELinux lead to soft lockup when pid 1 proceess reap child Oleg Nesterov
2017-01-09 18:29         ` Oleg Nesterov
2017-01-09 18:43           ` Stephen Smalley
2017-01-09 23:49             ` Paul Moore
2017-01-10  0:26             ` Casey Schaufler
2017-03-09  9:03       ` isolate selinux_enforcing yangshukui
2017-03-09  9:03         ` yangshukui
2017-03-09 15:28         ` Stephen Smalley
2017-03-09 15:28           ` Stephen Smalley
2017-03-09 15:39           ` Stephen Smalley
2017-03-09 15:39             ` Stephen Smalley
2017-03-09 16:39         ` Casey Schaufler
2017-03-09 16:39           ` Casey Schaufler
2017-03-09 20:49           ` Eric W. Biederman
2017-03-09 20:49             ` Eric W. Biederman
2017-03-10  0:05             ` Paul Moore
2017-03-10  0:05               ` Paul Moore
2017-03-13  7:06             ` James Morris
2017-03-13  7:06               ` James Morris
2017-03-13 16:05               ` Casey Schaufler
2017-03-13 16:05                 ` Casey Schaufler

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=58736B2E.90201@huawei.com \
    --to=yangshukui@huawei.com \
    --cc=ebiederm@xmission.com \
    --cc=eparis@parisplace.org \
    --cc=guohanjun@huawei.com \
    --cc=h.huangqiang@huawei.com \
    --cc=james.l.morris@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=miaoxie@huawei.com \
    --cc=oleg@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@tycho.nsa.gov \
    --cc=serge.hallyn@ubuntu.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=zhangdianfang@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.