From patchwork Mon Jan 9 18:12:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 9505707 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2A43560710 for ; Mon, 9 Jan 2017 18:12:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A4A0284F6 for ; Mon, 9 Jan 2017 18:12:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C512284F9; Mon, 9 Jan 2017 18:12:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCFB9284F6 for ; Mon, 9 Jan 2017 18:12:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935638AbdAISMc (ORCPT ); Mon, 9 Jan 2017 13:12:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35886 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932317AbdAISMb (ORCPT ); Mon, 9 Jan 2017 13:12:31 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E6D39C05678C; Mon, 9 Jan 2017 18:12:29 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com ([10.34.27.30]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id v09ICPUa010235; Mon, 9 Jan 2017 13:12:26 -0500 Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Mon, 9 Jan 2017 19:12:29 +0100 (CET) Date: Mon, 9 Jan 2017 19:12:25 +0100 From: Oleg Nesterov To: yangshukui Cc: selinux@tycho.nsa.gov, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Kefeng Wang , "Guohanjun (Hanjun Guo)" , "'Qiang Huang'" , Lizefan , "miaoxie (A)" , Zhangdianfang , paul@paul-moore.com, sds@tycho.nsa.gov, eparis@parisplace.org, james.l.morris@oracle.com, ebiederm@xmission.com, serge.hallyn@ubuntu.com Subject: Re: SELinux lead to soft lockup when pid 1 proceess reap child Message-ID: <20170109181225.GB8972@redhat.com> References: <58732BCF.4090908@huawei.com> <58734284.1060504@huawei.com> <58736B2E.90201@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <58736B2E.90201@huawei.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 09 Jan 2017 18:12:30 +0000 (UTC) Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP On 01/09, yangshukui wrote: > > --- 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; this check is not really correct, it can be a sub-thread... Doesn't matter, please see below. > + } > 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? I never understood why security_task_wait() should deny to reap a child. But since it can we probably want some explicit "the whole namespace goes away" check. We could use, say, PIDNS_HASH_ADDING but I'd suggest something like a trivial change below for now. Eric, what do you think? Oleg. --- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/security/security.c b/security/security.c index f825304..1330b4e 100644 --- a/security/security.c +++ b/security/security.c @@ -1027,6 +1027,9 @@ int security_task_kill(struct task_struct *p, struct siginfo *info, int security_task_wait(struct task_struct *p) { + /* must be the exiting child reaper */ + if (unlikely(current->flags & PF_EXITING)) + return 0; return call_int_hook(task_wait, 0, p); }