Commit Graph

8528 Commits

Author SHA1 Message Date
Yu Watanabe
ff5b9aeeda Merge pull request #32340 from YHNdnzj/wait-for-unit-cleanup
bus-wait-for-units: some cleanup
2024-04-19 12:36:48 +09:00
Mike Yuan
61cd6c4db7 bus-wait-for-units: simplify property_map_job_id 2024-04-19 10:08:37 +08:00
Mike Yuan
ac21fafbea bus-wait-for-units: drop 'current' field
This is not used anywhere.
2024-04-19 10:08:37 +08:00
Mike Yuan
cc6978d6ae bus-wait-for-units: check for existing unit first, use hashmap_ensure_put 2024-04-19 10:08:36 +08:00
Mike Yuan
df0183d8f1 bus-wait-for-units: make callback type end with "_t" 2024-04-19 10:08:36 +08:00
Mike Yuan
4b8fdb4681 bus-wait-for-units: drop ready_callback
This is never used, and given that bus_wait_for_units_run
returns BusWaitForUnits.state it's not really useful.
2024-04-19 10:08:36 +08:00
Yu Watanabe
f72e851fd3 conf-parser: move config_parse_timezone() to conf-parser.[ch]
Even though it is currently only used by networkd, the parser itself
is quite generic. Let's move it to the shared library.
2024-04-19 10:23:01 +09:00
Nick Rosbrook
c0bc1e8971 copy: ignore -EOPNOTSUPP from copy_file_range()
According to copy_file_range (2), errno will be set to EOPNOTSUPP when
the file system does not support copy_file_range(). Since there is
already fallback logic in place here for other kinds of errors, add
-EOPNOTSUPP to the list of ignored errors.
2024-04-19 09:57:25 +09:00
Lennart Poettering
dd37963aff Merge pull request #31790 from poettering/pcrlock-policy-fix
Replace PolicyAuthValue by PolicySigned as access policy for pcrlock policy nvindex
2024-04-18 21:11:27 +02:00
Lennart Poettering
d10d4a3701 tpm2-util: now that we don't use PolicyAuthValue anymore, let's not set an authValue anymore for the policy nvindex
We have now switched from PolicyAuthValue to PolicySigned to control
access to the policy nvindex to. This means there's no point in setting
an authValue on the nvindex anymore, hence drop this.
2024-04-18 18:12:23 +02:00
Lennart Poettering
cb835a2ed1 pcrlock: switch access policy for nvindex to store policy in from PolicyAuthValue to PolicySigned (with an HMAC-SHA256 key)
So far the nvindex to store the pcrlock policy in was protected via a
PolicyAuthValue policy (i.e. with a simple PIN set on the nvindex).
That's a bad idea however, as it means an attacker can simply remove and
re-create the nvindex and the "name" of the nvindex does not change,
thus defeating the logic. (This is because the authValue is *not* part
of the "name" of an nvindex!).

Fix this by switching from PolicyAuthValue to PolicySigned with an
HMAC-SHA256 key. Behaviour is very similar: however, the PIN is now part
of of the access policy hash, which *is* part of the "name" of an
nvindex. Thus, if an attacker removes and recreates the nvindex it has
to provide the same PIN again or the "name" of the nvindex will change.
Mission accomplished.

I'd like to thank Chris Coulson for finding this issue (and helping me
address it). Thank you!
2024-04-18 18:12:23 +02:00
Lennart Poettering
19d82e1bee tpm2-util: add comment explaining what tpm2_define_policy_nv_index() actually does 2024-04-18 18:12:23 +02:00
Lennart Poettering
371b594414 tpm2-util: load external key into NULL hierarchy if private key is provided
If we load an external key into the TPM we must do so in the NULL
hierarchy. An external key after all is one that is not wrapped by any
hierarchy's seed.

See TPM2 spec, Part 3, Section 12.3.1
2024-04-18 18:12:23 +02:00
Lennart Poettering
d0f8da9815 tpm2-util: rename tpm2_get_pin_auth() → tpm2_auth_value_from_pin()
Just some renaming. I found the old name a bit confusing since it sounds
as if this would get the pin from somewhere, but it really doesn't. It
just converts a PIN into an auth_value, and I think saying so explicitly
makes things easier to grok.
2024-04-18 18:12:23 +02:00
Lennart Poettering
98ef5f8419 tpm2: export tpm2_get_name()
We later want to use this from pcrlock.c, hence export it.
2024-04-18 18:12:23 +02:00
Lennart Poettering
9892b7238b tpm2-util: import two more symbols from tpm2-tss libraries
We want to make use of TPM_PolicySigned soon, hence import the necessary
symbols from tpm2-tss.
2024-04-18 18:12:23 +02:00
Matteo Croce
854711645b use FOREACH_ELEMENT
Use FOREACH_ELEMENT where possible. Generated with this command,
and checked manually:

    git grep -l 'FOREACH_ARRAY.*ELEMENTSOF' | \
    xargs sed -ri 's/FOREACH_ARRAY\((.*), (.*), (ELEMENTSOF.*)\)/FOREACH_ELEMENT(\1, \2)/'
