<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/include/linux/lsm_hooks.h, branch v6.19.11</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.19.11</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.19.11'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2025-10-22T23:24:24+00:00</updated>
<entry>
<title>lsm: introduce an initcall mechanism into the LSM framework</title>
<updated>2025-10-22T23:24:24+00:00</updated>
<author>
<name>Paul Moore</name>
<email>paul@paul-moore.com</email>
</author>
<published>2025-02-11T17:18:35+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=cdc028812f727907d1575cf454a5f01ddffa7750'/>
<id>urn:sha1:cdc028812f727907d1575cf454a5f01ddffa7750</id>
<content type='text'>
Currently the individual LSMs register their own initcalls, and while
this should be harmless, it can be wasteful in the case where a LSM
is disabled at boot as the initcall will still be executed.  This
patch introduces support for managing the initcalls in the LSM
framework, and future patches will convert the existing LSMs over to
this new mechanism.

Only initcall types which are used by the current in-tree LSMs are
supported, additional initcall types can easily be added in the future
if needed.

Reviewed-by: Kees Cook &lt;kees@kernel.org&gt;
Reviewed-by: Casey Schaufler &lt;casey@schaufler-ca.com&gt;
Reviewed-by: John Johansen &lt;john.johhansen@canonical.com&gt;
Reviewed-by: Mimi Zohar &lt;zohar@linux.ibm.com&gt;
Signed-off-by: Paul Moore &lt;paul@paul-moore.com&gt;
</content>
</entry>
<entry>
<title>lsm: cleanup the LSM blob size code</title>
<updated>2025-10-22T23:24:21+00:00</updated>
<author>
<name>Paul Moore</name>
<email>paul@paul-moore.com</email>
</author>
<published>2025-02-11T22:49:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=291271e691740003021cf5b48fa7cf7e3371eaa7'/>
<id>urn:sha1:291271e691740003021cf5b48fa7cf7e3371eaa7</id>
<content type='text'>
Convert the lsm_blob_size fields to unsigned integers as there is no
current need for them to be negative, change "lsm_set_blob_size()" to
"lsm_blob_size_update()" to better reflect reality, and perform some
other minor cleanups to the associated code.

Reviewed-by: Kees Cook &lt;kees@kernel.org&gt;
Reviewed-by: John Johansen &lt;john.johansen@canonical.com&gt;
Reviewed-by: Casey Schaufler &lt;casey@schaufler-ca.com&gt;
Reviewed-by: Mimi Zohar &lt;zohar@linux.ibm.com&gt;
Signed-off-by: Paul Moore &lt;paul@paul-moore.com&gt;
</content>
</entry>
<entry>
<title>lsm: get rid of the lsm_names list and do some cleanup</title>
<updated>2025-10-22T23:24:19+00:00</updated>
<author>
<name>Paul Moore</name>
<email>paul@paul-moore.com</email>
</author>
<published>2025-02-13T22:34:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=935d508d4d7ab9d19c603bd7eb2937249551d507'/>
<id>urn:sha1:935d508d4d7ab9d19c603bd7eb2937249551d507</id>
<content type='text'>
The LSM currently has a lot of code to maintain a list of the currently
active LSMs in a human readable string, with the only user being the
"/sys/kernel/security/lsm" code.  Let's drop all of that code and
generate the string on first use and then cache it for subsequent use.

Signed-off-by: Paul Moore &lt;paul@paul-moore.com&gt;
</content>
</entry>
<entry>
<title>lsm: replace the name field with a pointer to the lsm_id struct</title>
<updated>2025-10-22T23:24:18+00:00</updated>
<author>
<name>Paul Moore</name>
<email>paul@paul-moore.com</email>
</author>
<published>2025-02-12T19:45:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=9f9dc69e06ecbc61e7a50b823b82a78daf130dc0'/>
<id>urn:sha1:9f9dc69e06ecbc61e7a50b823b82a78daf130dc0</id>
<content type='text'>
Reduce the duplication between the lsm_id struct and the DEFINE_LSM()
definition by linking the lsm_id struct directly into the individual
LSM's DEFINE_LSM() instance.

