Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp5586907imw; Wed, 20 Jul 2022 08:26:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u8bAolnKlIpDcP5KnoHDrae2WVDvA+8DP2pdFLgrfjz8PQ/3gvJmh63KEoyAuRw3kT0U49 X-Received: by 2002:a17:907:7ba8:b0:72b:9186:5bff with SMTP id ne40-20020a1709077ba800b0072b91865bffmr36092696ejc.650.1658330809556; Wed, 20 Jul 2022 08:26:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658330809; cv=none; d=google.com; s=arc-20160816; b=YZG94FkEAYbKwYNAJmn4F6WlLXaRLurw+2OK9tL8z8Mex3/BXSlASgHQ1fySA8CFA4 E4bEUO9+oILp6AbiZSqtzDFVuQab/F5XD125V+T4TSktgHwPnDbOyqmJ5PDVaqku7uKU EJ6lmHCVCM5yC0X5762ZhVbc7ZcMFkhPIxPtFtJ2tBN9vJA04IwD/4in3J8Bl6UPa+J4 daBsSS77sWeF0Zk5FrvP0XSQbsqBqyK9rHxZK4VuPscF1n1Xj1VdSRfKZmC5+Aftlw/I +VnozycM/Z9Uuuo6Di54SgfzferjuCJKmownqYKcyiucrwBkrX0RBaW5uqZwQPlf0Syz vqOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=XSU2WUPOvF0fUCTGSGRZkl8WCZhfSChGKTGTEOsuYNI=; b=dtA+tzkrzy7DwHzyuHTFS0bosG7Yd4zNBVKpmcUYbl7SCisJi8eWpdS+PvYzAGEDJb yGSC1JXejt3bKciJpNfnUDBiYT321K98oqnfL67bXQcWVx1iFgxa8+b1Lvyj2/LamnOR OY7fr2TuMWm4dDbzm+d9244kskqEkOslaOdXjMUQ2/rXpTyx5DlAnJP+1o1IkQG3TtAj jvrhiNpSPb/B+Ecr4vMsjOtaQ07nGYuSTCzI4Rg4cDv0wRXfmmmcj3DiqXdy+xgJc6e2 QB8GpHXL7SYYwWpUUDAojpKhgFXnlYutqV33X/IxsS3XimbSwUDgmmlw5NZmWpSmpa8a QYdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=iGIpbP2d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e21-20020a17090658d500b0072f2bdf2bc6si7845617ejs.920.2022.07.20.08.26.25; Wed, 20 Jul 2022 08:26:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=iGIpbP2d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241076AbiGTO6I (ORCPT + 99 others); Wed, 20 Jul 2022 10:58:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240466AbiGTO6A (ORCPT ); Wed, 20 Jul 2022 10:58:00 -0400 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8CDA4AD55 for ; Wed, 20 Jul 2022 07:57:56 -0700 (PDT) Received: by mail-oi1-x230.google.com with SMTP id bb16so11134950oib.11 for ; Wed, 20 Jul 2022 07:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=XSU2WUPOvF0fUCTGSGRZkl8WCZhfSChGKTGTEOsuYNI=; b=iGIpbP2d3UEwVFWw5G9dZlMqJx4o8UCPvRj6piZLN7Qixwv38zIteUBoiwtf11TzoJ 8pcI1FzJmEI8s8Z8r4wNd/P56A7AMD40p0ifu6Z8wqaycmhnxl9M7kNdXzB8SXogNKD/ YVqd80JtH2cgsBKx3SUf9wdgi1qit4j7Py/II= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=XSU2WUPOvF0fUCTGSGRZkl8WCZhfSChGKTGTEOsuYNI=; b=zi78knCJ8rFZbBer3/9t2tT75+a0m1PSeetMgp1HpRHEAEzrRV/ZOBis+L3D//PF84 Q9/+6U08W4u/udK3ELBK7C627/BSOJlYoY5I6IZO7nZvh8ed/nZaRKXeciEGnnpkMAW5 4obeP9352jup3qM7Nv4/tccJjMxgDRuwqohtVZOmZRMF0JthftBoOk8uKB0cQfzdPwST V/VQwGcHfu3W39I/1cKB4T9AvjJ+EBRlTQBIJEsTyUX4yjypIm2ad6nsIF6SRpejURo+ 2w79q+1kVeHpZAEncmQg1QPoWl8ghyg/JwKfAJfUSyGNWReBxLxV7iu7gJpX7dJoEAVI DXjQ== X-Gm-Message-State: AJIora8Y1he0vrPbqXGDiyWieCmtqUkBcrIjVIb8B5c6NG/qmAYDk4A5 ytB0D2Omcn2vgMzatwV/KpKPSA== X-Received: by 2002:a05:6808:170c:b0:335:1d14:f99d with SMTP id bc12-20020a056808170c00b003351d14f99dmr2435919oib.243.1658329076048; Wed, 20 Jul 2022 07:57:56 -0700 (PDT) Received: from [192.168.0.41] ([184.4.90.121]) by smtp.gmail.com with ESMTPSA id z14-20020a9d62ce000000b0061c7a5691f2sm7425058otk.47.2022.07.20.07.57.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Jul 2022 07:57:55 -0700 (PDT) Message-ID: <42069251-3ea7-b0c7-4efb-e144c52ebf51@cloudflare.com> Date: Wed, 20 Jul 2022 09:57:53 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v2 4/4] selinux: Implement create_user_ns hook Content-Language: en-US To: Paul Moore Cc: kpsingh@kernel.org, revest@chromium.org, jackmanb@chromium.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, jmorris@namei.org, serge@hallyn.com, stephen.smalley.work@gmail.com, eparis@parisplace.org, shuah@kernel.org, brauner@kernel.org, casey@schaufler-ca.com, ebiederm@xmission.com, bpf@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, kernel-team@cloudflare.com References: <20220707223228.1940249-1-fred@cloudflare.com> <20220707223228.1940249-5-fred@cloudflare.com> From: Frederick Lawler In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/19/22 8:32 PM, Paul Moore wrote: > On Thu, Jul 7, 2022 at 6:32 PM Frederick Lawler wrote: >> >> Unprivileged user namespace creation is an intended feature to enable >> sandboxing, however this feature is often used to as an initial step to >> perform a privilege escalation attack. >> >> This patch implements a new namespace { userns_create } access control >> permission to restrict which domains allow or deny user namespace >> creation. This is necessary for system administrators to quickly protect >> their systems while waiting for vulnerability patches to be applied. >> >> This permission can be used in the following way: >> >> allow domA_t domB_t : namespace { userns_create }; >> >> Signed-off-by: Frederick Lawler >> >> --- >> Changes since v1: >> - Introduce this patch >> --- >> security/selinux/hooks.c | 9 +++++++++ >> security/selinux/include/classmap.h | 2 ++ >> 2 files changed, 11 insertions(+) >> >> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c >> index beceb89f68d9..73fbcb434fe0 100644 >> --- a/security/selinux/hooks.c >> +++ b/security/selinux/hooks.c >> @@ -4227,6 +4227,14 @@ static void selinux_task_to_inode(struct task_struct *p, >> spin_unlock(&isec->lock); >> } >> >> +static int selinux_userns_create(const struct cred *cred) >> +{ >> + u32 sid = current_sid(); >> + >> + return avc_has_perm(&selinux_state, sid, sid, SECCLASS_NAMESPACE, >> + NAMESPACE__USERNS_CREATE, NULL); >> +} > > As we continue to discuss this, I'm beginning to think that having a > dedicated object class for the userns might be a good idea. I believe > I was the one who gave you these code snippets, so feel free to blame > me for the respin ;) > No worries, I'll make this change for v3. > This is what I'm thinking: > > static int selinux_userns_create(const struct cred *cred) > { > u32 sid = current_sid(); > > return avc_has_perm(&selinux_state, sid, sid, > SECCLASS_USER_NAMESPACE, > USER_NAMESPACE__CREATE, NULL); > } > >> diff --git a/security/selinux/include/classmap.h b/security/selinux/include/classmap.h >> index ff757ae5f253..9943e85c6b3e 100644 >> --- a/security/selinux/include/classmap.h >> +++ b/security/selinux/include/classmap.h >> @@ -254,6 +254,8 @@ const struct security_class_mapping secclass_map[] = { >> { COMMON_FILE_PERMS, NULL } }, >> { "io_uring", >> { "override_creds", "sqpoll", NULL } }, >> + { "namespace", >> + { "userns_create", NULL } }, > > The above would need to change to: > > { "user_namespace", > { "create", NULL } } >