<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/include/linux/lsm_hooks.h, branch v6.12.80</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.12.80</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.12.80'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2024-08-22T16:24:10+00:00</updated>
<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>
<entry>
<title>lsm: infrastructure management of the infiniband 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:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=66de33a0bbb59ef3909d2c65dbbb7fc503d573bd'/>
<id>urn:sha1:66de33a0bbb59ef3909d2c65dbbb7fc503d573bd</id>
<content type='text'>
Move management of the infiniband security blob out of the individual
security modules and into the LSM infrastructure.  The security modules
tell the infrastructure how much space they require at initialization.
There are no longer any modules that require the ib_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, selinux style fixes]
Signed-off-by: Paul Moore &lt;paul@paul-moore.com&gt;
</content>
</entry>
<entry>
<title>lsm: infrastructure management of the dev_tun blob</title>
<updated>2024-07-29T20:54:51+00:00</updated>
<author>
<name>Casey Schaufler</name>
<email>casey@schaufler-ca.com</email>
</author>
<published>2024-07-10T21:32:28+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a39c0f77dbbe083f3eec6c3b32d90f168f7575eb'/>
<id>urn:sha1:a39c0f77dbbe083f3eec6c3b32d90f168f7575eb</id>
<content type='text'>
Move management of the dev_tun security blob out of the individual
security modules and into the LSM infrastructure.  The security modules
tell the infrastructure how much space they require at initialization.
There are no longer any modules that require the dev_tun_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, selinux style fixes]
Signed-off-by: Paul Moore &lt;paul@paul-moore.com&gt;
</content>
</entry>
<entry>
<title>lsm: infrastructure management of the key security blob</title>
<updated>2024-07-29T20:54:51+00:00</updated>
<author>
<name>Casey Schaufler</name>
<email>casey@schaufler-ca.com</email>
</author>
<published>2024-07-10T21:32:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=5f8d28f6d7d568dbbc8c5bce94894474c07afd4f'/>
<id>urn:sha1:5f8d28f6d7d568dbbc8c5bce94894474c07afd4f</id>
<content type='text'>
Move management of the key-&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 existing modules that require a key_free hook, so the call to it and
the definition for it have 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>
<entry>
<title>lsm: infrastructure management of the sock security</title>
<updated>2024-07-29T20:54:50+00:00</updated>
<author>
<name>Casey Schaufler</name>
<email>casey@schaufler-ca.com</email>
</author>
<published>2024-07-10T21:32:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=2aff9d20d50ac45dd13a013ef5231f4fb8912356'/>
<id>urn:sha1:2aff9d20d50ac45dd13a013ef5231f4fb8912356</id>
<content type='text'>
Move management of the sock-&gt;sk_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.

Acked-by: Paul Moore &lt;paul@paul-moore.com&gt;
Reviewed-by: Kees Cook &lt;keescook@chromium.org&gt;
Reviewed-by: John Johansen &lt;john.johansen@canonical.com&gt;
Acked-by: Stephen Smalley &lt;stephen.smalley.work@gmail.com&gt;
Signed-off-by: Casey Schaufler &lt;casey@schaufler-ca.com&gt;
[PM: subject tweak]
Signed-off-by: Paul Moore &lt;paul@paul-moore.com&gt;
</content>
</entry>
<entry>
<title>LSM: syscalls for current process attributes</title>
<updated>2023-11-13T03:54:42+00:00</updated>
<author>
<name>Casey Schaufler</name>
<email>casey@schaufler-ca.com</email>
</author>
<published>2023-09-12T20:56:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a04a1198088a1378d0389c250cc684f649bcc91e'/>
<id>urn:sha1:a04a1198088a1378d0389c250cc684f649bcc91e</id>
<content type='text'>
Create a system call lsm_get_self_attr() to provide the security
module maintained attributes of the current process.
Create a system call lsm_set_self_attr() to set a security
module maintained attribute of the current process.
Historically these attributes have been exposed to user space via
entries in procfs under /proc/self/attr.

The attribute value is provided in a lsm_ctx structure. The structure
identifies the size of the attribute, and the attribute value. The format
of the attribute value is defined by the security module. A flags field
is included for LSM specific information. It is currently unused and must
be 0. The total size of the data, including the lsm_ctx structure and any
padding, is maintained as well.

struct lsm_ctx {
        __u64 id;
        __u64 flags;
        __u64 len;
        __u64 ctx_len;
        __u8 ctx[];
};

Two new LSM hooks are used to interface with the LSMs.
security_getselfattr() collects the lsm_ctx values from the
LSMs that support the hook, accounting for space requirements.
security_setselfattr() identifies which LSM the attribute is
intended for and passes it along.

Signed-off-by: Casey Schaufler &lt;casey@schaufler-ca.com&gt;
Reviewed-by: Kees Cook &lt;keescook@chromium.org&gt;
Reviewed-by: Serge Hallyn &lt;serge@hallyn.com&gt;
Reviewed-by: John Johansen &lt;john.johansen@canonical.com&gt;
Signed-off-by: Paul Moore &lt;paul@paul-moore.com&gt;
</content>
</entry>
<entry>
<title>LSM: Identify modules by more than name</title>
<updated>2023-11-13T03:54:42+00:00</updated>
<author>
<name>Casey Schaufler</name>
<email>casey@schaufler-ca.com</email>
</author>
<published>2023-09-12T20:56:46+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=f3b8788cde61b02f1e6c202f8fac4360e6adbafc'/>
<id>urn:sha1:f3b8788cde61b02f1e6c202f8fac4360e6adbafc</id>
<content type='text'>
Create a struct lsm_id to contain identifying information about Linux
Security Modules (LSMs). At inception this contains the name of the
module and an identifier associated with the security module.  Change
the security_add_hooks() interface to use this structure.  Change the
individual modules to maintain their own struct lsm_id and pass it to
security_add_hooks().

The values are for LSM identifiers are defined in a new UAPI
header file linux/lsm.h. Each existing LSM has been updated to
include it's LSMID in the lsm_id.

The LSM ID values are sequential, with the oldest module
LSM_ID_CAPABILITY being the lowest value and the existing modules
numbered in the order they were included in the main line kernel.
This is an arbitrary convention for assigning the values, but
none better presents itself. The value 0 is defined as being invalid.
The values 1-99 are reserved for any special case uses which may
arise in the future. This may include attributes of the LSM
infrastructure itself, possibly related to namespacing or network
attribute management. A special range is identified for such attributes
to help reduce confusion for developers unfamiliar with LSMs.

LSM attribute values are defined for the attributes presented by
modules that are available today. As with the LSM IDs, The value 0
is defined as being invalid. The values 1-99 are reserved for any
special case uses which may arise in the future.

Cc: linux-security-module &lt;linux-security-module@vger.kernel.org&gt;
Signed-off-by: Casey Schaufler &lt;casey@schaufler-ca.com&gt;
Reviewed-by: Kees Cook &lt;keescook@chromium.org&gt;
Reviewed-by: Serge Hallyn &lt;serge@hallyn.com&gt;
Reviewed-by: Mickael Salaun &lt;mic@digikod.net&gt;
Reviewed-by: John Johansen &lt;john.johansen@canonical.com&gt;
Signed-off-by: Kees Cook &lt;keescook@chromium.org&gt;
Nacked-by: Tetsuo Handa &lt;penguin-kernel@I-love.SAKURA.ne.jp&gt;
[PM: forward ported beyond v6.6 due merge window changes]
Signed-off-by: Paul Moore &lt;paul@paul-moore.com&gt;
</content>
</entry>
</feed>
