Received: by 10.192.165.156 with SMTP id m28csp1567891imm; Wed, 18 Apr 2018 11:46:59 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+qtphm2BJmJ+zTSGg315zRCR/m3J4lBj3vV4OqAHwch2M0ndZHCVobYP1mxzwwFpYwlXsr X-Received: by 10.99.109.134 with SMTP id i128mr2652021pgc.59.1524077219769; Wed, 18 Apr 2018 11:46:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524077219; cv=none; d=google.com; s=arc-20160816; b=wHDAMND+qY7NckmyHVJ4JX0FH4TxxrBKqHDtnf/8ufipF8vFBf1g2m0MxKXaemQyT0 ubI4ezXdrAYjmVpvAcs5T1vc8Sk0RK4+HpGavXiDiPyIBU6LaSy0+wt6hz5wE+WdF15m YwGpQvoIc8fU2NfffLtXi06wPF8qGgBdQilPZ79So9jaXu1AKsje2omUT8DXGUFOQIny VeEYh7ca9UfumEZgWRm4y9Lv/vy/w0aiymHwkGel+Bs3G7QhlCHeK9yAsGHLUBkh0BQE HWVQx7bZoty83gpR9v8T+tkNxpg8PfAMgvQqVsvBc9J1soBBHJb6c1oje6N/a5OHNuoC b3Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:from:cc:references:to :subject:arc-authentication-results; bh=Agd7uaG4Wyu32wcHNOTWgXntzEIO6sF8asNKL9naP4s=; b=I12H0NuNQlnlrZMaYaY9L1C/U1hCyRLNkHmyMNcpYEwcfFC0qnfngMY/KRdALRZLM5 lxO20g+e0PXxtRlkmztShas6cg5Vfmgz6ZLYTek0YSjov3ngpuCJvOzYAZkE56uAZKD8 MMwhy54tcUxPfE3rImJbzY5+nNG1jSAPrskqZftPY47wjQw7PZUeOLWWYxSKZEizpmGP DdiL6PG811C4t0kWLDIWP0bUuJvR6DrrWFMn7n0wg7nRTXQE1xfSkQRe4fsDlPxmYx0/ 9Kg5yP4wJslOTzIve2lcf8vxgOVBXj0bJpP/6OVuv5snOc0eBDnqf3ZaL4BFqm0BbUk8 e8nQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q21-v6si1760438pls.3.2018.04.18.11.46.44; Wed, 18 Apr 2018 11:46:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752712AbeDRSpc (ORCPT + 99 others); Wed, 18 Apr 2018 14:45:32 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:40014 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752617AbeDRSpZ (ORCPT ); Wed, 18 Apr 2018 14:45:25 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3IIinec046536 for ; Wed, 18 Apr 2018 14:45:24 -0400 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0a-001b2d01.pphosted.com with ESMTP id 2he9p9dakw-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Wed, 18 Apr 2018 14:45:24 -0400 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 18 Apr 2018 12:45:23 -0600 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 18 Apr 2018 12:45:17 -0600 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3IIjGqt5243246; Wed, 18 Apr 2018 11:45:16 -0700 Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B128A6E03A; Wed, 18 Apr 2018 12:45:16 -0600 (MDT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP id 37ACB6E044; Wed, 18 Apr 2018 12:45:15 -0600 (MDT) Subject: Re: [RFC PATCH V1 01/12] audit: add container id To: Richard Guy Briggs References: <2e5d93ee46feca915a101c2fc3062da674a98223.1519930146.git.rgb@redhat.com> <216d1ab1-531b-9185-2e31-34f162f08aad@linux.vnet.ibm.com> <20180316035837.ddnqvbyrbp3fdk7e@madcap2.tricolour.ca> Cc: cgroups@vger.kernel.org, containers@lists.linux-foundation.org, linux-api@vger.kernel.org, Linux-Audit Mailing List , linux-fsdevel@vger.kernel.org, LKML , netdev@vger.kernel.org, mszeredi@redhat.com, luto@kernel.org, jlayton@redhat.com, carlos@redhat.com, viro@zeniv.linux.org.uk, dhowells@redhat.com, simo@redhat.com, trondmy@primarydata.com, eparis@parisplace.org, serge@hallyn.com, ebiederm@xmission.com, madzcar@gmail.com From: Stefan Berger Date: Wed, 18 Apr 2018 14:45:14 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20180316035837.ddnqvbyrbp3fdk7e@madcap2.tricolour.ca> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 18041818-0028-0000-0000-000009770F10 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008878; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000257; SDB=6.01019812; UDB=6.00520300; IPR=6.00799054; MB=3.00020646; MTD=3.00000008; XFM=3.00000015; UTC=2018-04-18 18:45:21 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041818-0029-0000-0000-00003A6E568B Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-18_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804180167 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/15/2018 11:58 PM, Richard Guy Briggs wrote: > On 2018-03-15 16:27, Stefan Berger wrote: >> On 03/01/2018 02:41 PM, Richard Guy Briggs wrote: >>> Implement the proc fs write to set the audit container ID of a process, >>> emitting an AUDIT_CONTAINER record to document the event. >>> >>> This is a write from the container orchestrator task to a proc entry of >>> the form /proc/PID/containerid where PID is the process ID of the newly >>> created task that is to become the first task in a container, or an >>> additional task added to a container. >>> >>> The write expects up to a u64 value (unset: 18446744073709551615). >>> >>> This will produce a record such as this: >>> type=UNKNOWN[1333] msg=audit(1519903238.968:261): op=set pid=596 uid=0 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 auid=0 tty=pts0 ses=1 opid=596 old-contid=18446744073709551615 contid=123455 res=0 >>> >>> The "op" field indicates an initial set. The "pid" to "ses" fields are >>> the orchestrator while the "opid" field is the object's PID, the process >>> being "contained". Old and new container ID values are given in the >>> "contid" fields, while res indicates its success. >>> >>> It is not permitted to self-set, unset or re-set the container ID. A >>> child inherits its parent's container ID, but then can be set only once >>> after. >>> >>> See: https://github.com/linux-audit/audit-kernel/issues/32 >>> >>> >>> /* audit_rule_data supports filter rules with both integer and string >>> * fields. It corresponds with AUDIT_ADD_RULE, AUDIT_DEL_RULE and >>> diff --git a/kernel/auditsc.c b/kernel/auditsc.c >>> index 4e0a4ac..0ee1e59 100644 >>> --- a/kernel/auditsc.c >>> +++ b/kernel/auditsc.c >>> @@ -2073,6 +2073,92 @@ int audit_set_loginuid(kuid_t loginuid) >>> return rc; >>> } >>> >>> +static int audit_set_containerid_perm(struct task_struct *task, u64 containerid) >>> +{ >>> + struct task_struct *parent; >>> + u64 pcontainerid, ccontainerid; >>> + pid_t ppid; >>> + >>> + /* Don't allow to set our own containerid */ >>> + if (current == task) >>> + return -EPERM; >>> + /* Don't allow the containerid to be unset */ >>> + if (!cid_valid(containerid)) >>> + return -EINVAL; >>> + /* if we don't have caps, reject */ >>> + if (!capable(CAP_AUDIT_CONTROL)) >>> + return -EPERM; >>> + /* if containerid is unset, allow */ >>> + if (!audit_containerid_set(task)) >>> + return 0; >> I am wondering whether there should be a check for the target process that >> will receive the containerid to not have CAP_SYS_ADMIN that would otherwise >> allow it to arbitrarily unshare()/clone() and leave the set of namespaces >> that may make up the container whose containerid we assign here? > This is a reasonable question. This has been debated and I understood > the conclusion was that without a clear definition of a "container", the > task still remains in that container that just now has more > sub-namespaces (in the case of hierarchical namespaces), we don't want > to restrict it in such a way and that allows it to create nested > containers. I see setns being more problematic if it could switch to > another existing namespace that was set up by the orchestrator for a > different container. The coming v2 patchset acknowledges this situation > with the network namespace being potentially shared by multiple > containers. Are you going to post v2 soon? We would like to build on top of it for IMA namespacing and auditing inside of IMA namespaces. Stefan