Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4314810iog; Tue, 21 Jun 2022 17:17:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vE5IXQdDRouSE61mqTuI9xLmCNFhAASasLLGuNDV3Fe4ncUseIyRiLngEaATfxqj9ymOy+ X-Received: by 2002:aa7:8b47:0:b0:525:4214:c195 with SMTP id i7-20020aa78b47000000b005254214c195mr2327406pfd.55.1655857048154; Tue, 21 Jun 2022 17:17:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655857048; cv=none; d=google.com; s=arc-20160816; b=ShLdtLv5E6bM1guaVVpm/ccxWcFUauSqsx5td0TiuVWqVR1FfzKDIAC0AAgQxYGFla SB5T9d76XRlMsfeTe5IROPJk/iorJylo11KsL7LCzup1jkpR+xpKyPjfdn/Xl/SyYckt /7eHXRNQEGa6Lm/6GnwqzFAzKDwzia1pTrL8/Znd2qbzdGxAOgw//pQmc//gVGTe2DPQ Tdk4ocgWwJV7iBT65AabHHnv4Od9hpk62bELMwXEbJR6csfCz2tpwmrpb4kR11vWPTWK bnXSA3I7JDYQwnidfLTeX9x2P5pdWwbHY3pUFKlF0teaRrQU3hiCYG4fWvF+yWaR5Ytk kDoA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=R2mtRCui72arwwdDzhHcYMhEmif96x0EwcrauisT3VI=; b=qhplMHt5nCmirlx2t1sMrSTCbcNQNjnZVyNIfvnuKXS3f+IfCuHRqBb57/Q7NR7wa2 IQjzWpNxt6jfWfG5fygL9JgrJVsisemab7I5iuBKUMzom4nbfDr/sfZDGoc8+infs1uq GleeZWbgWJTJz2ogmxmHQcrAkDJ4nY2dfqNegDJIDJKmra0fm0ILL8jrc3i0wba2OZRj 1AvdVjvTGG6OjwVXTw8DXsm0L9nXv8OVDYkip/I8gY0gM3YRmDXN/d65KaNd0RCa6fJ/ iBtLXekP0m4Glxr1Py+ysR+ytm6fsHofTG74gd0Z3q2d9NffhKxaeoSZtEZl9bbN8ixJ Krfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=OKq+JTNl; 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 r69-20020a632b48000000b004088e9a1b81si19398787pgr.541.2022.06.21.17.17.15; Tue, 21 Jun 2022 17:17:28 -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=OKq+JTNl; 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 S1353377AbiFUXjw (ORCPT + 99 others); Tue, 21 Jun 2022 19:39:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230302AbiFUXju (ORCPT ); Tue, 21 Jun 2022 19:39:50 -0400 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48E0831218 for ; Tue, 21 Jun 2022 16:39:47 -0700 (PDT) Received: by mail-oi1-x22c.google.com with SMTP id q11so19055688oih.10 for ; Tue, 21 Jun 2022 16:39:47 -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:mime-version :content-transfer-encoding; bh=R2mtRCui72arwwdDzhHcYMhEmif96x0EwcrauisT3VI=; b=OKq+JTNlWYyJIGaHUB9FKXgvMsyco0CeOWV1KYGWQohAZt5NFz5zqXeDRWNKqF0Aqt GOLRsh7mIOUphoH/n2W4X+nfqb4ogdgJU1DmkO3+vV9csNfMd8uYI2VVWvf1QxtvoGND znZdRcMnCbbdIrTnDFZCu2eAdFbusULqHF9wI= 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:mime-version :content-transfer-encoding; bh=R2mtRCui72arwwdDzhHcYMhEmif96x0EwcrauisT3VI=; b=I0+OALZi+ihkfc0tIkA6r6PODLH8EVPJ5ooZSgwhFff1MW4tLWzUl+J8d/XSjXwcDs SMhJenPf9Zct0sN7cghOVBaIebqCsnERy7ZtFTLjiSI7d/QYeJtVzryOr8yaHg5aZ08b CumVOJer36L7lOrP8K6iSZa2PojAI6wdc2rcPIz1iOeabW8j8Qdrsc6zR0T+sEePsAKf vlU2rzJJmSvVuhx9wx+3bXDZha7I8Ccm+ZgkgbjVuY49vDbRzQpSlxcll70+oAcCq79E q8ywScpdDgHW6X/lPNxYHpRwx1fycUJU3sRcuCSp8skr0ljgOesjqKkCHa9XFfMOALlg 1LRA== X-Gm-Message-State: AJIora+w8jRMmUt/CEYnsrSz0tGOgxVDXbcpKqZiipLGM6aWZXVbG7Yp S8vE/JtPxldSVQ80mfOUVRV2pQ== X-Received: by 2002:a05:6808:150e:b0:331:39bf:2228 with SMTP id u14-20020a056808150e00b0033139bf2228mr329850oiw.9.1655854786546; Tue, 21 Jun 2022 16:39:46 -0700 (PDT) Received: from localhost.localdomain ([172.58.70.161]) by smtp.gmail.com with ESMTPSA id v73-20020acaac4c000000b00326414c1bb7sm9839181oie.35.2022.06.21.16.39.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 16:39:46 -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, bpf@vger.kernel.org, linux-security-module@vger.kernel.org Cc: brauner@kernel.org, casey@schaufler-ca.com, paul@paul-moore.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@cloudflare.com, Frederick Lawler Subject: [PATCH 0/2] Introduce security_create_user_ns() Date: Tue, 21 Jun 2022 18:39:37 -0500 Message-Id: <20220621233939.993579-1-fred@cloudflare.com> X-Mailer: git-send-email 2.30.2 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 While creating a LSM BPF MAC policy to block user namespace creation, we used the LSM cred_prepare hook because that is the closest hook to prevent a call to create_user_ns(). The calls look something like this: cred = prepare_creds() security_prepare_creds() call_int_hook(cred_prepare, ... if (cred) create_user_ns(cred) We noticed that error codes were not propagated from this hook and introduced a patch [1] to propagate those errors. The discussion notes that security_prepare_creds() is not appropriate for MAC policies, and instead the hook is meant for LSM authors to prepare credentials for mutation. [2] Ultimately, we concluded that a better course of action is to introduce a new security hook for LSM authors. [3] This patch set first introduces a new security_create_user_ns() function and create_user_ns LSM hook, then marks the hook as sleepable in BPF. Links: 1. https://lore.kernel.org/all/20220608150942.776446-1-fred@cloudflare.com/ 2. https://lore.kernel.org/all/87y1xzyhub.fsf@email.froward.int.ebiederm.org/ 3. https://lore.kernel.org/all/9fe9cd9f-1ded-a179-8ded-5fde8960a586@cloudflare.com/ Frederick Lawler (2): security, lsm: Introduce security_create_user_ns() bpf-lsm: Make bpf_lsm_create_user_ns() sleepable include/linux/lsm_hook_defs.h | 2 ++ include/linux/lsm_hooks.h | 5 +++++ include/linux/security.h | 8 ++++++++ kernel/bpf/bpf_lsm.c | 1 + kernel/user_namespace.c | 5 +++++ security/security.c | 6 ++++++ 6 files changed, 27 insertions(+) -- 2.30.2