Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4254086imw; Thu, 7 Jul 2022 15:39:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ubcmQP+EORzKXCNyabBrgc8BZzjMAUNi7C7uBNg8q5mGPGt8SjP2AqGF6/IpUQAqEDZV8K X-Received: by 2002:aa7:dcd5:0:b0:43a:70f7:8e4d with SMTP id w21-20020aa7dcd5000000b0043a70f78e4dmr521740edu.85.1657233588171; Thu, 07 Jul 2022 15:39:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657233588; cv=none; d=google.com; s=arc-20160816; b=Wo3dYNmievIanhkeF5QikBeGcRLVKDFzYdRqJzPoqoY2TKeQIxAw5syqkRMjJmvi91 Il7dz3IKu2FEIAUxahGTpkLGQ66+75AcOFwH1/Lcptq5GIiH2/dqMZogQtgh6Nzoy9j2 BqQ73VmekRAfZCS/bKXj+aR/UBgpmG94/Crz/fXObHfmpR35EHcaZHOzrloGl+SoGqki zEg6I/bmKIyvQZ4ZZUn5YV3SDQ+sK+A7qzCDWcs7Frl/CPXxokzEwsGv5ycGnqsodnH6 FhjIDbF+Nb3bObxLXVoFN3j+wVq4FVoCKOjMR+BH6X2N/x0fDV40jU9MUmt1CAZwfWj/ voKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gpnGP72y7AlRDZxLLIIKCxGjGB4QqIYx1EtuBERrAGY=; b=vHQVumnLJa51sToDjzRhk1vVg6KYLZDBo6VLIsxVjhMbowkEa0ASY+fBVA35xZ5ShS +w6XEvKz0M+eedURtJrs3qVtdNkRy08C1JwXVCPBd/Ymc94rk+9ieGjPJxWbJmMpfMiW wLHrVAp2+0MWw9s9iVClH47bBvZdK9zVHNoZWJCO2Y3NB2nO3Tn7kFrQFusFIYhrQWbP D4jbnbiBzENhs7af5gfSHqbFfj5Oty0Zx3d1YkO2IvrvTkc7OvVHmZPw8ekBeclQJdkQ GM4M2wb3d47hTj5NDcNwiE9dQVHuPezxKnH7y9NRXv26Wt032yD21QoVmb/W7YNxJ37i yF1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=KfAsVex6; 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 c6-20020aa7c986000000b0043a54f78399si16095414edt.485.2022.07.07.15.39.22; Thu, 07 Jul 2022 15:39:48 -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=KfAsVex6; 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 S236039AbiGGWdT (ORCPT + 99 others); Thu, 7 Jul 2022 18:33:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237023AbiGGWcw (ORCPT ); Thu, 7 Jul 2022 18:32:52 -0400 Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED0C2675B6 for ; Thu, 7 Jul 2022 15:32:45 -0700 (PDT) Received: by mail-ot1-x331.google.com with SMTP id q18-20020a9d7c92000000b00616b27cda7cso14993457otn.9 for ; Thu, 07 Jul 2022 15:32:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gpnGP72y7AlRDZxLLIIKCxGjGB4QqIYx1EtuBERrAGY=; b=KfAsVex69jTCIdg5XmbRjXWWWy/S0Tca6CS8SwDAmazdBPIoDnrCREhbjrLFevHaGt 6ufFk77dMvGWeRIVQPkT2IDgHAiRo2457GzNSRpAj0LvK9u6HolMJoALdrhWiSJY3cDP lupYF3+zn3pi6FeorsgnBUBjJN6/6EstmhD80= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gpnGP72y7AlRDZxLLIIKCxGjGB4QqIYx1EtuBERrAGY=; b=lVQe8khsnVeieqTROpknLFOIs1qHp1wGcR6Bav3gryySPszeB37gGE3IchcSbG1w5K kJhzFQVNlJBr7yrMjTX8X0qRKxcyXbJNWMFg8tTxlxuk2IPTlafPrl7UKWN3sJ/ine1U Uhvf56AhsBqc9KV8sFXaK0zxTx7ub4l9imJxgNhbaMoGdB5aynccwNbnv3bSGyHrB4lZ oRMo0vZPA7fdYkhY4bywP+kXzbfaHGA7z1YzIyQe/+0ssXUi7ZmwCzGyAkNTycwuM+5U oottcUz3QA/t25Tyy4RO90ugTl1fNO8AyJfOCulAAD1ET13RjvOOPVDjtQ29/WfJYj+e 86yA== X-Gm-Message-State: AJIora/E4E/vz0TmDckfiH02ZFbahxf7l8+XS3oMfr7awKWX/DSJBrsM Y4cf1bEKvpgz2tg9MT/amkrKog== X-Received: by 2002:a9d:4c0e:0:b0:616:dd87:cb91 with SMTP id l14-20020a9d4c0e000000b00616dd87cb91mr182367otf.185.1657233164958; Thu, 07 Jul 2022 15:32:44 -0700 (PDT) Received: from localhost.localdomain ([184.4.90.121]) by smtp.gmail.com with ESMTPSA id i16-20020a05683033f000b00616b835f5e7sm16246222otu.43.2022.07.07.15.32.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 15:32:43 -0700 (PDT) From: Frederick Lawler To: 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, paul@paul-moore.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 Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, kernel-team@cloudflare.com, Frederick Lawler Subject: [PATCH v2 4/4] selinux: Implement create_user_ns hook Date: Thu, 7 Jul 2022 17:32:28 -0500 Message-Id: <20220707223228.1940249-5-fred@cloudflare.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220707223228.1940249-1-fred@cloudflare.com> References: <20220707223228.1940249-1-fred@cloudflare.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 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); +} + /* Returns error only if unable to parse addresses */ static int selinux_parse_skb_ipv4(struct sk_buff *skb, struct common_audit_data *ad, u8 *proto) @@ -7117,6 +7125,7 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(task_movememory, selinux_task_movememory), LSM_HOOK_INIT(task_kill, selinux_task_kill), LSM_HOOK_INIT(task_to_inode, selinux_task_to_inode), + LSM_HOOK_INIT(create_user_ns, selinux_userns_create), LSM_HOOK_INIT(ipc_permission, selinux_ipc_permission), LSM_HOOK_INIT(ipc_getsecid, selinux_ipc_getsecid), 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 } }, { NULL } }; -- 2.30.2