Commit Graph
4017 Commits
Author SHA1 Message Date
Dan Streetman 2eea1b8f2f tpm2: add test to verify srk templates
Verify the tpm2_get_srk_template() and tpm2_get_best_srk_template() functions
work as expected.
2023-11-07 10:59:44 -05:00
Dan Streetman 788933379d tpm2: allow using tpm2_get_srk_template() without tpm
The SRK templates are defined by specification, so move the check for TPM
support to the tpm2_get_best_srk_template() function, and allow anyone to get
the ECC and RSA templates.

Also add test to verify the SRK templates are correct.
2023-11-07 10:59:44 -05:00
Lennart Poettering 67a3028555 json: teach dispatch logic to also take numbers formatted as strings
JSON famously is problematic with integers beyond 53 bits, because
JavaScript stores everything in double precision floating points.
Various implementations in other languages can deal with signed 64 bit
integers, and a few can deal with unsigned 64bit too (like ours).

Typically program that need more then 53 bit of accuracy encode integers
as decimal strings, to make sure that even if consumers can't really
process larger values they at least won't corrupt the data while passing
it along. This is also recommended by JSON-I (RFC 7493)

To maximize compatibility with other implementations let's add 1st class
parsing support for such objects in the json_dispatch() API.

This makes json_dispatch_uint64() and related calls parse such
integers-formatted-as-decimal-strings as uint64_t. This logic will only
be enabled if the "type" field of JsonDispatch is left unspecified (i.e.
set to negative/_JSON_VARIANT_TYPE_INVALID) though, hence alone does not
change anything in effect.

This purely is about consuming such values, whether we should genreate
them also is a discussion for a separate PR.
2023-11-07 14:25:40 +01:00
Luca Boccassi 93c2d8d5c4 test: fix build without SBAT_DISTRO
Follow-up for c9bebec872
2023-11-06 19:05:47 +00:00
Lennart Poettering fd81692f4b test: add test for the combined base64/base64url decoder 2023-11-03 21:35:28 +01:00
Lennart Poettering a434270139 pcrlock: add new pcrlock tool 2023-11-03 11:23:54 +01:00
Frantisek Sumsal 69d17e23db varlink: limit the maximum nesting depth
Let's limit the maximum nesting depth for structure definitions to 64 to
avoid stack overflows with very deep definitions.

Resolves: #29589
2023-11-02 20:43:38 +00:00
Lennart Poettering 3b516db71d glyph-util: add computer disk + world emoji 2023-11-02 14:19:32 +01:00
Lennart Poettering e5f1e8b894 lock-util: add a new lock_generic_with_timeout() helper
This is just like lock_generic(), but applies the lock with a timeout.
This requires jumping through some hoops by executing things in a child
process, so that we can abort if necessary via a timer. Linux after all
has no native way to take file locks with a timeout.
2023-11-02 14:19:32 +01:00
Lennart Poettering e9ccae3135 process-util: add new FORK_DEATHSIG_SIGKILL flag, rename FORK_DEATHSIG → FORK_DEATHSIG_SIGTERM
Sometimes it makes sense to hard kill a client if we die. Let's hence
add a third FORK_DEATHSIG flag for this purpose: FORK_DEATHSIG_SIGKILL.

To make things less confusing this also renames FORK_DEATHSIG to
FORK_DEATHSIG_SIGTERM to make clear it sends SIGTERM. We already had
FORK_DEATHSIG_SIGINT, hence this makes things nicely symmetric.

A bunch of users are switched over for FORK_DEATHSIG_SIGKILL where we
know it's safe to abort things abruptly. This should make some kernel
cases more robust, since we cannot get confused by signal masks or such.

While we are at it, also fix a bunch of bugs where we didn't take
FORK_DEATHSIG_SIGINT into account in safe_fork()
2023-11-02 14:09:23 +01:00
Lennart Poettering f1b622a00c varlink,json: introduce new varlink_dispatch() helper
varlink_dispatch() is a simple wrapper around json_dispatch() that
returns clean, standards-compliant InvalidParameter error back to
clients, if the specified JSON cannot be parsed properly.

For this json_dispatch() is extended to return the offending field's
name. Because it already has quite a few parameters, I then renamed
json_dispatch() to json_dispatch_full() and made json_dispatch() a
wrapper around it that passes the new argument as NULL. While doing so I
figured we should also get rid of the bad= argument in the short
wrapper, since it's only used in the OCI code.

To simplify the OCI code this adds a second wrapper oci_dispatch()
around json_dispatch_full(), that fills in bad= the way we want.

Net result: instead of one json_dispatch() call there are now:

1. json_dispatch_full() for the fully feature mother of all dispathers.
2. json_dispatch() for the simpler version that you want to use most of
   the time.
3. varlink_dispatch() that generates nice Varlink errors
4. oci_dispatch() that does the OCI specific error handling

And that's all there is.
2023-11-02 01:19:21 +00:00
Arseny MaslennikovandMike Yuan c21566d90b basic/missing_syscall: add missing_fchmodat2()
Follow-up for 8b45281daa
and preparation for later commits.