Linking the lsm_id into the LSM definition also allows us to simplify
the security_add_hooks() function by removing the code which populates
the lsm_idlist[] array and moving it into the normal LSM startup code
where the LSM list is parsed and the individual LSMs are enabled,
making for a cleaner implementation with less overhead at boot.

Reviewed-by: Kees Cook &lt;kees@kernel.org&gt;
Reviewed-by: John Johansen &lt;john.johansen@canonical.com&gt;
Reviewed-by: Casey Schaufler &lt;casey@schaufler-ca.com&gt;
Reviewed-by: Mimi Zohar &lt;zohar@linux.ibm.com&gt;
Signed-off-by: Paul Moore &lt;paul@paul-moore.com&gt;
</content>
</entry>
<entry>
<title>lsm: split the init code out into lsm_init.c</title>
<updated>2025-10-22T23:24:16+00:00</updated>
<author>
<name>Paul Moore</name>
<email>paul@paul-moore.com</email>
</author>
<published>2025-02-06T21:44:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=67a4b6a89b99aff0883114e4ecba4b11aedc29a5'/>
<id>urn:sha1:67a4b6a89b99aff0883114e4ecba4b11aedc29a5</id>
<content type='text'>
Continue to pull code out of security/security.c to help improve
readability by pulling all of the LSM framework initialization
code out into a new file.

No code changes.

Reviewed-by: Kees Cook &lt;kees@kernel.org&gt;
Reviewed-by: John Johansen &lt;john.johansen@canonical.com&gt;
Reviewed-by: Casey Schaufler &lt;casey@schaufler-ca.com&gt;
Reviewed-by: Mimi Zohar &lt;zohar@linux.ibm.com&gt;
Signed-off-by: Paul Moore &lt;paul@paul-moore.com&gt;
</content>
</entry>
<entry>
<title>lsm,selinux: Add LSM blob support for BPF objects</title>
<updated>2025-08-11T21:56:09+00:00</updated>
<author>
<name>Blaise Boscaccy</name>
<email>bboscaccy@linux.microsoft.com</email>
</author>
<published>2025-07-22T21:21:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=5816bf4273edb32716a88c796e0b04f0e12962eb'/>
<id>urn:sha1:5816bf4273edb32716a88c796e0b04f0e12962eb</id>
<content type='text'>
This patch introduces LSM blob support for BPF maps, programs, and
tokens to enable LSM stacking and multiplexing of LSM modules that
govern BPF objects. Additionally, the existing BPF hooks used by
SELinux have been updated to utilize the new blob infrastructure,
removing the assumption of exclusive ownership of the security
pointer.

Signed-off-by: Blaise Boscaccy &lt;bboscaccy@linux.microsoft.com&gt;
[PM: dropped local variable init, style fixes]
Signed-off-by: Paul Moore &lt;paul@paul-moore.com&gt;
</content>
</entry>
<entry>
<title>lsm: replace indirect LSM hook calls with static calls</title>
<updated>2024-08-22T16:24:10+00:00</updated>
<author>
<name>KP Singh</name>
<email>kpsingh@kernel.org</email>
</author>
<published>2024-08-16T15:43:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=417c5643cd67a55f424b203b492082035d0236c3'/>
<id>urn:sha1:417c5643cd67a55f424b203b492082035d0236c3</id>
<content type='text'>
LSM hooks are currently invoked from a linked list as indirect calls
which are invoked using retpolines as a mitigation for speculative
attacks (Branch History / Target injection) and add extra overhead which
is especially bad in kernel hot paths:

