Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4911522pxj; Tue, 25 May 2021 20:59:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7/32NBO3D630y0qbUTRQ2+MAa9G0wtZ7Ye84Wox6FasF92Jl+Aq6XWYY1npM21462pnde X-Received: by 2002:a6b:4408:: with SMTP id r8mr15342081ioa.55.1622001546302; Tue, 25 May 2021 20:59:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622001546; cv=none; d=google.com; s=arc-20160816; b=NGSpptYHvdiuEitIUBMb+YgoZkC7+ISMf/3yM6MKHeVvmYP5i7zt1fTClCy80Ev87Z OBU2BOUY5rpdcwUSaD9QUMs6kXkvI8hSmvenfpSx6FNZ9jXIeu+Opno0R10I6eI9U7bo wFufHftjLXcV99djJyCFRYKthLheOojq7Ym2gLpQMzDHEP7KrO7tcYAssQ83ZIcUbrY6 HHB26A/PekBq3NsveSp6ODszkWRpQTwtqCNVopCY6FRp1ZFVCF0yF32obb31vOh8Gt41 V43rddomeb+p4bsYbnbXD3Z90r02wYaK98UkuS+GjLpfLZxIsBru4pMs5mh6tE59ZsNB xzLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=mvSm0zmB+BMDw2EKW2It3WUM0gYqaOcZAoXM7pXqn1w=; b=sam+zlQfriYGwGeA68zVnmztIzVu2WjIb/6RyrWa1hpDhmt2/Sd8dx33eYCByIPzLV edzTvKMSuX24u8Vc29vjeU9nVB6tTj90qM4IXJK8rlt2u0PB3aJy5a6UhuP9I9jJFer/ xvNetSlZ7rKXO4jcqeIui6NDC22bgiYR5SA7EvHeZnN4LJE0NmZ+jJaKYT5CJLdnECN9 0Hd8XDxFo2n606siKUcPY5zvXRXi3ovVrOqpWOTxd/9vJF6i7xbeOfk2um7g+0uzIqYM bMfmsHYjJesjmN0543oybaVyeCQPpOaOBenYbLTygnfUxVr3VWuTzpGSAJvps0KPV82g lf0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=GLo2F00x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l15si7500178ilk.32.2021.05.25.20.58.52; Tue, 25 May 2021 20:59:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=GLo2F00x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231947AbhEYXxo (ORCPT + 99 others); Tue, 25 May 2021 19:53:44 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:46492 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232111AbhEYXxn (ORCPT ); Tue, 25 May 2021 19:53:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1621986733; bh=mvSm0zmB+BMDw2EKW2It3WUM0gYqaOcZAoXM7pXqn1w=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject:Reply-To; b=GLo2F00xV3u/FBAegG7qkuIoOWBH7oBQSsqXLHsmyahkLaqQxTT5hQCYcv3A0TafXq4SeFIraVyD+pAv0UGIZOg+OcvZW7WM0Dk1B8Rr47mZKL15MQqOnqYwPuA/9CknL4ffOgA062myaFKRkOIFgTIY5EGEW/fhqIosBL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5IRJzyuZL3.cMFFAiuYaE_Ac1e3CiQDW6wpwODsBbl dtQa8ZKu3mCKV2Pzs2m67.V69ODvgORuWh41SuKNm2dHFjhiJpUHtCOoYYMbaGst271OPGxF5Acw x8JziJbhxoazcNvQbx4BrMBkwuuERbsn_bR18eD.8yqm7Hcz1dYX3KZM42DnuI1wEgR3hdawrsD9 YVrXCcFGYbj2c6beLk7z39.n.2PpqZtZAf2zfyGZXRSsSOXW.CJokwvp5X7jKdFHi6rktPyBR8ih YzTSsYCqN6sXVKEkIH5kiG6fFTRP3rHNnf3C0pWbV6y8w3XE0dwciqDGMrptS9xaecWtHqYQV.A0 gI3c1V_MEy9FYkpgcablGJIUPI8yfMCvhd8W5JgbaTWQASgxBSsS20Hfe.ZYe3tC.7J9pGHue8tZ 8uf7qFw5ppTnrw1UnNgfxFUVs4IMjHphyPEkNCeEXU5iVTDxWcdXADdVtuJ5xpv.pnerj14YajF1 4xVF.bFLxtte4L49Eg28T9v60ENsyC7BKx.s4oSghLcoY9hnx9ItYn16w4_DpglI75mp1PQtVegm GC4Tqr1c8I7CuEa13iBtDitmvET1SOzYsPX5N8CgwWCJQHqPKHp_mq4BtYuqjeg2hsGao4nx23DK kJQM34tz3CdqsawsJph4P.xo4Tqze7lsobK9XqjTFdQMaRZLQpYA- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 25 May 2021 23:52:13 +0000 Received: by kubenode565.mail-prod1.omega.gq1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 37ef89f8728ecb08423fd6b99f8ccf9e; Tue, 25 May 2021 23:52:11 +0000 (UTC) Subject: Re: [PATCH v26 02/25] LSM: Add the lsmblob data structure. To: =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= , casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: linux-audit@redhat.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Casey Schaufler References: <20210513200807.15910-1-casey@schaufler-ca.com> <20210513200807.15910-3-casey@schaufler-ca.com> <206971d6-70c7-e217-299f-1884310afa15@digikod.net> From: Casey Schaufler Message-ID: <1c3874c1-870a-ac60-03e6-2c16d49e185b@schaufler-ca.com> Date: Tue, 25 May 2021 16:52:10 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <206971d6-70c7-e217-299f-1884310afa15@digikod.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Language: en-US X-Mailer: WebService/1.1.18368 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Content-Length: 5918 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/22/2021 1:39 AM, Micka=C3=ABl Sala=C3=BCn wrote: > I like this design but there is an issue with Landlock though, see belo= w. > > On 13/05/2021 22:07, Casey Schaufler wrote: >> When more than one security module is exporting data to >> audit and networking sub-systems a single 32 bit integer >> is no longer sufficient to represent the data. Add a >> structure to be used instead. >> >> The lsmblob structure is currently an array of >> u32 "secids". There is an entry for each of the >> security modules built into the system that would >> use secids if active. The system assigns the module >> a "slot" when it registers hooks. If modules are >> compiled in but not registered there will be unused >> slots. >> >> A new lsm_id structure, which contains the name >> of the LSM and its slot number, is created. There >> is an instance for each LSM, which assigns the name >> and passes it to the infrastructure to set the slot. >> >> The audit rules data is expanded to use an array of >> security module data rather than a single instance. >> Because IMA uses the audit rule functions it is >> affected as well. >> >> Acked-by: Stephen Smalley >> Acked-by: Paul Moore >> Acked-by: John Johansen >> Signed-off-by: Casey Schaufler >> Cc: >> Cc: linux-audit@redhat.com >> Cc: linux-security-module@vger.kernel.org >> Cc: selinux@vger.kernel.org >> To: Mimi Zohar >> To: Micka=C3=ABl Sala=C3=BCn >> --- >> include/linux/audit.h | 4 +- >> include/linux/lsm_hooks.h | 12 ++++- >> include/linux/security.h | 67 +++++++++++++++++++++++++-- >> kernel/auditfilter.c | 24 +++++----- >> kernel/auditsc.c | 13 +++--- >> security/apparmor/lsm.c | 7 ++- >> security/bpf/hooks.c | 12 ++++- >> security/commoncap.c | 7 ++- >> security/integrity/ima/ima_policy.c | 40 +++++++++++----- >> security/landlock/cred.c | 2 +- >> security/landlock/fs.c | 2 +- >> security/landlock/ptrace.c | 2 +- >> security/landlock/setup.c | 4 ++ >> security/landlock/setup.h | 1 + >> security/loadpin/loadpin.c | 8 +++- >> security/lockdown/lockdown.c | 7 ++- >> security/safesetid/lsm.c | 8 +++- >> security/security.c | 72 ++++++++++++++++++++++++----= - >> security/selinux/hooks.c | 8 +++- >> security/smack/smack_lsm.c | 7 ++- >> security/tomoyo/tomoyo.c | 8 +++- >> security/yama/yama_lsm.c | 7 ++- >> 22 files changed, 262 insertions(+), 60 deletions(-) >> > [...] > >> diff --git a/security/landlock/setup.c b/security/landlock/setup.c >> index f8e8e980454c..4a12666a4090 100644 >> --- a/security/landlock/setup.c >> +++ b/security/landlock/setup.c >> @@ -23,6 +23,10 @@ struct lsm_blob_sizes landlock_blob_sizes __lsm_ro_= after_init =3D { >> .lbs_superblock =3D sizeof(struct landlock_superblock_security), >> }; >> =20 >> +struct lsm_id landlock_lsmid __lsm_ro_after_init =3D { >> + .lsm =3D LANDLOCK_NAME, > It is missing: .slot =3D LSMBLOB_NEEDED, Sorry for the delay. Landlock does not provide any of the hooks that use a struct lsmblob. That would be secid_to_secctx, secctx_to_secid, inode_getsecid, cred_getsecid, kernel_act_as task_getsecid_subj task_getsecid_obj and ipc_getsecid. Setting .slot =3D LSMBLOB_NEEDED indicates that the LSM uses a slot in struct lsmblob. Landlock does not need a slot. > > You can run the Landlock tests please? > make -C tools/testing/selftests TARGETS=3Dlandlock gen_tar > tar -xf kselftest.tar.gz && ./run_kselftest.sh Sure. I'll add them to my routine. > > >> +}; >> + >> static int __init landlock_init(void) >> { >> landlock_add_cred_hooks(); > [...] > >> diff --git a/security/security.c b/security/security.c >> index e12a7c463468..a3276deb1b8a 100644 >> --- a/security/security.c >> +++ b/security/security.c >> @@ -344,6 +344,7 @@ static void __init ordered_lsm_init(void) >> init_debug("sock blob size =3D %d\n", blob_sizes.lbs_sock); >> init_debug("superblock blob size =3D %d\n", blob_sizes.lbs_superbloc= k); >> init_debug("task blob size =3D %d\n", blob_sizes.lbs_task); >> + init_debug("lsmblob size =3D %zu\n", sizeof(struct lsmblob))= ; >> =20 >> /* >> * Create any kmem_caches needed for blobs >> @@ -471,21 +472,36 @@ static int lsm_append(const char *new, char **re= sult) >> return 0; >> } >> =20 >> +/* >> + * Current index to use while initializing the lsmblob secid list. >> + */ >> +static int lsm_slot __lsm_ro_after_init; >> + >> /** >> * security_add_hooks - Add a modules hooks to the hook lists. >> * @hooks: the hooks to add >> * @count: the number of hooks to add >> - * @lsm: the name of the security module >> + * @lsmid: the identification information for the security module >> * >> * Each LSM has to register its hooks with the infrastructure. >> + * If the LSM is using hooks that export secids allocate a slot >> + * for it in the lsmblob. >> */ >> void __init security_add_hooks(struct security_hook_list *hooks, int = count, >> - char *lsm) >> + struct lsm_id *lsmid) >> { >> int i; >> =20 > Could you add a WARN_ON(!lsmid->slot || !lsmid->name) here? Yes. That's reasonable. > > >> + if (lsmid->slot =3D=3D LSMBLOB_NEEDED) { >> + if (lsm_slot >=3D LSMBLOB_ENTRIES) >> + panic("%s Too many LSMs registered.\n", __func__); >> + lsmid->slot =3D lsm_slot++; >> + init_debug("%s assigned lsmblob slot %d\n", lsmid->lsm, >> + lsmid->slot); >> + } >> + >> for (i =3D 0; i < count; i++) { >> - hooks[i].lsm =3D lsm; >> + hooks[i].lsmid =3D lsmid; >> hlist_add_tail_rcu(&hooks[i].list, hooks[i].head); >> } >> =20