Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2119276imn; Mon, 1 Aug 2022 11:49:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR4zK52Rzsxeq+sK3/dtomFtk3q2+vSjRYYw0c62Q4P78AHtmOpCIG9bG9tzfclK/ADt4b/o X-Received: by 2002:a17:902:d54e:b0:16e:f3e4:8c88 with SMTP id z14-20020a170902d54e00b0016ef3e48c88mr4453245plf.94.1659379774297; Mon, 01 Aug 2022 11:49:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659379774; cv=none; d=google.com; s=arc-20160816; b=yr7+9drH7MIy4OX2h9CwROCbLqooeLHlw7w8e16KmrJqjpCkOadZGniFfO4lVcn5zE 3Qv/km6paALXWO0rwAaPYtL7u4+YQ3oA1fTvjZ/b0qlJHQvmBNchGMxK9Vi4KDNc1mQd je31cDbiusdJCwbrdQAugsQknuz7vYRX5h4002797hp+iLzCnHl5PNKw1mfINRWUPz1S fWWlwj0DHQBjSq2fOKHDlbqxaY8Mor7zTAeVavMCBeCmxBrLE7zLRC2Dii1sLPi52jwt 2DVCRxLAJZwGGQ7t0iR4vX5E84eHltTc0fz0VWpLOsaOGwb0NhdF+IRyS/xEDHxzS+eY KGOw== 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=bttyVQI+o0yCdSSwfTGsmfJypexzzz/Ptc7wrcpVb94=; b=Qgf/IT9XFTesLXALcdwNAch5Nnh2ClY5sZxRa1qP2pgoZHklKGBiaYaWSsOKwcvX1N AQs2SGTtMnZzwRkK1QjQnu1BgUjeSgb8+sB+1rR/ZQ2ZIN8Qpy4PPi4gbDZ6NQ5ULIq+ 20cqgfyaC6AYPswMfXiDcvrRFB4sk089I1MZf/t2T8LBnafdLW6UBLdebhYrYJJHgtfW 2g7idQrbFmYeSPVVNFUr7OX+/C3/nL46eWGMITmDgBWceQMjvw1TVptbFUK3PEDyAf8s Cf5nWsKaXrR99WR9L0semJ+M+XIokOoC61iIBbVgAkqqcKyOqsTCj0UCCfrXrBD9E7+X WPzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=i4ToQg1x; 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 w18-20020a056a0014d200b0052d472f00f7si537280pfu.358.2022.08.01.11.49.19; Mon, 01 Aug 2022 11:49:34 -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=i4ToQg1x; 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 S234000AbiHASDE (ORCPT + 99 others); Mon, 1 Aug 2022 14:03:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233909AbiHASCx (ORCPT ); Mon, 1 Aug 2022 14:02:53 -0400 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE25E2B61D for ; Mon, 1 Aug 2022 11:02:25 -0700 (PDT) Received: by mail-oi1-x22d.google.com with SMTP id n133so13985678oib.0 for ; Mon, 01 Aug 2022 11:02:25 -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=bttyVQI+o0yCdSSwfTGsmfJypexzzz/Ptc7wrcpVb94=; b=i4ToQg1x5/k2OuSwcs5fz8zHz6WBhwfxswzE6nWWdWaeEdPc6pv10CDx0N+HMBM9Yj apKtW+hsRPgAXYA0BTvzit4oSXA5q0fwJgMIOswGMI+7uQRvQtuNrIn2Q8ZTP+qQUF4U PXAMRMONfHRrue6t5Oi+zRbQrpqKUBZwty/Yw= 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=bttyVQI+o0yCdSSwfTGsmfJypexzzz/Ptc7wrcpVb94=; b=Ov6Mov2u7U1YQR0Kd2OP6TI/zyi+JzSUPFF46kscv2KI5xLV1q9YBct34kBI6br9Vu sMMroZDmJK/7wTJ9z7PbzB1fgpNlJxsfoXJkyLcuIpzV6CYc4owc54sZXCGEAjimGRWJ YvLemctXJN/igbAOJxpGn2evebjI6lbjLhouTJmpPkOrQl1Jgvz5AJUQ3OyIqM+ZgCPg CXICjWF6EBbHIXzVYGw3EIul/QJkeX3LVJ3o2jhFS8mqCE0MwMH9JOxyD1Xrs/v3ck6x 3mymOlk3NQb8337GUgDgU0nKxVbNYpxRky/39P+TkwpKN/laVjh6TKkdFVnfHyx0QGcJ xpKA== X-Gm-Message-State: AJIora/rDy2a2WMuDs9Vi5yu0FeNGgpYx68gVSjXEvmiL+sABKPpEuPC 89X2Yzuj4p2H5Vr+//4nd+v32g== X-Received: by 2002:a05:6808:302b:b0:2f9:eeef:f03 with SMTP id ay43-20020a056808302b00b002f9eeef0f03mr6998147oib.128.1659376942519; Mon, 01 Aug 2022 11:02:22 -0700 (PDT) Received: from localhost.localdomain ([184.4.90.121]) by smtp.gmail.com with ESMTPSA id n14-20020a9d64ce000000b00618fa37308csm2881348otl.35.2022.08.01.11.02.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 11:02:22 -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, Frederick Lawler Subject: [PATCH v4 4/4] selinux: Implement userns_create hook Date: Mon, 1 Aug 2022 13:01:46 -0500 Message-Id: <20220801180146.1157914-5-fred@cloudflare.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220801180146.1157914-1-fred@cloudflare.com> References: <20220801180146.1157914-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 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 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 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 beceb89f68d9..afc9da0249e7 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_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) @@ -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(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