2024-04-18 17:39:34 +02:00
Yu Watanabe
955d5012e0 blockdev-util: fix typo
Follow-up for 33ff155957.
2024-04-18 13:08:14 +09:00
Yu Watanabe
f846002fa2 Merge pull request #32192 from yuwata/part-scan
blockdev-util: fix detection of partscan
2024-04-18 11:38:48 +09:00
Yu Watanabe
d2a0ef6073 Merge pull request #32249 from CodethinkLabs/vmspawn/predicatable_tap_names
vmspawn: generate predicatable TAP device names and MAC addresses
2024-04-18 10:26:07 +09:00
Yu Watanabe
33ff155957 blockdev-util: also read 'ext_range' sysattr to check if the partscan is enabled
The 'capability' sysattr was deprecated by
e81cd5a983 (v6.3).
2024-04-18 09:48:26 +09:00
Lennart Poettering
7e16650d83 Merge pull request #32143 from yuwata/magic
basic/linux: copy magic.h from kernel to our code
2024-04-17 17:03:48 +02:00
Bryan Jacobs
12cf745cce cryptenroll: Use CTAP2.1 credProtect extension
When enrolling a new FIDO2 token with a client PIN, this tells the authenticator to require the PIN on all uses.

It also collects a PIN before attempting to create a credential.

Works around #31443 in most (not all) scenarios.
2024-04-17 11:46:22 +09:00
Mike Yuan
fecea05e15 shared/vpick: also align function params in header
Follow-up for 6d8690ecd3
2024-04-16 10:46:50 +02:00
Yu Watanabe
6c15a28454 creds-util: move pick_up_credentials() from network-generator
The function is quite general, and can be used at other places.
Let's move to our shared library.
2024-04-16 09:42:20 +09:00
Mike Yuan
c694419a51 shared/vpick: add missing condition on ret_result
Fixes #32285
2024-04-16 01:38:08 +08:00
Mike Yuan
ac68e6d691 shared/vpick: drop unneeded strempty()
prefix_roota() handles NULL root param gracefully.
2024-04-16 01:38:08 +08:00
Mike Yuan
6d8690ecd3 shared/vpick: align function args correctly, add missing assertion 2024-04-16 01:38:08 +08:00
Yu Watanabe
e2f0876ecd dissect: refuse to use diskseq if ID_IGNORE_DISKSEQ=1 is specified
Follow-up for 1a81ddef00.
2024-04-15 16:50:45 +02:00
Sam Leonard
c50e7dcaf6 nspawn,shared/netif-util: move generate_mac and shorten_ifname to shared/netif-util 2024-04-15 11:42:05 +01:00
Mike Yuan
da130b9ab8 cgroup-setup: modernize cg_migrate 2024-04-14 23:22:13 +08:00
Yu Watanabe
87bbcb26c8 Merge pull request #32255 from YHNdnzj/strextendf
shared/killall: minor modernization
2024-04-13 05:10:20 +09:00
Mike Yuan
bbfb9edc66 shared/killall: minor modernization 2024-04-13 02:35:01 +08:00
Antonio Alvarez Feijoo
126928de76 bus-polkit: fix return value for varlink_allow_interactive_authentication()
Follow-up for d04c1a1c8e
2024-04-12 13:26:22 +01:00
Yu Watanabe
1ae891037e Merge pull request #32202 from DaanDeMeyer/assert
tests: Improve assertion error messages
2024-04-11 09:51:49 +09:00
Luca Boccassi
798ea5c05a Merge pull request #32181 from YHNdnzj/open-file
Some fixes/improvements for OpenFile=
2024-04-10 23:15:56 +01:00
Daan De Meyer
681e39c1dc Introduce ASSERT_OK_ERRNO()
ASSERT_OK() is for functions that return negative errno. Let's
introduce ASSERT_OK_ERRNO() for syscalls that return -1 and store
the error in errno.
2024-04-10 18:24:26 +02:00
Daan De Meyer
29b27d59d5 tests: Improve assertion error messages 2024-04-10 18:20:23 +02:00
Mike Yuan
c1f9509f79 shared/open-file: use xescape to escape ':'
Fixes #32179
2024-04-10 20:16:35 +08:00
Mike Yuan
4eb1feb110 shared/open-file: make open_file_free_many static inline 2024-04-10 20:16:35 +08:00
Antonio Alvarez Feijoo
866a469e5a test: add missing header to test.h
```
../src/shared/tests.h:361:28: error: implicit declaration of function ‘fork’ [-Werror=implicit-function-declaration]
  361 |                 int _pid = fork();                                                                              \
      |                            ^~~~
../src/test/test-macro.c:1114:9: note: in expansion of macro ‘ASSERT_SIGNAL’
 1114 |         ASSERT_SIGNAL(ASSERT_OK(-1), SIGABRT);
      |         ^~~~~~~~~~~~~
../src/shared/tests.h:369:25: error: implicit declaration of function ‘_exit’ [-Werror=implicit-function-declaration]
  369 |                         _exit(EXIT_SUCCESS);                                                                    \
      |                         ^~~~~
../src/test/test-macro.c:1114:9: note: in expansion of macro ‘ASSERT_SIGNAL’
 1114 |         ASSERT_SIGNAL(ASSERT_OK(-1), SIGABRT);
      |         ^~~~~~~~~~~~~
../src/shared/tests.h:369:25: warning: incompatible implicit declaration of built-in function ‘_exit’ [-Wbuiltin-declaration-mismatch]
  369 |                         _exit(EXIT_SUCCESS);                                                                    \
      |                         ^~~~~
../src/test/test-macro.c:1114:9: note: in expansion of macro ‘ASSERT_SIGNAL’
 1114 |         ASSERT_SIGNAL(ASSERT_OK(-1), SIGABRT);
      |         ^~~~~~~~~~~~~
../src/shared/tests.h:369:25: warning: incompatible implicit declaration of built-in function ‘_exit’ [-Wbuiltin-declaration-mismatch]
  369 |                         _exit(EXIT_SUCCESS);                                                                    \
      |                         ^~~~~
../src/test/test-macro.c:1115:9: note: in expansion of macro ‘ASSERT_SIGNAL’
 1115 |         ASSERT_SIGNAL(ASSERT_OK(-ENOANO), SIGABRT);
      |         ^~~~~~~~~~~~~
../src/test/test-macro.c:1119:21: error: implicit declaration of function ‘getpid’; did you mean ‘getpt’? [-Werror=implicit-function-declaration]
 1119 |         ASSERT_TRUE(getpid());
      |                     ^~~~~~
```

