From patchwork Tue Sep 27 09:31:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Ruffell X-Patchwork-Id: 1683113 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=CmX8sSEH; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McDtK4PzWz1yq7 for ; Tue, 27 Sep 2022 19:32:24 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1od6wo-00033k-QZ; Tue, 27 Sep 2022 09:32:14 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1od6wm-00033D-F4 for kernel-team@lists.ubuntu.com; Tue, 27 Sep 2022 09:32:12 +0000 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 2A8623F1D5 for ; Tue, 27 Sep 2022 09:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1664271132; bh=/TyIFLTiCgt2grtemJDex6ctSfir4A/c8H3Qo7CTNIM=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CmX8sSEH9pU8Fr+cD8sbxNC0975jP8GOnfLtMQIU61IAaMUb16n2MIfuGeu1BG2rX N3FHGzk01YlhTATElMoaR55Ci3NeTszE+juCU2wtYt1u2GS1+BFKY1B0GjNmFPY3Ph fYJVT40vqf7BEbcMI0NQPbO0aTDMvDgpFQrcXQUYa1512t+gDjI0R2dCvbccNQ14wr D8v32W3p2P6iBeW4om2aC3L0RjTwcu1fWaI59LIoGZj2vLjoMsEMG2ssOQngngVjdV 1jEY+IqzpagMKmelMETAri+9YxBJoXKzLZ7JByFDLhQJznoi9FUgDpqnRvpLKtliPw wI+NKhPQjvHAA== Received: by mail-pl1-f199.google.com with SMTP id y16-20020a17090322d000b0017848b6f556so6057990plg.19 for ; Tue, 27 Sep 2022 02:32:12 -0700 (PDT) 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:to:from:x-gm-message-state:from:to:cc :subject:date; bh=/TyIFLTiCgt2grtemJDex6ctSfir4A/c8H3Qo7CTNIM=; b=wn+AudUuwNUnUTt7EZ9bf4f7xAc5GW9ix3whtwJFhlBw1KQWZh7oL4YNAeumVvflfQ cwN5vupRgI6gkpDVd++0cCnxDGv7OYsji46xd3OcC3zN5IcWIteyyHV3LNmFkg8zI+v3 EghnAy2z26BMp56SjHB1W0yfb5jbwTolXbCBGqpXIK7mY4eVl/OOeyR8BMZMbLZ4jlDy /0AdawmACYuQb9iX0c6EsDgzxP25LYeiJhCp3ap3GPUKTtm7VMrJbVUWtEbPvAaYmXoE bzcSVpA/5wVZTYdv0bbvjLEEqeMxz3XJ4dJ0Sg6voPX6gWA0VmUH3CPcVis8gLDSMilX E5ig== X-Gm-Message-State: ACrzQf1BhUJ/giLczuqHqWlyW700E6tkygkwJIhWsZRNrWYya3ers+RA eUrj5T+rj/sL/ZweGmcs9WKU5rICvWgH8CeE7O/60oza9Trz9ioBkqYi5Ne2DM74j8cIvdEv0da lfUOOg+6dyPImAFKHYhT2mMidJz7HmrR+88bBqRsKjQ== X-Received: by 2002:a05:6a00:140d:b0:52a:d561:d991 with SMTP id l13-20020a056a00140d00b0052ad561d991mr28240597pfu.46.1664271130170; Tue, 27 Sep 2022 02:32:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7lI75pOlKgkvlAfo8L9+UzJjhPtPaogA/gq/p0wZ9cNoleW3AkWf1gk65gd89tjNlr5M0MpA== X-Received: by 2002:a05:6a00:140d:b0:52a:d561:d991 with SMTP id l13-20020a056a00140d00b0052ad561d991mr28240564pfu.46.1664271129740; Tue, 27 Sep 2022 02:32:09 -0700 (PDT) Received: from desktop.. (125-239-70-54-fibre.sparkbb.co.nz. [125.239.70.54]) by smtp.gmail.com with ESMTPSA id t16-20020aa79470000000b0053e5b905843sm1201527pfq.203.2022.09.27.02.32.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 02:32:09 -0700 (PDT) From: Matthew Ruffell To: kernel-team@lists.ubuntu.com Subject: [SRU][J][K][Unstable][PATCH V2 1/1] UBUNTU: SAUCE: LSM: Change Landlock from LSMBLOB_NEEDED to LSMBLOB_NOT_NEEDED Date: Tue, 27 Sep 2022 22:31:59 +1300 Message-Id: <20220927093159.20056-2-matthew.ruffell@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220927093159.20056-1-matthew.ruffell@canonical.com> References: <20220927093159.20056-1-matthew.ruffell@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/1987998 The Landlock LSM does not register any hooks which use struct lsmblob, and does not require a slot in the secid array of struct lsmblob. Change LSMBLOB_NEEDED to LSMBLOB_NOT_NEEDED. This is required to fix a panic on boot where too many LSMs can be configured, since while we currently mark Landlock as LSMBLOB_NEEDED, we do not actually make LSMBLOB_ENTRIES large enough to fit it, and we panic when more than 2 LSMs are configured, like: GRUB_CMDLINE_LINUX_DEFAULT="lsm=landlock,bpf,apparmor" LSM: Security Framework initializing landlock: Up and running. LSM support for eBPF active Kernel panic - not syncing: security_add_hooks Too many LSMs registered. CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.15.0-46-generic #49-Ubuntu Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.15.0-1 04/01/2014 Call Trace: show_stack+0x52/0x5c dump_stack_lvl+0x4a/0x63 dump_stack+0x10/0x16 panic+0x149/0x321 security_add_hooks+0x45/0x13a apparmor_init+0x189/0x1ef initialize_lsm+0x54/0x74 ordered_lsm_init+0x379/0x392 security_init+0x40/0x49 start_kernel+0x466/0x4dc x86_64_start_reservations+0x24/0x2a x86_64_start_kernel+0xe4/0xef secondary_startup_64_no_verify+0xc2/0xcb ---[ end Kernel panic - not syncing: security_add_hooks Too many LSMs registered. ]--- Also refactor the Landlock support by going to just one struct lsm_id, and extern it from setup.h, following upstream development. Fixes: f17b27a2790e ("UBUNTU: SAUCE: LSM: Create and manage the lsmblob data structure.") ubuntu-jammy Signed-off-by: Matthew Ruffell Acked-by: Stefan Bader Acked-by: Andrea Righi --- security/landlock/cred.c | 5 ----- security/landlock/fs.c | 5 ----- security/landlock/ptrace.c | 5 ----- security/landlock/setup.c | 5 +++++ security/landlock/setup.h | 1 + 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/security/landlock/cred.c b/security/landlock/cred.c index e3bd04cc7177..2eb1d65f10d6 100644 --- a/security/landlock/cred.c +++ b/security/landlock/cred.c @@ -14,11 +14,6 @@ #include "ruleset.h" #include "setup.h" -static struct lsm_id landlock_lsmid __lsm_ro_after_init = { - .lsm = "landlock", - .slot = LSMBLOB_NEEDED -}; - static int hook_cred_prepare(struct cred *const new, const struct cred *const old, const gfp_t gfp) { diff --git a/security/landlock/fs.c b/security/landlock/fs.c index b81db9d184bd..d8842a2ac58a 100644 --- a/security/landlock/fs.c +++ b/security/landlock/fs.c @@ -37,11 +37,6 @@ #include "ruleset.h" #include "setup.h" -static struct lsm_id landlock_lsmid __lsm_ro_after_init = { - .lsm = "landlock", - .slot = LSMBLOB_NEEDED -}; - /* Underlying object management */ static void release_inode(struct landlock_object *const object) diff --git a/security/landlock/ptrace.c b/security/landlock/ptrace.c index 0f3bb8ea12db..eab35808f395 100644 --- a/security/landlock/ptrace.c +++ b/security/landlock/ptrace.c @@ -20,11 +20,6 @@ #include "ruleset.h" #include "setup.h" -static struct lsm_id landlock_lsmid __lsm_ro_after_init = { - .lsm = "landlock", - .slot = LSMBLOB_NEEDED -}; - /** * domain_scope_le - Checks domain ordering for scoped ptrace * diff --git a/security/landlock/setup.c b/security/landlock/setup.c index f8e8e980454c..759e00b9436c 100644 --- a/security/landlock/setup.c +++ b/security/landlock/setup.c @@ -23,6 +23,11 @@ struct lsm_blob_sizes landlock_blob_sizes __lsm_ro_after_init = { .lbs_superblock = sizeof(struct landlock_superblock_security), }; +struct lsm_id landlock_lsmid __lsm_ro_after_init = { + .lsm = LANDLOCK_NAME, + .slot = LSMBLOB_NOT_NEEDED, +}; + static int __init landlock_init(void) { landlock_add_cred_hooks(); diff --git a/security/landlock/setup.h b/security/landlock/setup.h index 1daffab1ab4b..38bce5b172dc 100644 --- a/security/landlock/setup.h +++ b/security/landlock/setup.h @@ -14,5 +14,6 @@ extern bool landlock_initialized; extern struct lsm_blob_sizes landlock_blob_sizes; +extern struct lsm_id landlock_lsmid; #endif /* _SECURITY_LANDLOCK_SETUP_H */