Since libcs are more interested in the POSIX `fchmodat(3)`, they are
unlikely to provide a direct wrapper for this syscall. Thus, the headers
we examine to set `HAVE_*` are picked somewhat arbitrarily.

Also, hook up `try_fchmodat2()` in `test-seccomp.c`. (Also, correct that
function's prototype, despite the fact that mistake would not matter in
practice)

Co-authored-by: Mike Yuan <me@yhndnzj.com>
2023-11-02 00:23:12 +08:00
Lennart Poettering 9c21cfdd7d chase: fix corner case when using CHASE_PARENT with a path ending in ".."
If we use CHASE_PARENT on a path ending in ".." then things are a bit
weird, because we the last path we look at is actually the *parent* and not
the *child* of the preceeding path. Hence we cannot just return the 2nd
to last fd we look at. We have to correct it, by going *two* levels up,
to get to the actual parent, and make sure CHASE_PARENT does what it
should.

Example: for the path /a/b/c chase() with CHASE_PARENT will return
/a/b/c as path, and the fd returned points to /a/b. All good.  But now,
for the path /a/b/c/.. chase() with CHASE_PARENT would previously return
/a/b as path (which is OK) but the fd would point to /a/b/c, which is
*not* the parent of /a/b, after all! To get to the actual parent of
/a/b we have to go *two* levels up to get to /a.

Very confusing. But that's what we here for, no?

@mrc0mmand ran into this in https://github.com/systemd/systemd/pull/28891#issuecomment-1782833722
2023-11-01 14:43:24 +00:00
Luca Boccassi 7c2fd96dba Merge pull request #29764 from dtardon/varlink-io.systemd.service
Add varlink interface io.systemd.service
2023-11-01 14:41:58 +00:00
Lennart Poettering 553a596ad9 Merge pull request #29763 from yuwata/vconsole-conf
locale,firstboot: add comments to vconsole.conf
2023-10-31 14:37:47 +01:00
David Tardon 4ffe0aedf9 varlink: define interface io.systemd.service 2023-10-31 12:49:16 +01:00
Yu Watanabe f155cb6d75 env-util: make write_env_file() optionally take headers
This also makes write_env_file() and write_env_file_label() optionally
take dir_fd, and drop write_env_file_at().

Preparation for later commits.
2023-10-31 17:15:21 +09:00
Yu Watanabe 84a594f4b3 tests: use log_tests_skipped() and friend more 2023-10-31 14:54:27 +09:00
Yu Watanabe d19434fbf8 tree-wide: fix typo 2023-10-31 14:35:33 +09:00
Frantisek Sumsal b0bb3be130 core: don't insert an extra space before each SocketBind{Allow,Deny}= item
The extra space was actually screwing up deserialization:

~# systemd-run --wait --pipe -p SocketBindAllow=any true
Running as unit: run-u167.service
Finished with result: exit-code
Main processes terminated with: code=exited/status=234
Service runtime: 1ms
CPU time consumed: 0
~# journalctl -b -p err
...
Oct 27 16:39:15 arch systemd-executor[5983]: Failed to deserialize: Invalid argument

Let's not do that by default and introduce a simple wrapper which
inserts the space after each item only when necessary.
2023-10-27 20:08:47 +02:00
Lennart Poettering 7113640493 fd-uitl: rename PIPE_EBADF → EBADF_PAIR, and add EBADF_TRIPLET
We use it for more than just pipe() arrays. For example also for
socketpair(). Hence let's give it a generic name.

Also add EBADF_TRIPLET to mirror this for things like
stdin/stdout/stderr arrays, which we use a bunch of times.
2023-10-26 22:30:42 +02:00
Luca Boccassi b44a72da57 Merge pull request #29711 from berrange/tests-silverblue
Fix test suite when developing on Fedora SilverBlue (rpm-ostree) host
2023-10-26 21:17:03 +01:00
Richard Maw 31cfcf5008 test: Skip test-recurse-dir on overlayfs 2023-10-26 19:11:21 +01:00
Daniel P. Berrangé 6aa77f9284 test-blockdev-util: avoid abort when /home is a symlink
On rpm-ostree distributions like Fedora SilverBlue /home (and various
other well known locations) are symlinks to somewhere beneath /var.

The path_is_encrypted() method uses O_NOFOLLOW and as a result will
return ELOOP on /home. This causes test-blockdev-util to abort.
Add ELOOP to the ignorable set of errnos for testing.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-10-26 14:46:15 +01:00
Luca Boccassi 7470e161cf Merge pull request #29553 from keszybz/analyze-cat-config-tldr
analyze/cat-config: add switch to print only "interesting" parts of conffiles
2023-10-25 09:53:19 +01:00
Luca Boccassi e5cd8bc060 Merge pull request #29601 from yuwata/mmap-check-overflow
mmap: check offset and size more carefully
2023-10-24 12:20:04 +01:00
Lennart Poettering 24aeaf4e7f glyph-util: add 'full block' glyph 2023-10-23 11:24:35 +01:00
Lennart Poettering b98c4f1d48 tpm2-util: rename tpm2_calculate_name() → tpm2_calculate_pubkey_name()
We'll soon have a function for determining the name of an NV index,
hence let's rename the existing function for the same of a public key to
make clear it's about public keys only.
2023-10-21 19:34:55 +01:00
Mike Yuan a0f6d74ec8 sleep-config: introduce sleep_supported_full that returns a reason
Preparation for later commits.