Follow-up for #32189
2024-04-10 11:09:52 +02:00
Yu Watanabe
cd226becd8 Merge pull request #32189 from mrc0mmand/test-tweaks
Another batch of assorted test tweaks
2024-04-10 16:57:00 +09:00
Lennart Poettering
e1771c8ee6 sd-journal: make sure sd_journal_add_match() also accepts SIZE_MAX as size
In many of our internal functions that take a pointer + a size we have
introduced the rule that SIZE_MAX as size means: take strlen().

sd_journal_add_match() has something similar, but the special value is
0, not SIZE_MAX. This is a bit ugly, since a zero size data block is
theoretically fine. The only reason sd_journal_add_match() gets away
with using this special value is because valid matches must consist of
at least 2 chars, hence cannot be zero.

But let's make this more robust and less surprising when compared to the
rest of our code, and *also* accept SIZE_MAX to mean strlen().

No actual code changes, just some clean-up.
2024-04-10 16:54:03 +09:00
Daan De Meyer
7072777163 core: Serialize both pid and pidfd
If we try to deserialize only a pidfd that points to a process that
has been reaped, creating the pidref object will fail, which means that
we'll try to create a pidref object from the serialized pid that comes
next. If the pid has already been reused, this will succeed and we'll
now have a pidref that points to a different process.

Let's avoid this issue by serializing both the pidfd and the pid and
creating the pidref object directly from both. This means we'll reuse
the deserialized pidfd instead of opening a new one. We'll then immediately
notice the pidfd is dead and do the appropriate follow up depending on
the unit type.
2024-04-10 09:32:04 +02:00
Yu Watanabe
e1dad06100 home,resize-fs: replace XFS_SB_MAGIC -> XFS_SUPER_MAGIC 2024-04-10 06:38:29 +09:00
Frantisek Sumsal
8c33218e9e test: add a couple of sanity tests for ASSERT_*() macros
Also, introduce ASSERT_SIGNAL() macro that should help us test failing
cases of mentioned macros (which usually end with calling abort()).
2024-04-09 21:39:46 +02:00
Frantisek Sumsal
7d7a3d4787 test: handle NULL correctly when passed to ASSERT_EQ()
strcmp() doesn't handle NULLs nicely, so switch to streq_ptr().
2024-04-09 21:39:46 +02:00
Frantisek Sumsal
edda10f2ae tree-wide: make sure net/if.h is included before any linux/ header
The linux/ headers include linux/libc-compat.h that makes sure the
linux/ headers won't redeclare symbols already declared by net/if.h, but
glibc's net/if.h doesn't do that, so if the include order is reversed
we'll end up with a bunch of errors about redeclared stuff:

[3/519] Compiling C object test-network-tables.p/src_network_test-network-tables.c.o
FAILED: test-network-tables.p/src_network_test-network-tables.c.o
cc -Itest-network-tables.p -I. -I.. -Isrc/basic -I../src/basic -Isrc/fundamental -I../src/fundamental -Isrc/systemd -I../src/systemd -I../src/libsystemd/sd-bus -I../src/libsystemd/sd-device -I../src/libsystemd/sd-event -I../src/libsystemd/sd-hwdb -I../src/libsystemd/sd-id128 -I../src/libsystemd/sd-journal -I../src/libsystemd/sd-netlink -I../src/libsystemd/sd-network -I../src/libsystemd/sd-resolve -Isrc/shared -I../src/shared -Isrc/libsystemd-network -I../src/libsystemd-network -Isrc/network -I../src/network -I../src/network/netdev -I../src/network/tc -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu11 -O0 -g -Wno-missing-field-initializers -Wno-unused-parameter -Wno-nonnull-compare -Warray-bounds -Warray-bounds=2 -Wdate-time -Wendif-labels -Werror=format=2 -Werror=format-signedness -Werror=implicit-function-declaration -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Werror=missing-declarations -Werror=missing-prototypes -Werror=overflow -Werror=override-init -Werror=return-type -Werror=shift-count-overflow -Werror=shift-overflow=2 -Werror=strict-flex-arrays -Werror=undef -Wfloat-equal -Wimplicit-fallthrough=5 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpointer-arith -Wredundant-decls -Wshadow -Wstrict-aliasing=2 -Wstrict-prototypes -Wsuggest-attribute=noreturn -Wunused-function -Wwrite-strings -Wzero-length-bounds -fdiagnostics-show-option -fno-common -fstack-protector -fstack-protector-strong -fstrict-flex-arrays --param=ssp-buffer-size=4 -Wno-unused-result -Werror=shadow -fno-strict-aliasing -fstrict-flex-arrays=1 -fvisibility=hidden -fno-omit-frame-pointer -include config.h -pthread -DTEST_CODE=1 -MD -MQ test-network-tables.p/src_network_test-network-tables.c.o -MF test-network-tables.p/src_network_test-network-tables.c.o.d -o test-network-tables.p/src_network_test-network-tables.c.o -c ../src/network/test-network-tables.c
In file included from ../src/basic/linux/if_bonding.h:47,
                 from ../src/network/netdev/bond.h:5,
                 from ../src/network/test-network-tables.c:3:
../src/basic/linux/if.h:111:41: error: redeclaration of enumerator ‘IFF_UP’
  111 | #define IFF_UP                          IFF_UP
      |                                         ^~~~~~
../src/basic/linux/if.h:84:9: note: previous definition of ‘IFF_UP’ with type ‘enum net_device_flags’
   84 |         IFF_UP                          = 1<<0,  /* sysfs */
      |         ^~~~~~
../src/basic/linux/if.h:112:41: error: redeclaration of enumerator ‘IFF_BROADCAST’
  112 | #define IFF_BROADCAST                   IFF_BROADCAST
      |                                         ^~~~~~~~~~~~~
...

This also drops remaining workarounds from the last time this issue was
brought up (6f270e6bd8) since they shouldn't be needed anymore if the
order of the includes is the "correct" one. I also added a comment to
each affected include when this is inevitably encountered again in the
future.

Resolves: #32160
2024-04-09 21:19:15 +02:00
Luca Boccassi
9dcc2a5838 nsresource: fix FD leak
Also fix return code, namespace_open_by_type uses RET_NERRNO

CID#1542923

Follow-up for 54452c7b2a
2024-04-08 10:19:42 +01:00
Yu Watanabe
6952ebae3b tree-wide: drop several remaining license headers
And downgrade the license of utf8.c to LGPL-2.0-or-later, to follow the
original license.
2024-04-08 10:14:50 +02:00