History

Merge tag 'lsm-pr-20240911' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm

Pull lsm updates from Paul Moore: - Move the LSM framework to static calls This transitions the vast majority of the LSM callbacks into static calls. Those callbacks which haven't been converted were left as-is due to the general ugliness of the changes required to support the static call conversion; we can revisit those callbacks at a future date. - Add the Integrity Policy Enforcement (IPE) LSM This adds a new LSM, Integrity Policy Enforcement (IPE). There is plenty of documentation about IPE in this patches, so I'll refrain from going into too much detail here, but the basic motivation behind IPE is to provide a mechanism such that administrators can restrict execution to only those binaries which come from integrity protected storage, e.g. a dm-verity protected filesystem. You will notice that IPE requires additional LSM hooks in the initramfs, dm-verity, and fs-verity code, with the associated patches carrying ACK/review tags from the associated maintainers. We couldn't find an obvious maintainer for the initramfs code, but the IPE patchset has been widely posted over several years. Both Deven Bowers and Fan Wu have contributed to IPE's development over the past several years, with Fan Wu agreeing to serve as the IPE maintainer moving forward. Once IPE is accepted into your tree, I'll start working with Fan to ensure he has the necessary accounts, keys, etc. so that he can start submitting IPE pull requests to you directly during the next merge window. - Move the lifecycle management of the LSM blobs to the LSM framework Management of the LSM blobs (the LSM state buffers attached to various kernel structs, typically via a void pointer named "security" or similar) has been mixed, some blobs were allocated/managed by individual LSMs, others were managed by the LSM framework itself. Starting with this pull we move management of all the LSM blobs, minus the XFRM blob, into the framework itself, improving consistency across LSMs, and reducing the amount of duplicated code across LSMs. Due to some additional work required to migrate the XFRM blob, it has been left as a todo item for a later date; from a practical standpoint this omission should have little impact as only SELinux provides a XFRM LSM implementation. - Fix problems with the LSM's handling of F_SETOWN The LSM hook for the fcntl(F_SETOWN) operation had a couple of problems: it was racy with itself, and it was disconnected from the associated DAC related logic in such a way that the LSM state could be updated in cases where the DAC state would not. We fix both of these problems by moving the security_file_set_fowner() hook into the same section of code where the DAC attributes are updated. Not only does this resolve the DAC/LSM synchronization issue, but as that code block is protected by a lock, it also resolve the race condition. - Fix potential problems with the security_inode_free() LSM hook Due to use of RCU to protect inodes and the placement of the LSM hook associated with freeing the inode, there is a bit of a challenge when it comes to managing any LSM state associated with an inode. The VFS folks are not open to relocating the LSM hook so we have to get creative when it comes to releasing an inode's LSM state. Traditionally we have used a single LSM callback within the hook that is triggered when the inode is "marked for death", but not actually released due to RCU. Unfortunately, this causes problems for LSMs which want to take an action when the inode's associated LSM state is actually released; so we add an additional LSM callback, inode_free_security_rcu(), that is called when the inode's LSM state is released in the RCU free callback. - Refactor two LSM hooks to better fit the LSM return value patterns The vast majority of the LSM hooks follow the "return 0 on success, negative values on failure" pattern, however, there are a small handful that have unique return value behaviors which has caused confusion in the past and makes it difficult for the BPF verifier to properly vet BPF LSM programs. This includes patches to convert two of these"special" LSM hooks to the common 0/-ERRNO pattern. - Various cleanups and improvements A handful of patches to remove redundant code, better leverage the IS_ERR_OR_NULL() helper, add missing "static" markings, and do some minor style fixups. * tag 'lsm-pr-20240911' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm: (40 commits) security: Update file_set_fowner documentation fs: Fix file_set_fowner LSM hook inconsistencies lsm: Use IS_ERR_OR_NULL() helper function lsm: remove LSM_COUNT and LSM_CONFIG_COUNT ipe: Remove duplicated include in ipe.c lsm: replace indirect LSM hook calls with static calls lsm: count the LSMs enabled at compile time kernel: Add helper macros for loop unrolling init/main.c: Initialize early LSMs after arch code, static keys and calls. MAINTAINERS: add IPE entry with Fan Wu as maintainer documentation: add IPE documentation ipe: kunit test for parser scripts: add boot policy generation program ipe: enable support for fs-verity as a trust provider fsverity: expose verified fsverity built-in signatures to LSMs lsm: add security_inode_setintegrity() hook ipe: add support for dm-verity as a trust provider dm-verity: expose root hash digest and signature data to LSMs block,lsm: add LSM blob and new LSM hooks for block devices ipe: add permissive toggle ...

Linus Torvalds committed 2 years ago

Commit a430d952 parents ad060db 19c9d5571 files · +6062 −483Browse files

Showing the changes to scripts (5 of 71 files). Show all

Unified · Split

5 files
  1. scripts/Makefile +1 −0
  2. scripts/ipe/Makefile +2 −0
  3. scripts/ipe/polgen/.gitignore +2 −0
  4. scripts/ipe/polgen/Makefile +5 −0
  5. scripts/ipe/polgen/polgen.c +145 −0