security_file_ioctl:
   0xff...0320 &lt;+0&gt;:	endbr64
   0xff...0324 &lt;+4&gt;:	push   %rbp
   0xff...0325 &lt;+5&gt;:	push   %r15
   0xff...0327 &lt;+7&gt;:	push   %r14
   0xff...0329 &lt;+9&gt;:	push   %rbx
   0xff...032a &lt;+10&gt;:	mov    %rdx,%rbx
   0xff...032d &lt;+13&gt;:	mov    %esi,%ebp
   0xff...032f &lt;+15&gt;:	mov    %rdi,%r14
   0xff...0332 &lt;+18&gt;:	mov    $0xff...7030,%r15
   0xff...0339 &lt;+25&gt;:	mov    (%r15),%r15
   0xff...033c &lt;+28&gt;:	test   %r15,%r15
   0xff...033f &lt;+31&gt;:	je     0xff...0358 &lt;security_file_ioctl+56&gt;
   0xff...0341 &lt;+33&gt;:	mov    0x18(%r15),%r11
   0xff...0345 &lt;+37&gt;:	mov    %r14,%rdi
   0xff...0348 &lt;+40&gt;:	mov    %ebp,%esi
   0xff...034a &lt;+42&gt;:	mov    %rbx,%rdx

   0xff...034d &lt;+45&gt;:	call   0xff...2e0 &lt;__x86_indirect_thunk_array+352&gt;
   			       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    Indirect calls that use retpolines leading to overhead, not just due
    to extra instruction but also branch misses.

   0xff...0352 &lt;+50&gt;:	test   %eax,%eax
   0xff...0354 &lt;+52&gt;:	je     0xff...0339 &lt;security_file_ioctl+25&gt;
   0xff...0356 &lt;+54&gt;:	jmp    0xff...035a &lt;security_file_ioctl+58&gt;
   0xff...0358 &lt;+56&gt;:	xor    %eax,%eax
   0xff...035a &lt;+58&gt;:	pop    %rbx
   0xff...035b &lt;+59&gt;:	pop    %r14
   0xff...035d &lt;+61&gt;:	pop    %r15
   0xff...035f &lt;+63&gt;:	pop    %rbp
   0xff...0360 &lt;+64&gt;:	jmp    0xff...47c4 &lt;__x86_return_thunk&gt;

The indirect calls are not really needed as one knows the addresses of
enabled LSM callbacks at boot time and only the order can possibly
change at boot time with the lsm= kernel command line parameter.

An array of static calls is defined per LSM hook and the static calls
are updated at boot time once the order has been determined.

With the hook now exposed as a static call, one can see that the
retpolines are no longer there and the LSM callbacks are invoked
directly:

security_file_ioctl:
   0xff...0ca0 &lt;+0&gt;:	endbr64
   0xff...0ca4 &lt;+4&gt;:	nopl   0x0(%rax,%rax,1)
   0xff...0ca9 &lt;+9&gt;:	push   %rbp
   0xff...0caa &lt;+10&gt;:	push   %r14
   0xff...0cac &lt;+12&gt;:	push   %rbx
   0xff...0cad &lt;+13&gt;:	mov    %rdx,%rbx
   0xff...0cb0 &lt;+16&gt;:	mov    %esi,%ebp
   0xff...0cb2 &lt;+18&gt;:	mov    %rdi,%r14
   0xff...0cb5 &lt;+21&gt;:	jmp    0xff...0cc7 &lt;security_file_ioctl+39&gt;
  			       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   Static key enabled for SELinux

   0xffffffff818f0cb7 &lt;+23&gt;:	jmp    0xff...0cde &lt;security_file_ioctl+62&gt;
   				^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   Static key enabled for BPF LSM. This is something that is changed to
   default to false to avoid the existing side effect issues of BPF LSM
   [1] in a subsequent patch.

   0xff...0cb9 &lt;+25&gt;:	xor    %eax,%eax
   0xff...0cbb &lt;+27&gt;:	xchg   %ax,%ax
   0xff...0cbd &lt;+29&gt;:	pop    %rbx
   0xff...0cbe &lt;+30&gt;:	pop    %r14
   0xff...0cc0 &lt;+32&gt;:	pop    %rbp
   0xff...0cc1 &lt;+33&gt;:	cs jmp 0xff...0000 &lt;__x86_return_thunk&gt;
   0xff...0cc7 &lt;+39&gt;:	endbr64
   0xff...0ccb &lt;+43&gt;:	mov    %r14,%rdi
   0xff...0cce &lt;+46&gt;:	mov    %ebp,%esi
   0xff...0cd0 &lt;+48&gt;:	mov    %rbx,%rdx
   0xff...0cd3 &lt;+51&gt;:	call   0xff...3230 &lt;selinux_file_ioctl&gt;
   			       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   Direct call to SELinux.

   0xff...0cd8 &lt;+56&gt;:	test   %eax,%eax
   0xff...0cda &lt;+58&gt;:	jne    0xff...0cbd &lt;security_file_ioctl+29&gt;
   0xff...0cdc &lt;+60&gt;:	jmp    0xff...0cb7 &lt;security_file_ioctl+23&gt;
   0xff...0cde &lt;+62&gt;:	endbr64
   0xff...0ce2 &lt;+66&gt;:	mov    %r14,%rdi
   0xff...0ce5 &lt;+69&gt;:	mov    %ebp,%esi
   0xff...0ce7 &lt;+71&gt;:	mov    %rbx,%rdx
   0xff...0cea &lt;+74&gt;:	call   0xff...e220 &lt;bpf_lsm_file_ioctl&gt;
   			       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   Direct call to BPF LSM.

   0xff...0cef &lt;+79&gt;:	test   %eax,%eax
   0xff...0cf1 &lt;+81&gt;:	jne    0xff...0cbd &lt;security_file_ioctl+29&gt;
   0xff...0cf3 &lt;+83&gt;:	jmp    0xff...0cb9 &lt;security_file_ioctl+25&gt;
   0xff...0cf5 &lt;+85&gt;:	endbr64
   0xff...0cf9 &lt;+89&gt;:	mov    %r14,%rdi
   0xff...0cfc &lt;+92&gt;:	mov    %ebp,%esi
   0xff...0cfe &lt;+94&gt;:	mov    %rbx,%rdx
   0xff...0d01 &lt;+97&gt;:	pop    %rbx
   0xff...0d02 &lt;+98&gt;:	pop    %r14
   0xff...0d04 &lt;+100&gt;:	pop    %rbp
   0xff...0d05 &lt;+101&gt;:	ret
   0xff...0d06 &lt;+102&gt;:	int3
   0xff...0d07 &lt;+103&gt;:	int3
   0xff...0d08 &lt;+104&gt;:	int3
   0xff...0d09 &lt;+105&gt;:	int3

