Commit Graph
91069 Commits
Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek df03655bc5 resolvectl: convert to VERB_COMMAND 2026-08-13 13:23:05 +02:00
Zbigniew Jędrzejewski-Szmek 580489eeec resolvectl: drop --help for systemd-resolve
The rename was done in v239. We generally don't document obsolete
interfaces, so let's just drop the (very nice) --help that we have here.
2026-08-13 13:23:05 +02:00
Zbigniew Jędrzejewski-Szmek a60c999d5b systemd-backlight: convert to VERB_COMMAND 2026-08-13 13:23:05 +02:00
Zbigniew Jędrzejewski-Szmek c9cd66ee3a backlight: add parse_argv() 2026-08-13 13:23:05 +02:00
Zbigniew Jędrzejewski-Szmek 92462517a1 systemd-ask-password: convert to VERB_COMMAND 2026-08-13 13:23:05 +02:00
Zbigniew Jędrzejewski-Szmek 24acd23d8d systemd-analyze: convert to VERB_COMMAND 2026-08-13 13:23:05 +02:00
Zbigniew Jędrzejewski-Szmek 37e3568236 systemd-ac-power: convert to VERB_COMMAND 2026-08-13 13:23:05 +02:00
Zbigniew Jędrzejewski-Szmek edb15285d0 systemd-veritysetup: convert to VERB_COMMAND
The --help output now shows -h/--help.

"verity protected" is changed to the more correct spelling of
"verity-protected".
2026-08-13 13:23:05 +02:00
Zbigniew Jędrzejewski-Szmek c81b5d36b9 veritysetup: add the usual parse_argv() function
More options will be added later, so let's use the usual
setup.
2026-08-13 13:23:05 +02:00
Zbigniew Jędrzejewski-Szmek d94e88fe14 varlinkctl: convert to VERB_COMMAND
help verb is moved to the end as in most other commands.
2026-08-13 13:23:05 +02:00
Zbigniew Jędrzejewski-Szmek 6566264405 homectl: convert to VERB_COMMAND 2026-08-13 13:23:05 +02:00
Zbigniew Jędrzejewski-Szmek e256153186 verbs: add flags and allow verbs&options tables to not be synchronized 2026-08-13 13:23:05 +02:00
Zbigniew Jędrzejewski-Szmek 7e2ef99cfb timedatectl: convert to VERB_COMMAND 2026-08-13 13:23:05 +02:00
Zbigniew Jędrzejewski-Szmek 0059c3f5f2 verbs: introduce VERB_COMMON_HELP_AUTO{,_HIDDEN} 2026-08-13 13:23:04 +02:00
Zbigniew Jędrzejewski-Szmek 0ebe40080e id128: convert to VERB_COMMAND 2026-08-13 13:23:04 +02:00
Zbigniew Jędrzejewski-Szmek 8616e54872 verbs: add "program header" and generate all help from data
We add a CommandDescription that contains basic info about the program:
- names (the main name and deprecated aliases)
- abstract, man page list, footer
This gets stored as a fake verb entry through VERB_COMMAND macro.

We can then generate the full help for the program from the verbs
and option arrays.

The formatting of man page links is changed from the form used
previously: the section is printed as ".N" instead of "(N)". This
for has the following advantages:
- the form with parenthesis looks like a function call, so e.g. close(1)
  is both a valid call and a man page link.
- the new form can be automatically selected with a double click in the
  typical terminal configurations, while '(' would usually terminate the
  selection area.
- parentheses are special in shell syntax, so even the user manages to
  successfully select and paste them, they still have to add quoting or
  escaping on the command line.
- the new form is shorter
- it looks better
2026-08-13 13:23:04 +02:00
Zbigniew Jędrzejewski-Szmek 4d620b49f5 shared/format-table: add helper to sync widths of a table array 2026-08-13 13:23:04 +02:00
Paul Meyer d66923ea07 test: fix race in TEST-07-PID1 multi-unit transaction subtest
Test failed with the following:

TEST-07-PID1.sh[20020]: + systemctl stop issue8102-nop-dep.service
TEST-07-PID1.sh[20409]: ++ systemctl show -P ActiveState issue8102-nop-dep.service
TEST-07-PID1.sh[20020]: + [[ failed == inactive ]]

systemctl start only waits for the jobs of the units named on the
command line, so the start job pulled in for issue8102-nop-dep.service
via Wants= was not waited for. When the following stop landed while its
ExecStart= was still running, the process was SIGTERMed, and since
Type=oneshot does not treat termination by signal as a clean exit, the
unit ended up failed instead of inactive:

issue8102-nop-dep.service: Changed start -> stop-sigterm
issue8102-nop-dep.service: Main process exited, code=killed, status=15/TERM
issue8102-nop-dep.service: Failed with result 'signal'.

Start both units explicitly so both jobs are waited for.

Signed-off-by: Paul Meyer <katexochen0@gmail.com>
2026-08-13 09:58:53 +01:00
Armaan Sandhu 32ac7af788 strv: treat newlines as hard line breaks in strv_rebreak_lines()
A newline embedded in an input entry only reset the width counter and the
leading-whitespace state, but the text collected before it was never flushed.
If nothing but whitespace followed the newline, the end-of-line path then saw
that we were still in the leading whitespace and emitted an empty line,
dropping everything before the newline: "foo\n" turned into "".

Newlines also didn't start a new output entry, so returned entries could
contain newlines and be wider than the requested width, even though callers
expect one output entry per output line.