Also some other cleanups:
* Add assertions
* Use FOREACH_ARRAY
2023-10-20 23:22:28 +08:00
Mike Yuan 23577f4462 sleep-config: minor cleanup for can_sleep_{state,disk}
* Rename to sleep_{state,mode}_supported
* Treat unreadable/unwriable sysfs files as error
2023-10-20 23:22:28 +08:00
Mike Yuan d12babb574 test-btrfs-physical-offset: log correct errno 2023-10-20 23:22:28 +08:00
Luca Boccassi beea591742 Merge pull request #29627 from poettering/io-split
split up io-util.[ch], and some clean-ups
2023-10-20 12:19:22 +01:00
Luca Boccassi ed51ccf4b8 Merge pull request #29618 from bonktree/fchmodat2
seccomp: get `fchmodat2(2)` covered by `RestrictSUIDSGID=`
2023-10-20 10:49:46 +01:00
Lennart Poettering ea1f38146a io-util: split out iovw_xyz into iovec-wrapper.h
Let's split these APIs out, they are kinda their own thing.
2023-10-20 10:43:50 +02:00
Lennart Poettering bd1ae17833 io-util: split out "struct iovec" related calls into their own .c/.h files
This is preparation for #28891, which adds a bunch more helpers around
"struct iovec", at which point this really deserves its own .c/.h file.

The idea is that we sooner or later can consider "struct iovec" as an
entirely generic mechanism to reference some binary blob, and is the
go-to type for this purpose whenever we need one.
2023-10-20 10:34:33 +02:00
Zbigniew Jędrzejewski-Szmek 974959e6f6 test-recurse-dir: work around nftw() ignoring symlinks()
We have a test where we compare the results from nftw() and our own
resurce_dit_at(). nftw() skips a dangling symlink when running under mkosi and
the test fails. I don't understand why nftw() does that, but in our code we
don't need to test and care about the details of nftw(), which we don't use,
outside of the one test, so let's just skip symlinks in the test.

Closes #29603.
2023-10-19 22:40:22 +01:00
Arseny Maslennikov 8b45281daa seccomp: also check the mode parameter of fchmodat2(2)
If there is no libseccomp support, just ban the entire syscall instead
so wrappers will fall back to older, supported syscalls.
Also reflect all of this in `test-seccomp.c`.
2023-10-19 15:53:58 +03:00
Arthur Shau 1bd0b9c053 varlink: Add new varlink_collect method
varlink_collect is meant to be used when the client is willing to wait for the reply from the varlink method, much like varlink_call.
However, unlike varlink_call, it allows the client to collect all "more" replies that may be sent by method before the "final" reply is enqueued.
It aggregates all of these replies into a json variant array that it returns to the client.
2023-10-19 11:52:09 +02:00
Yu Watanabe ffee7b97e3 macro: introduce u64_multiply_safe() to avoid overflow
Just a paranoia.
2023-10-19 18:31:44 +09:00
Yu Watanabe 2977904cad macro: introduce several helper functions for alignment
Some of them are not used in this commit, but will be used later.
2023-10-19 18:31:44 +09:00
Lennart Poettering 81c1c387fe Merge pull request #29594 from poettering/cgroup-rename-ret-params
more pidfdification
2023-10-18 17:25:44 +02:00
Lennart Poettering d0547385d9 test-cgroup: make test case a bit more robust towards previous aborted runs 2023-10-18 14:49:40 +02:00
Lennart Poettering 957f84e950 test: port tests over to new /proc/ enumeration API 2023-10-18 14:49:40 +02:00
Lennart Poettering 4d9f092b5e process-util: add pidref_is_unwaited() and make pid_is_unwaited() return errors 2023-10-18 14:49:40 +02:00
Lennart Poettering becdfcb9f1 process-util: change pid_is_alive() to not eat up errors, and add pidref_is_alive()
Let's no eat up errors, but propagate unexpected ones.
2023-10-18 14:40:25 +02:00
Lennart Poettering 8b51341545 process-util: add pidref_get_uid() and rename get_process_uid() → pidref_get_uid() 2023-10-18 14:39:33 +02:00
Lennart Poettering d7d748548b process-util: add pidref_get_comm() and rename get_process_comm() to pid_get_comm() 2023-10-18 14:39:33 +02:00
Lennart Poettering fc87713bed process-util: add pidref_is_kernel_thread() 2023-10-18 14:39:33 +02:00
Lennart Poettering a034620f1a process-util: add pidref_get_cmdline() 2023-10-18 14:39:33 +02:00
Lennart Poettering c2e42d4b88 serialize: change order of deserialize_strv() parameters
The other deserializers put value first, and return parameter second,
let's do so here too.
2023-10-18 12:54:20 +02:00