Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2716481rwb; Mon, 15 Aug 2022 10:06:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR4lUtpX4oUL3GRJ2zksdgI26/dsQkLI2sZfTKYE1Q83I3QKDkicp60aZBpXwulT/jIgN5Re X-Received: by 2002:a17:90a:e7cb:b0:1f5:38:cb53 with SMTP id kb11-20020a17090ae7cb00b001f50038cb53mr19647528pjb.110.1660583198538; Mon, 15 Aug 2022 10:06:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660583198; cv=none; d=google.com; s=arc-20160816; b=ZvkEp2Y9WkKZ3Zod2fgj5toHiVxen1G9lNEpiHfn8flFQvEAda0MEFQB2owtyBmb9U PeNn4YH3y4V85X7Gd/xQyQH2IA37DwH225sBTVJuvQXoPsDFw33ijd4HaQh6UC82nM6w +GOrhoAczNEC6kHBmmPzaTR2o/OnDEU/qMLuZgs8YVWDcVZWGihpvoEpv3FbSuzFw9mD 6LIRfcs1ux/yK3FqaqVGhkXaW1TNPVcNONbIHkEeR2zFH97f2L2QLDkV9JGkLUBf9nKG oxe/UAzSclIzF/yiUeQFTasGHlXrmxszJiL0bqD0UMMGDRRL0lEy2Y+KpYwbDMOZYhnw KjMA== 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=U3OK8Oqnf2K0vdWXT1jn4LVlcHC3Qy4QXRttGxzPtuo=; b=LD6nCqWZ7nFAGaxY2iCY6H9i/50aOIuLMJwynxMBjBsaZTwJ+ujMwpCcCaRcJ5WKf8 WCeCGCtlyV4kD9NsjO27K64BWsxncIYPvaQ6fPPt33Pnc8FFNab/hBUpvbq8OVBf59dJ W10+CTe/vK7rZXu0TxLgoIfgerc23fAXTKevSH//kJk7xOV4DEnPj5OO0yjKDKqC67RF WHq6/6Q/S7GmcRlldlnZhiXozhCuPUaf8R7XfKEwxmISgH91EGAsp4zaRYf81ULxrbn1 7pFmj3/h3wUVmMXC3WsV+rEusI32TRqlCIHtmumQVN1tXCnXb1n1xe0bqvFhwhgNyuNM WPwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=XU3mICcI; 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 f2-20020a170902ce8200b0016ee3b6681esi11666178plg.75.2022.08.15.10.06.12; Mon, 15 Aug 2022 10:06:38 -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=XU3mICcI; 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 S232913AbiHOQV6 (ORCPT + 99 others); Mon, 15 Aug 2022 12:21:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232854AbiHOQUq (ORCPT ); Mon, 15 Aug 2022 12:20:46 -0400 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD3481EEC1 for ; Mon, 15 Aug 2022 09:20:42 -0700 (PDT) Received: by mail-ot1-x333.google.com with SMTP id t11-20020a05683014cb00b0063734a2a786so5754512otq.11 for ; Mon, 15 Aug 2022 09:20:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=U3OK8Oqnf2K0vdWXT1jn4LVlcHC3Qy4QXRttGxzPtuo=; b=XU3mICcICTtNu7uN8K5AA/UUF9eGokgmjP4mS51xOSo4TbR6mIgICfjf3JleWSCsnD 3bKxTlmLlhl3CdsgdqLQhB63ngHK/3WAjkc9apGYatsqocuIO2tLcXn8aGkf/AKiaTLs sTT1sq/iMyXBWFfe2c4PBoNmB/mESTtAqL4LQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=U3OK8Oqnf2K0vdWXT1jn4LVlcHC3Qy4QXRttGxzPtuo=; b=2UNGKmaG3umZy+9LCYVIYkFOR34y7Neb3NjIys/ZV00kAmV40RaamG13JKC38tv6dS /L5mxM08Rc4RuYcYHG1EdTJYtvAyJo+imFeBujdM+qr/RRF4taSoH5bp6g4CwSlWrBFO 0Bu0e83fbUHjc3n9a/zAMZhlOXv6nF4iFYs7Ye11ISNYKuKqC3DVYxWvmngJgn3GzZRK AwHm5GuIqJ86Q5QmKR+kYOut/RgJL+zX2elxt9s68f/9Oij02+Yxs6XP3ul4PLjp0P+q VO3zWFriuJOVk8fw6NabMmXUFEiH5UoY/yD0R9OrpHwEA/iWD1XsLeBtw4LCjAjd/V67 +OxQ== X-Gm-Message-State: ACgBeo3Oh8OFZ8TwGxhHGR6u1oXHxLvQQxRC2OkYJP5rCvDo6dAD4AkY s8fDUTeBAtH0ljSoT7TZbqUPdw== X-Received: by 2002:a05:6830:10c9:b0:636:d88f:1299 with SMTP id z9-20020a05683010c900b00636d88f1299mr6217405oto.134.1660580441763; Mon, 15 Aug 2022 09:20:41 -0700 (PDT) Received: from localhost.localdomain ([184.4.90.121]) by smtp.gmail.com with ESMTPSA id x91-20020a9d37e4000000b00636ee04e7aesm2163371otb.67.2022.08.15.09.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 09:20:41 -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, cgzones@googlemail.com, karl@bigbadwolfsecurity.com, tixxdz@gmail.com, Frederick Lawler Subject: [PATCH v5 4/4] selinux: Implement userns_create hook Date: Mon, 15 Aug 2022 11:20:28 -0500 Message-Id: <20220815162028.926858-5-fred@cloudflare.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815162028.926858-1-fred@cloudflare.com> References: <20220815162028.926858-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=ham 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 user_namespace { 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 domA_t : user_namespace { create }; Signed-off-by: Frederick Lawler --- Changes since v4: - None Changes since v3: - None Changes since v2: - Rename create_user_ns hook to userns_create - Use user_namespace as an object opposed to a generic namespace object - s/domB_t/domA_t in commit message 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 79573504783b..b9f1078450b3 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -4221,6 +4221,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_USER_NAMESPACE, + USER_NAMESPACE__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) @@ -7111,6 +7119,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(userns_create, 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..0bff55bb9cde 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 } }, + { "user_namespace", + { "create", NULL } }, { NULL } }; -- 2.30.2