While this patch uses static_branch_unlikely indicating that an LSM hook
is likely to be not present. In most cases this is still a better choice
as even when an LSM with one hook is added, empty slots are created for
all LSM hooks (especially when many LSMs that do not initialize most
hooks are present on the system).

There are some hooks that don't use the call_int_hook or
call_void_hook. These hooks are updated to use a new macro called
lsm_for_each_hook where the lsm_callback is directly invoked as an
indirect call.

Below are results of the relevant Unixbench system benchmarks with BPF LSM
and SELinux enabled with default policies enabled with and without these
patches.

Benchmark                                          Delta(%): (+ is better)
==========================================================================
Execl Throughput                                             +1.9356
File Write 1024 bufsize 2000 maxblocks                       +6.5953
Pipe Throughput                                              +9.5499
Pipe-based Context Switching                                 +3.0209
Process Creation                                             +2.3246
Shell Scripts (1 concurrent)                                 +1.4975
System Call Overhead                                         +2.7815
System Benchmarks Index Score (Partial Only):                +3.4859

In the best case, some syscalls like eventfd_create benefitted to about
~10%.

Tested-by: Guenter Roeck &lt;linux@roeck-us.net&gt;
Reviewed-by: Casey Schaufler &lt;casey@schaufler-ca.com&gt;
Reviewed-by: Kees Cook &lt;keescook@chromium.org&gt;
Acked-by: Song Liu &lt;song@kernel.org&gt;
Acked-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Signed-off-by: KP Singh &lt;kpsingh@kernel.org&gt;
Signed-off-by: Paul Moore &lt;paul@paul-moore.com&gt;
</content>
</entry>
<entry>
<title>block,lsm: add LSM blob and new LSM hooks for block devices</title>
<updated>2024-08-20T18:02:33+00:00</updated>
<author>
<name>Deven Bowers</name>
<email>deven.desai@linux.microsoft.com</email>
</author>
<published>2024-08-03T06:08:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=b55d26bd1891423a3cdccf816b386aec8bbefc87'/>
<id>urn:sha1:b55d26bd1891423a3cdccf816b386aec8bbefc87</id>
<content type='text'>
This patch introduces a new LSM blob to the block_device structure,
enabling the security subsystem to store security-sensitive data related
to block devices. Currently, for a device mapper's mapped device containing
a dm-verity target, critical security information such as the roothash and
its signing state are not readily accessible. Specifically, while the
dm-verity volume creation process passes the dm-verity roothash and its
signature from userspace to the kernel, the roothash is stored privately
within the dm-verity target, and its signature is discarded
post-verification. This makes it extremely hard for the security subsystem
to utilize these data.

