Implement Trusted Security Event Modeling.
Subsystems (5)
Re: [PATCH 14/14] Activate the configuration and build of the TSEM LSM.
In reply to Dr. GregQuoted 26 lines · Dr. Greg
Complete the implementation by integrating the LSM into the configuration and kernel build infrastructure.
Signed-off-by Greg Wettstein <[email protected]>--- security/Kconfig | 11 ++++++----- security/Makefile | 1 + security/tsem/Kconfig | 22 ++++++++++++++++++++++ security/tsem/Makefile | 2 ++ 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 security/tsem/Kconfig create mode 100644 security/tsem/Makefilesecurity/Kconfig +1
-0@@ -207,6 +207,7 @@ source "security/yama/Kconfig" source "security/safesetid/Kconfig" source "security/lockdown/Kconfig" source "security/landlock/Kconfig" +source "security/tsem/Kconfig" source "security/integrity/Kconfig"
security/Kconfig endchoice · line 250
Quoted 9 lines
security/Kconfig +1
-5@@ -246,11 +247,11 @@ endchoice config LSM string "Ordered list of enabled LSMs" - default "landlock,lockdown,yama,loadpin,safesetid,integrity,smack,selinux,tomoyo,apparmor,bpf" if DEFAULT_SECURITY_SMACK - default "landlock,lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf" if DEFAULT_SECURITY_APPARMOR - default "landlock,lockdown,yama,loadpin,safesetid,integrity,tomoyo,bpf" if DEFAULT_SECURITY_TOMOYO - default "landlock,lockdown,yama,loadpin,safesetid,integrity,bpf" if DEFAULT_SECURITY_DAC - default "landlock,lockdown,yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor,bpf" + default "landlock,lockdown,yama,loadpin,safesetid,integrity,smack,selinux,tomoyo,apparmor,bpf,tsem"
Better check with the BPF team to see if they're OK with TSEM following BPF in loading order.
Quoted 56 lines
if
DEFAULT_SECURITY_SMACKsecurity/Kconfig +4
-0+ default "landlock,lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf,tsem" if DEFAULT_SECURITY_APPARMOR + default "landlock,lockdown,yama,loadpin,safesetid,integrity,tomoyo,bpf,tsem" if DEFAULT_SECURITY_TOMOYO + default "landlock,lockdown,yama,loadpin,safesetid,integrity,bpf,tsem" if DEFAULT_SECURITY_DAC + default "landlock,lockdown,yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor,bpf,tsem" help A comma-separated list of LSMs, in initialization order. Any LSMs left off this list will be ignored. This can besecurity/Makefile +1
-0@@ -24,6 +24,7 @@ obj-$(CONFIG_SECURITY_LOCKDOWN_LSM) += lockdown/ obj-$(CONFIG_CGROUPS) += device_cgroup.o obj-$(CONFIG_BPF_LSM) += bpf/ obj-$(CONFIG_SECURITY_LANDLOCK) += landlock/ +obj-$(CONFIG_SECURITY_TSEM) += tsem/ # Object integrity file lists obj-$(CONFIG_INTEGRITY) += integrity/security/tsem/Kconfig new file +22
-0@@ -0,0 +1,22 @@ +config SECURITY_TSEM + bool "Trusted Security Event Modeling" + depends on SECURITY + depends on NET && INET + select SECURITY_NETWORK + select SECURITYFS + select CRYPTO + select CRYPTO_SHA256 + select CRYPTO_HASH_INFO + select TCG_TPM if HAS_IOMEM && !UML + select TCG_TIS if TCG_TPM && X86 + select TCG_CRB if TCG_TPM && ACPI + default n + help + This option selects support for Trusted Security Event + Modeling (TSEM). TSEM implements the ability to model + the security state of either the system at large or in a + restricted namespace on the basis of the LSM security + events and attributes that occur in the scope of the model. + The model may be implemented either in the kernel proper + or exported to an external Trusted Modeling Agent (TMA). + If you are unsure how to answer this question, answer N.security/tsem/Makefile new file +2
-0@@ -0,0 +1,2 @@ +obj-$(CONFIG_SECURITY_TSEM) := tsem.o model.o namespace.o map.o event.o fs.o \ + export.o trust.o
Re: [PATCH 14/14] Activate the configuration and build of the TSEM LSM.
Quoted 28 lines · Casey Schaufler
Quoted 27 lines · Dr. Greg
Complete the implementation by integrating the LSM into the configuration and kernel build infrastructure.
Signed-off-by Greg Wettstein <[email protected]>--- security/Kconfig | 11 ++++++----- security/Makefile | 1 + security/tsem/Kconfig | 22 ++++++++++++++++++++++ security/tsem/Makefile | 2 ++ 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 security/tsem/Kconfig create mode 100644 security/tsem/Makefilesecurity/Kconfig +1
-0@@ -207,6 +207,7 @@ source "security/yama/Kconfig" source "security/safesetid/Kconfig" source "security/lockdown/Kconfig" source "security/landlock/Kconfig" +source "security/tsem/Kconfig" source "security/integrity/Kconfig"@@ -246,11 +247,11 @@ endchoice
Quoted 8 lines
security/Kconfig endchoice
Quoted 8 lines
security/Kconfig +1
-5config LSM string "Ordered list of enabled LSMs" - default "landlock,lockdown,yama,loadpin,safesetid,integrity,smack,selinux,tomoyo,apparmor,bpf" if DEFAULT_SECURITY_SMACK - default "landlock,lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf" if DEFAULT_SECURITY_APPARMOR - default "landlock,lockdown,yama,loadpin,safesetid,integrity,tomoyo,bpf" if DEFAULT_SECURITY_TOMOYO - default "landlock,lockdown,yama,loadpin,safesetid,integrity,bpf" if DEFAULT_SECURITY_DAC - default "landlock,lockdown,yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor,bpf" + default "landlock,lockdown,yama,loadpin,safesetid,integrity,smack,selin
ux,tomoyo,apparmor,bpf,tsem"
Hi Casey, thanks for the note, I hope your week is going well.
Quoted 2 lines
Better check with the BPF team to see if they're OK with TSEM following BPF in loading order.
We can do that, however, as we noted in the documentation, TSEM, being the first LSM to be based on a narratival security logic philosophy, should be largely ambivalent with respect to its stacking order.
We would thus, happily, entertain suggestions from the community as to where it would like us to stand in line.
As an example, without going off into the weeds, since TSEM is a generic security modeling architecture, it can implement any integrity policies, including validation of extended security attributes. Placing it first in line would allow a security workload architect to reject any modifications to expected MAC security labels as an invalid security model state point before the event got to the deontological handlers.
However, being the new kid on the block, we would never presume to be first or last, given that they may be coveted positions.
So we will remain open to suggestions for the second spin of the patches.
Have a good afternoon.
As always,
Dr. Greg
The Quixote Project - Flailing at the Travails of Cybersecurity
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 09/14] Add namespace implementation.
On Sat, Feb 04, 2023 at 07:59:17PM +0800, Hillf Danton wrote:
Good afternoon Hillf, I hope this note finds your week going well.
Sorry for the delay in getting back to you on this, had some travel and we are now in the process of readying the second spin of the patches.
Thank you, up front, for taking the time to comment on the series.
Quoted 1 line
[with lkml Cced]
Noted.
Quoted 57 lines
On Fri, 3 Feb 2023 23:09:49 -0600 Dr. Greg <[email protected]>
Quoted 36 lines
(quoted diff) +36
-0+/** + * tsem_ns_free() - Releases the namespace model infrastructure. + * @kref: A pointer to the reference counting structure for the namespace. + * + * This function is called when the last reference to a kernel + * based TMA model structure is released. + */ +void tsem_ns_free(struct kref *kref) +{ + struct tsem_TMA_context *ctx; + + ctx = container_of(kref, struct tsem_TMA_context, kref); + + if (ctx->external) { + tsem_fs_remove_external(ctx->external->dentry); + kfree(ctx->external); + } else + tsem_model_free(ctx); + + kfree(ctx); +} + +static void wq_put(struct work_struct *work) +{ + struct tsem_TMA_work *tsem_work; + struct tsem_TMA_context *ctx; + + tsem_work = container_of(work, struct tsem_TMA_work, work); + ctx = tsem_work->ctx; + kref_put(&ctx->kref, tsem_ns_free); +} + +/** + * tsem_ns_get() - Obtain a reference on a TSEM TMA namespace. + * @ctx: A pointer to the TMA modeling context for which a reference is + * to be released.Review
Quoted 10 lines
(quoted diff) +10
-0+ * + * This function is called to release a reference to a TMA modeling + * domain. + */ +void tsem_ns_put(struct tsem_TMA_context *ctx) +{ + if (kref_read(&ctx->kref) > 1) { + kref_put(&ctx->kref, tsem_ns_free); + return; + }Given
ctx->krefis 2, in the below scenariocpu 0 cpu 2 --- --- ctx->kref > 1 ctx->kref > 1 kref_put kref_put
Quoted 8 lines
no work will be scheduled, so it makes sense to move scheduling work to
tsem_ns_free()by makingtsem_ns_put()only a wrapper ofkref_put(), if ctx has to be released in workqueue.void
tsem_ns_put(struct tsem_TMA_context *ctx){ kref_put(&ctx->kref, tsem_ns_free); }
Missed this issue, thank you for pointing it out.
Based on your observations we re-worked the handling of the modeling context reference handling and release and we should have the issue addressed.
In the process we managed to clean up and simplify the implementation as well, always good.
The changes will be in the second version of the patch series.
Quoted 9 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ + INIT_WORK(&ctx->work.work, wq_put); + ctx->work.ctx = ctx; + if (!queue_work(release_wq, &ctx->work.work)) + WARN_ON_ONCE(1); +}PS given
system_unbound_wqandsystem_wqfor instance,release_wqlooks not mandatory if kfree is the major job.
Based on this observation, we also dropped the TSEM specific workqueue and the code is now scheduling the modeling domain release work onto the system_wq queue, given that there is nothing sophisticated about the work that is being scheduled.
This work includes the freeing of the memory for the structure that defines the external modeling context, or in the case of an internally modeled domain, the internal model description state.
In addition, in the case of an externally modeled domain, the workqueue also handles the removal of the securityfs based pseudo-file that surfaces the event descriptions to the trust orchestrator.
The use of the workqueue silences a series of lock debugging complaints about the release of the modeling domain/namespace infrastructure.
Thanks again for your comments, have a good day.
As always,
Dr. Greg
The Quixote Project - Flailing at the Travails of Cybersecurity