scripts/Makefile+1−0
@@ -55,6 +55,7 @@ targets += module.lds · 54 unmodified lines
55subdir-$(CONFIG_GCC_PLUGINS) += gcc-plugins55subdir-$(CONFIG_GCC_PLUGINS) += gcc-plugins
56subdir-$(CONFIG_MODVERSIONS) += genksyms56subdir-$(CONFIG_MODVERSIONS) += genksyms
57subdir-$(CONFIG_SECURITY_SELINUX) += selinux57subdir-$(CONFIG_SECURITY_SELINUX) += selinux
58subdir-$(CONFIG_SECURITY_IPE) += ipe
58 59
59# Let clean descend into subdirs60# Let clean descend into subdirs
60subdir- += basic dtc gdb kconfig mod61subdir- += basic dtc gdb kconfig mod
scripts/ipe/Makefile+2−0
@@ -0,0 +1,2 @@
1# SPDX-License-Identifier: GPL-2.0-only
2subdir-y := polgen
scripts/ipe/polgen/.gitignore+2−0
@@ -0,0 +1,2 @@
1# SPDX-License-Identifier: GPL-2.0-only
2polgen
scripts/ipe/polgen/Makefile+5−0
@@ -0,0 +1,5 @@
1# SPDX-License-Identifier: GPL-2.0
2hostprogs-always-y := polgen
3HOST_EXTRACFLAGS += \
4 -I$(srctree)/include \
5 -I$(srctree)/include/uapi \
scripts/ipe/polgen/polgen.c+145−0
@@ -0,0 +1,145 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2020-2024 Microsoft Corporation. All rights reserved.
4 */
5
6#include <stdlib.h>
7#include <stddef.h>
8#include <stdio.h>
9#include <unistd.h>
10#include <errno.h>
11
12static void usage(const char *const name)
13{
14 printf("Usage: %s OutputFile (PolicyFile)\n", name);
15 exit(EINVAL);
16}
17
18static int policy_to_buffer(const char *pathname, char **buffer, size_t *size)
19{
20 size_t fsize;
21 size_t read;
22 char *lbuf;
23 int rc = 0;
24 FILE *fd;
25
26 fd = fopen(pathname, "r");
27 if (!fd) {
28 rc = errno;
29 goto out;
30 }
31
32 fseek(fd, 0, SEEK_END);
33 fsize = ftell(fd);
34 rewind(fd);
35
36 lbuf = malloc(fsize);
37 if (!lbuf) {
38 rc = ENOMEM;
39 goto out_close;
40 }
41
42 read = fread((void *)lbuf, sizeof(*lbuf), fsize, fd);
43 if (read != fsize) {
44 rc = -1;
45 goto out_free;
46 }
47
48 *buffer = lbuf;
49 *size = fsize;
50 fclose(fd);
51
52 return rc;
53
54out_free:
55 free(lbuf);
56out_close:
57 fclose(fd);
58out:
59 return rc;
60}
61
62static int write_boot_policy(const char *pathname, const char *buf, size_t size)
63{
64 int rc = 0;
65 FILE *fd;
66 size_t i;
67
68 fd = fopen(pathname, "w");
69 if (!fd) {
70 rc = errno;
71 goto err;
72 }
73
74 fprintf(fd, "/* This file is automatically generated.");
75 fprintf(fd, " Do not edit. */\n");
76 fprintf(fd, "#include <linux/stddef.h>\n");
77 fprintf(fd, "\nextern const char *const ipe_boot_policy;\n\n");
78 fprintf(fd, "const char *const ipe_boot_policy =\n");
79
80 if (!buf || size == 0) {
81 fprintf(fd, "\tNULL;\n");
82 fclose(fd);
83 return 0;
84 }
85
86 fprintf(fd, "\t\"");
87
88 for (i = 0; i < size; ++i) {
89 switch (buf[i]) {
90 case '"':
91 fprintf(fd, "\\\"");
92 break;
93 case '\'':
94 fprintf(fd, "'");
95 break;
96 case '\n':
97 fprintf(fd, "\\n\"\n\t\"");
98 break;
99 case '\\':
100 fprintf(fd, "\\\\");
101 break;
102 case '\t':
103 fprintf(fd, "\\t");
104 break;
105 case '\?':
106 fprintf(fd, "\\?");
107 break;
108 default:
109 fprintf(fd, "%c", buf[i]);
110 }
111 }
112 fprintf(fd, "\";\n");
113 fclose(fd);
114
115 return 0;
116
117err:
118 if (fd)
119 fclose(fd);
120 return rc;
121}
122
123int main(int argc, const char *const argv[])
124{
125 char *policy = NULL;
126 size_t len = 0;
127 int rc = 0;
128
129 if (argc < 2)
130 usage(argv[0]);
131
132 if (argc > 2) {
133 rc = policy_to_buffer(argv[2], &policy, &len);
134 if (rc != 0)
135 goto cleanup;
136 }
137
138 rc = write_boot_policy(argv[1], policy, len);
139cleanup:
140 if (policy)
141 free(policy);
142 if (rc != 0)
143 perror("An error occurred during policy conversion: ");
144 return rc;
145}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t