With the addition of the LSM blob to the block_device structure, the
security subsystem can now retain and manage important security metadata
such as the roothash and the signing state of a dm-verity by storing them
inside the blob. Access decisions can then be based on these stored data.

The implementation follows the same approach used for security blobs in
other structures like struct file, struct inode, and struct superblock.
The initialization of the security blob occurs after the creation of the
struct block_device, performed by the security subsystem. Similarly, the
security blob is freed by the security subsystem before the struct
block_device is deallocated or freed.

This patch also introduces a new hook security_bdev_setintegrity() to save
block device's integrity data to the new LSM blob. For example, for
dm-verity, it can use this hook to expose its roothash and signing state
to LSMs, then LSMs can save these data into the LSM blob.

Please note that the new hook should be invoked every time the security
information is updated to keep these data current. For example, in
dm-verity, if the mapping table is reloaded and configured to use a
different dm-verity target with a new roothash and signing information,
the previously stored data in the LSM blob will become obsolete. It is
crucial to re-invoke the hook to refresh these data and ensure they are up
to date. This necessity arises from the design of device-mapper, where a
device-mapper device is first created, and then targets are subsequently
loaded into it. These targets can be modified multiple times during the
device's lifetime. Therefore, while the LSM blob is allocated during the
creation of the block device, its actual contents are not initialized at
this stage and can change substantially over time. This includes
alterations from data that the LSM 'trusts' to those it does not, making
it essential to handle these changes correctly. Failure to address this
dynamic aspect could potentially allow for bypassing LSM checks.

Signed-off-by: Deven Bowers &lt;deven.desai@linux.microsoft.com&gt;
Signed-off-by: Fan Wu &lt;wufan@linux.microsoft.com&gt;
[PM: merge fuzz, subject line tweaks]
Signed-off-by: Paul Moore &lt;paul@paul-moore.com&gt;
</content>
</entry>
<entry>
<title>lsm: cleanup lsm_hooks.h</title>
<updated>2024-08-12T18:49:37+00:00</updated>
<author>
<name>Paul Moore</name>
<email>paul@paul-moore.com</email>
</author>
<published>2024-07-16T01:22:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=711f5c5ce6c2c640c1b3b569ab2a8847be5ab21f'/>
<id>urn:sha1:711f5c5ce6c2c640c1b3b569ab2a8847be5ab21f</id>
<content type='text'>
Some cleanup and style corrections for lsm_hooks.h.

 * Drop the lsm_inode_alloc() extern declaration, it is not needed.
 * Relocate lsm_get_xattr_slot() and extern variables in the file to
   improve grouping of related objects.
 * Don't use tabs to needlessly align structure fields.

Reviewed-by: Casey Schaufler &lt;casey@schaufler-ca.com&gt;
Signed-off-by: Paul Moore &lt;paul@paul-moore.com&gt;
</content>
</entry>
<entry>
<title>lsm: infrastructure management of the perf_event security blob</title>
<updated>2024-07-29T20:54:52+00:00</updated>
<author>
<name>Casey Schaufler</name>
<email>casey@schaufler-ca.com</email>
</author>
<published>2024-07-10T21:32:30+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=61a1dcdceb44d79e5ab511295791b88ea178c045'/>
<id>urn:sha1:61a1dcdceb44d79e5ab511295791b88ea178c045</id>
<content type='text'>
Move management of the perf_event-&gt;security blob out of the individual
security modules and into the security infrastructure. Instead of
allocating the blobs from within the modules the modules tell the
infrastructure how much space is required, and the space is allocated
there.  There are no longer any modules that require the perf_event_free()
hook.  The hook definition has been removed.

Signed-off-by: Casey Schaufler &lt;casey@schaufler-ca.com&gt;
Reviewed-by: John Johansen &lt;john.johansen@canonical.com&gt;
[PM: subject tweak]
Signed-off-by: Paul Moore &lt;paul@paul-moore.com&gt;
</content>
</entry>
</feed>