Flush the collected line at the newline instead, reusing the same logic as at
the end of the string, and treat a trailing newline as terminating the last
line rather than adding an empty one.
2026-08-13 07:11:49 +09:00
Armaan Sandhu 5dc41f8283 options: reject an empty long option name
An argument of the form "--=VALUE" leaves an empty option name, which
startswith() treats as a prefix of every defined option. Depending on how many
long options a namespace defines that yields either an ambiguity error listing
every option, or, with exactly one option defined, a unique partial match that
silently parses "--=VALUE" as that option.
2026-08-13 07:11:37 +09:00
Yu Watanabe 3ae53ab8f6 analyze: allow --json= for the chid, blame and identify-tpm2 verbs (#43366)
verb_chid(), verb_blame() and verb_identify_tpm2() all render their
output via table_print_with_pager() with arg_json_format_flags, so JSON
output has been implemented for them since each verb was introduced.
None of them was ever added to the verb allowlist
that gates --json=, so e.g. systemd-analyze chid --json=pretty failed
with:

Option --json= is only supported for security, inspect-elf,
dlopen-metadata, ...

This adds them to the allowlist and the error message. After a sweep of
src/analyze/ for arg_json_format_flags, these are the only remaining
verbs that render through it but were not allowlisted.

has-tpm2 is deliberately not included: verb_has_tpm2() defers to
verb_has_tpm2_generic(), which writes plain text via printf() and has no
JSON support, so accepting --json= there would silently ignore it. The
table_print_with_pager() call in analyze-has-tpm2.c
belongs to verb_identify_tpm2(), which is what got allowlisted instead.

The chid gap went unnoticed because its TEST-65-ANALYZE coverage is
guarded behind a check for SMBIOS board_vendor and a non-container
environment, so it only runs on bare-metal/VM runners.
2026-08-13 00:06:07 +09:00
Luca Boccassi aec25f2770 Two HWDB fixes (#43367) 2026-08-12 15:12:58 +01:00
David Tardon 1d75afb798 hwdb: fix modalias
This line matches only if svn is the first field, but DMI modaliases
normally begin with BIOS fields such as bvn/bvr/bd. Use a wildcard like
other similar entries in the file.

Follow-up-for: 0aaea4b376
2026-08-12 13:30:36 +02:00
David Tardon ef3a8760cc hwdb: fix modalias
I'm not sure if these leading zeros matter or not, but the description
at the top of the file clearly says that the numbers are 4-digit. The
author of this entry also mentions evdev:input:b0003v1020p0501* in the
PR that added it.

Follow-up-for: 4ae4470ad9
2026-08-12 12:57:42 +02:00
Ivan Kruglov 46a91a1867 test: cover --json= for the blame and identify-tpm2 verbs
Both verbs render through arg_json_format_flags but --json= was rejected for
them until the previous commit, and nothing in TEST-65-ANALYZE exercised it.
Add coverage in line with the other JSON-capable verbs.

identify-tpm2 is only invoked when has-tpm2 reports full support, as it
fails with EOPNOTSUPP when built without TPM2 support.
2026-08-12 03:54:33 -07:00
Ivan Kruglov b3f76af401 shell-completion: offer --json= for the standalone verbs that support it
Several verbs in the STANDALONE bucket accept --json=, but that bucket only
offers --help --version --system --user --global --no-pager, so completion
never suggested the option for them.

Split those verbs out into a new STANDALONE_JSON bucket that additionally
offers --json=off/pretty/short. The verbs are moved rather than copied, as
${VERBS[*]} is used to complete the verb list itself.
2026-08-12 03:54:10 -07:00
Ivan Kruglov 9b16161f34 analyze: allow --json= for the chid, blame and identify-tpm2 verbs
verb_chid(), verb_blame() and verb_identify_tpm2() all render their output
via table_print_with_pager() with arg_json_format_flags, so JSON output has
been implemented for them since they were introduced. However, none of them
was ever added to the verb allowlist that gates --json=, so e.g.
"systemd-analyze chid --json=pretty" failed with:

Option --json= is only supported for security, inspect-elf, ...

Add them to the allowlist (and the error message) so the option is accepted.
These are the only remaining verbs that render through arg_json_format_flags
but were not allowlisted.

Note that has-tpm2 is deliberately not included: verb_has_tpm2() defers to
verb_has_tpm2_generic(), which writes plain text via printf() and has no JSON
support, so accepting --json= there would silently ignore it.

This went unnoticed for chid because the TEST-65-ANALYZE coverage for it is
guarded behind a check for SMBIOS board_vendor and a non-container
environment, so it only runs on bare-metal/VM runners.
2026-08-12 03:53:42 -07:00
dongshengyuan 628e8304cc resolved: notice route-only domain updates
SetLinkDomains() tracks whether the configured search domain list changed
so it can skip redundant persistence. The route_only flag is part of the
D-Bus API and is persisted as a ~ prefix, but flipping an existing domain
between search and route-only only updated in-memory state and left
changed false. The method then skipped link_save_user() and
manager_write_resolv_conf(), leaving stale state until restart.

Reproduced on Ubuntu with systemd 259:

  sudo resolvectl domain enp1s0 route-only-repro.test
  sudo resolvectl domain enp1s0 '~route-only-repro.test'
  resolvectl domain enp1s0
  grep '^DOMAINS=' /run/systemd/resolve/netif/$(cat /sys/class/net/enp1s0/ifindex)
  grep -H route-only-repro.test /run/systemd/resolve/*.conf

Before, resolvectl showed ~route-only-repro.test, but the persisted state
file still showed DOMAINS=route-only-repro.test, and the generated
resolv.conf files still contained search route-only-repro.test.

After this change, the state file is updated to
DOMAINS=~route-only-repro.test and the generated resolv.conf files are
refreshed so the route-only domain is not emitted as a search domain.

Follow-up for: cbf23f3853
2026-08-12 18:51:34 +09:00
Timon de Groot 40315add91 hwdb: add Blue Microphones Yeti X (#43363)
This microphone has vendor specific HID controls to control gain,
output, monitoring levels, polar patterns, etc.

Naming is completely based on names reported by the USB device itself
(`manufacturer` and `product`).

Information about this microphone:
- https://micpedia.com/microphone/blue-yeti-x/
- https://www.logitechg.com/en-us/shop/p/yeti-x-professional-microphone
2026-08-12 06:57:38 +09:00
zhaoshuang abffa868a8 virt: detect Alibaba Cloud ECS as KVM
Alibaba Cloud ECS instances expose "Alibaba Cloud ECS" in DMI
product_name/bios_vendor and "Alibaba Cloud" in sys_vendor. None of
these match dmi_vendor_table[], so systemd-detect-virt --vm reports
"none" on these machines, even though they run on a KVM-based
hypervisor. This is especially visible on ARM64 instances, where the
CPUID fallback does not exist (x86 only) and /proc/device-tree is
not populated.

Add "Alibaba Cloud ECS" to dmi_vendor_table[], mapping to
VIRTUALIZATION_KVM. The narrower prefix avoids matching the bare
"Alibaba Cloud" sys_vendor value, reducing the false-positive
surface for Alibaba's bare-metal (X-Dragon) instances compared to
the original broader prefix. bios_vendor also carries the same
string on ECS VMs though, so the protection is not complete —
fully resolving the VM-vs-bare-metal ambiguity would need the
SMBIOS BIOS-Characteristics bit check that the Amazon EC2 entry
uses.

The existing "back to DMI" fallback path in detect_vm() reports
"kvm" on both x86 and ARM64.
2026-08-12 04:12:19 +09:00
dongshengyuan e98c68104b core: do not chown fd-passed TTYs
When stdio is passed as file descriptors, the provider of those
descriptors remains responsible for their ownership and access mode.

This keeps run0 in a pipeline from changing the caller's TTY ownership
to the target user, which can otherwise break later terminal access from
the original user.

Fixes #43336
2026-08-12 03:11:02 +09:00
dongshengyuan e8454eb14c detect-virt: continue parsing after --cvm
--cvm is a mode switch, so it must not stop option parsing.
Keep parsing after it to honor later options and validate arguments.

Before: --cvm --quiet printed none; --cvm unexpected-argument printed none.
After: --cvm --quiet prints nothing; extra arguments are rejected.

Follow-up for: 5e0c61f64d
2026-08-12 03:02:33 +09:00
dongshengyuan f40aa8ea1c vpick: terminate tries output with newline
tries should be line-oriented like the other --print= modes.
Terminate its counter output with a newline to avoid glued CLI output.

Before: output bytes were 2b 32 2d 33.
After: output bytes are 2b 32 2d 33 0a.

Follow-up for: 9e61ed1115
2026-08-12 03:02:33 +09:00
Yu Watanabe 4443d0ec16 Fix error paths for pcrextend_pcr_now and pkcs7_extract_signers (#43357)
- pcrextend: Fix use-after-free/double-free error in pcrextend_pcr_now

  With SignInitrdPCRs=disabled in mkosi the TPM/PCR services are broken
which triggers the error path in the varlink call which means that we
get parameters set in the response. The wrong ownership assumption when
looking at the reply with _cleanup_ set caused a memory corruption that
surfaced in systemd-sysext with an ABRT.
This is a common mistake done with the API, fix it by not setting
_cleanup_(sd_json_variant_unrefp).

- pkcs7: Correct error handling for pkcs7_extract_signers

  The lack of error handling for sym_i2d_X509_NAME/sym_i2d_ASN1_INTEGER
means that we get a NULL iovec that will cause an assertion failure
later. The use of regular free for OpenSSL is probably okay but since
the allocator can differ, one should use OPENSSL_free.
Add error handling and do an explicit copy instead of ownership transfer
between possibly different allocators.
2026-08-12 02:48:51 +09:00
Luca Boccassi 8271442983 test: drop forgotten set +e (#43359)
This was introduced all the way back in 2019 where this particular test
case was the last one in the file, so it worked as intended.
Unfortunately, since then we added new tests after this one, which means
this particular `set +e` masked fails in any of them (except for
assert_*() calls, which call exit on fail).
2026-08-11 17:40:25 +01:00
Frantisek Sumsal ed0727fecd test: sync the journal before checking it for ordering cycle messages
Otherwise we might get an empty match:

TEST-03-JOBS.sh[100]: + IDS_FILE=/tmp/TEST-03-JOBS-CYCLE-IDS-30241
TEST-03-JOBS.sh[314]: + varlinkctl call /run/systemd/io.systemd.Manager io.systemd.Manager.Describe '{}'
TEST-03-JOBS.sh[315]: + jq .runtime.TransactionsWithOrderingCycle
TEST-03-JOBS.sh[316]: ++ jq length /tmp/TEST-03-JOBS-CYCLE-IDS-30241
TEST-03-JOBS.sh[100]: + [[ 20 -ge 20 ]]
TEST-03-JOBS.sh[100]: + for i in {0..19}
TEST-03-JOBS.sh[317]: ++ jq -r '.[0]' /tmp/TEST-03-JOBS-CYCLE-IDS-30241
TEST-03-JOBS.sh[100]: + journalctl -b TRANSACTION_ID=48 --grep 'cycle starting with'
TEST-03-JOBS.sh[318]: -- No entries --
[FAILED] Failed to start TEST-03-JOBS.service - TEST-03-JOBS.
[  !!  ] Exiting: unit TEST-03-JOBS.service failed

Even though the message was properly emitted:

$ journalctl --file TEST-03-JOBS-1.journal -b TRANSACTION_ID=48 --grep 'cycle starting with'
Aug 11 14:46:15 H systemd[1]: [🡕] transaction-cycle17.service: Unable to break cycle starting with transaction-cycle17.service/start
2026-08-11 16:12:42 +02:00
Frantisek Sumsal 143c284567 test: drop forgotten set +e
This was introduced all the way back in 2019 where this particular test
case was the last one in the file, so it worked as intended.
Unfortunately, since then we added new tests after this one, which means
this particular `set +e` masked fails in any of them (except for
assert_*() calls, which call exit on fail).
2026-08-11 16:12:42 +02:00
Frantisek Sumsal 2c4e86c290 test: fix & enhance test for RestartMode=
Stay `set +e` in the test masked that this test has apparently never
worked in the first place: when a unit is killed with a signal, any
bound unit is stopped retroactively via
retroactively_stop_dependencies() but it's not restarted again, as the
restart for the bound unit is queued as TRY_RESTART in a following
transaction - but at this point the bound unit is already inactive, so
the TRY_RESTART job collapses into a NOP.

Let's account for this and also add a couple of test cases for
RestartMode= with an explicit restart, which should trigger the bound
unit as well (assuming it's active).

Follow-up for 9b42c58a2b.
2026-08-11 16:11:25 +02:00
Christian Brauner 0b2d1203cb bpf-restrict-fsaccess: allow execution from overlayfs on signed dm-verity (#43223)
RestrictFileSystemAccess= currently denies execution from any overlayfs
  mount, even when every layer sits on a signed dm-verity device. The
enforcement hooks compare file->f_inode->i_sb->s_dev against the map of
  trusted devices and for a file on an overlay that's the overlay's own
  anonymous device, never the backing block device. So the fairly common
  image based setup where a signed DDI is the lower layer and a writable
  upper is stacked on top of it is out.

Kernel v7.2 grew the bpf_real_data_inode() kfunc which resolves a file
to
the inode hosting its data. Use it from the two enforcement hooks that
get
to see the union-level file. Execution through such an overlay then
works
  while anything whose data lives in an untrusted upper layer is still
  denied.

  All of it is gated on kernel support. The kfunc is a __weak __ksym and
every call sits behind a const volatile .rodata flag that PID1 only sets
when the kernel BTF advertises the function, so the object still loads
on
older kernels and keeps denying union filesystems exactly like before.
If
loading with resolution enabled fails anyway the loader retries with the
  flag off. A setup failure here is fatal to PID1 startup and I'd rather
  degrade than not boot.

  Two things worth pointing out. The mmap_file hook matters more than it
  looks like. binfmt_elf maps the PT_INTERP interpreter via vm_mmap() so
  ld.so is only ever checked there and never by bprm_check_security. And
  file_mprotect deliberately doesn't use the kfunc. It runs under
  mmap_write_lock where sleeping in d_real() would invert the documented
i_rwsem -> mmap_lock order, and it doesn't need it anyway since
ovl_mmap()
  has already installed the backing file into vma->vm_file by then.
  
   Known limitations:

    * With metacopy=on an untrusted upper layer can still own a trusted
      binary's mode, ownership and setuid bits since the resolution only
follows the data. Documented in the man page, just don't build that.

    * composefs with a separate data directory isn't covered. That needs
fs-verity digests and bpf_get_fsverity_digest() takes a struct file
      and gets the overlay inode, so it doesn't compose with this today.

    * erofs page cache sharing is denied. The inode comes from a pseudo
      filesystem whose s_dev is never in the verity map.

    * Multi-device filesystems like btrfs stay unsupported, as before.
    
    Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-08-11 14:31:25 +02:00
Kai Lüke 76a6dc6dc0 pcrextend: Fix use-after-free/double-free error in pcrextend_pcr_now
With SignInitrdPCRs=disabled in mkosi the TPM/PCR services are broken
which triggers the error path in the varlink call which means that we
get parameters set in the response. The wrong ownership assumption when
looking at the reply with _cleanup_ set caused a memory corruption that
surfaced in systemd-sysext with an ABRT.
This is a common mistake done with the API, fix it by not setting
_cleanup_(sd_json_variant_unrefp).
2026-08-11 20:35:57 +09:00
Kai Lüke a257de2688 pkcs7: Correct error handling for pkcs7_extract_signers
The lack of error handling for sym_i2d_X509_NAME/sym_i2d_ASN1_INTEGER
means that we get a NULL iovec that will cause an assertion failure
later. The use of regular free for OpenSSL is probably okay but since
the allocator can differ, one should use OPENSSL_free.
Add error handling and do an explicit copy instead of ownership transfer
between possibly different allocators.
2026-08-11 20:31:00 +09:00
Frantisek Sumsal 2b81535f74 test: fix typo in test unit
Follow-up for bf3dfa6202.
2026-08-11 12:40:53 +02:00
Kakueeen 9b75d9bc66 cgtop: use dynamic width for CPU% column (#43286)
On many-CPU hosts, the CPU% column in systemd-cgtop can exceed the
hardcoded %6.1f format width (e.g. 12769.4% on a 128-CPU host),
causing column overflow and table misalignment.

Follow the existing maxtcpu pattern for CPU Time: dynamically compute
the maximum width of CPU percentage values and use it for both the
header and data rows.

Fixes #39819
2026-08-11 00:38:17 +09:00
Christian Brauner 7849500cd9 mkosi: install bpftool in Debian/Ubuntu test images
The centos-fedora, opensuse and postmarketos image configurations all
install bpftool but the Debian/Ubuntu ones never did. Only their build
image gets it via the packaging's Build-Depends. So the
TEST-90-RESTRICT-FSACCESS guard and overlay subtests, both gated on
'command -v bpftool', just silently skip there.

Mirror what the build image does. Plain bpftool everywhere except Ubuntu
jammy and noble which still bundle it in linux-tools-generic.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-08-10 16:09:06 +02:00
Christian Brauner 24bbacbe7a man: document union filesystem resolution for RestrictFileSystemAccess=
Replace the paragraph that claims overlayfs is always blocked. Mention
that only the file data is checked, keep the btrfs note and mention the
new behavior in NEWS.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-08-10 16:09:06 +02:00
Christian Brauner 8c199d4f1a test: cover overlayfs in TEST-90-RESTRICT-FSACCESS
Have the attach helper print whether the loader enabled union filesystem
resolution and assert that this agrees with the kernel BTF.

Then mount the signed minimal image as an overlayfs lower layer with a
tmpfs upper. On kernels with bpf_real_data_inode() executing through the
overlay works while a file created in the upper layer or copied up into
it is denied. Without the kfunc execution through the overlay is denied
outright.

The overlay uses metacopy=off so that the copy-up test really does move
the data over to the untrusted upper layer.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-08-10 16:09:06 +02:00
Christian Brauner e37151765f core: gate bpf_real_data_inode() use on kernel support
Probe the kernel BTF for bpf_real_data_inode() and set the BPF program's
.rodata flag accordingly. The flag has to be written for every open of
the skeleton because .rodata is frozen once the object is loaded, so fold
the two open and load attempts into a common helper.

A positive BTF probe isn't a guarantee. It tells us that the function
exists, not that it is registered as an LSM kfunc with the signature we
expect. So if loading with resolution enabled fails anyway, retry with
the flag off. Files on union filesystems are then denied like they were
before which is a lot better than turning kernel drift into a boot
failure.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-08-10 16:09:06 +02:00
Christian Brauner cc54fb8f73 bpf-util: add helper to probe the kernel for a kfunc
Add bpf_kernel_has_kfunc() which checks whether the kernel's vmlinux BTF
advertises a function of a given name.

The three btf__* symbols it needs are optional in the dlopen table.
btf__load_vmlinux_btf() only exists since libbpf 0.5 and a libbpf that
lacks any of them should degrade this probe, not fail dlopen_bpf() and
with it all of BPF. Note, libbpf < 1.0 returns error pointers instead of
NULL, so the result is checked with bpf_get_error_translated().

Finding the name doesn't tell us all that much though. It tells us that
the function exists, not that it is registered as a kfunc for the program
type we care about. So callers still have to be prepared for the program
load to fail.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-08-10 16:09:06 +02:00
Christian Brauner 43914520c1 bpf-restrict-fsaccess: resolve union filesystems to the device hosting the data
Execution from an overlayfs mount is currently denied even when every
layer sits on a signed dm-verity device. The hooks compare
file->f_inode->i_sb->s_dev against the map of trusted devices and for a
file on an overlay that's the overlay's own anonymous device, never the
backing block device.

Kernel v7.2 grew the bpf_real_data_inode() kfunc which resolves a file to
the inode hosting its data. Use it from bprm_check_security and mmap_file
which both get to see the union-level file. They become lsm.s/ programs
because the kfunc is sleepable. That doesn't raise our kernel
requirements, both have been in sleepable_lsm_hooks since v5.11.

The file_mprotect hook stays non-sleepable. It runs under mmap_write_lock
where sleeping in d_real() would invert the documented i_rwsem ->
mmap_lock order, and it doesn't need the kfunc anyway. By the time a vma
exists ovl_mmap() has already installed the backing file into
vma->vm_file.

The initramfs trust window keeps comparing the mount device. If the
initrd is itself a union mount then userspace only ever recorded the
union's anonymous s_dev. The verity map is keyed by block device so that
one gets compared against the resolved device.

The kfunc is declared __weak __ksym and every call is gated on a const
volatile .rodata flag that PID1 only sets when the kernel provides it. So
the object still loads on pre-7.2 kernels where files on union
filesystems are denied as before. The flag stays off until the loader
learns to set it in a followup.

The file argument of bpf_lsm_mmap_file() is annotated __nullable since
v7.0 so the verifier won't let us hand it to the kfunc unless we branch
on it first.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-08-10 16:09:06 +02:00
Christian Brauner 060628d332 bpf-restrict-fsaccess: use direct field access for trusted pointers
The bprm_check_security and file_mprotect hooks currently fetch the file
pointer with BPF_CORE_READ_INTO(), i.e. bpf_probe_read_kernel(). That
hands us back a plain scalar and since 1a5c01d2508a ("bpf: Make
KF_TRUSTED_ARGS the default for all kfuncs") in v7.0 such a pointer can't
be passed to a kfunc at all.

Dereference the fields directly instead. Both bprm->file and vma->vm_file
are in the verifier's BTF_TYPE_SAFE_TRUSTED(_OR_NULL) lists so the loads
give us PTR_TRUSTED registers, and vmlinux.h pushes preserve_access_index
for all records so we don't lose CO-RE.

No functional changes. This is just so we can hand the pointers to the
bpf_real_data_inode() kfunc in the next patch.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-08-10 16:09:06 +02:00