Commit Graph

5815 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
8e1ac16bc6 src/basic: rename uid-alloc-range.[ch] to uid-classification.[ch]
We had both uid-range.h and uid-alloc-range.h. The latter now contains helpers
like {uid,gid}_is_{system,dynamic,container}(), uid_for_system_journal(), so
the existing name is outdated. I think the uid-range.[ch] should stay separate
because it has a bunch of helpers for parsing and printing of uid ranges. So
let's rename as in $subject to better reflect the contents of the file and make
the two sets of files harder to confuse.
2024-01-09 11:15:00 +01:00
Zbigniew Jędrzejewski-Szmek
eb7d7d14fb src/basic: "UidRange" → "UIDRange"
We don't "uncapitalize" parts of an already-capitalized name when concatenating
words. In particular, we had UidRange in basic/uid-range.h and UGIDAllocationRange
in basic/uid-alloc-range.h, which is annoying.
2024-01-09 11:15:00 +01:00
Yu Watanabe
35716eed55 Merge pull request #30837 from poettering/varlink-over-ssh
varlink: add "ssh:" transport for talking to remote servers
2024-01-09 10:14:03 +09:00
Lennart Poettering
fc1f05ebab socket-util: modernize socknameinfo_pretty() a bit 2024-01-09 10:00:21 +09:00
Lennart Poettering
3b1e80f7cb process-util: turn off O_NONBLOCK on stdio fds when rearranging fds
We often create our fds O_NONBLOCK, but when we want to invoke some
program with them as stdin/stdout/stderr we really should turn it off
again.
2024-01-08 23:23:42 +01:00
Lennart Poettering
b20e9dc515 env-util: add new setenvf() helper
And convert some pieces of code over.
2024-01-08 23:22:58 +01:00
Mike Yuan
bdd2036e81 hexdecoct: make unbase64mem and unhexmem always use SIZE_MAX 2024-01-09 03:59:15 +09:00
Yu Watanabe
e701439998 virt: fix detection of avx2 and friends
To get the CPUID with EAX=7, we need explicitly set 0 to ECX.

From Intel® Architecture Instruction Set Extensions Programming
Reference and Related Specifications,
===
Leaf 07H output depends on the initial value in ECX.
If ECX contains an invalid sub leaf index, EAX/EBX/ECX/EDX return 0
===

Fixes #30822.
2024-01-08 16:04:17 +01:00
Lennart Poettering
d3109d8de0 socket-util: add helper for querying the local AF_VSOCK CID 2024-01-08 10:26:34 +01:00
Yu Watanabe
b82b4d258e Merge pull request #30794 from poettering/parse-vsock-better
socket-util: add more careful parsers for AF_VSOCK cid/port
2024-01-06 11:16:19 +09:00
networkException
dcfac3a3f9 parse-helpers: allow port 0 for socket bind items
This patch adds a new parameter to parse_ip_port_range, giving callers
the option to allow ranges to have their min be 0 instead of 1.

This is then used by parse_ip_ports_token, intern used by
parse_socket_bind_item to allow port 0 when restricting bind system
calls with SocketBindDeny / SocketBindAllow.

With this, users running server software written using the golang
standard library will be able to effectively sandbox their software,
albeit with a small loss in security protections by allowing the
process to bind on a random port in the
/proc/sys/net/ipv4/ip_local_port_range.
2024-01-06 08:27:14 +09:00
Lennart Poettering
8e471c6a9f socket-util: add more careful parsers for AF_VSOCK cid/port
Let's handle the magic CIDs, and filter out invalid ports.
2024-01-05 22:29:55 +01:00
Lennart Poettering
41dd51f8f5 missing: add a bunch of vsock related defines 2024-01-05 22:29:55 +01:00
Lennart Poettering
2148c669d2 fileio: add new flag WRITE_STRING_FILE_MODE_0444
With this write_string_file() will create the file with 0444 access mode
(i.e. read-only).
2024-01-05 17:30:41 +01:00
Lennart Poettering
dddc12f9eb iovec-util: add CONST_IOVEC_MAKE_STRING() 2024-01-05 11:10:22 +01:00
Lennart Poettering
4cc467b67c iovec-util: add new iovec_memdup() helper 2024-01-05 11:10:22 +01:00
Lennart Poettering
bf38e4c0c1 iovec-util: add new iovec_memcmp() helper 2024-01-05 11:10:22 +01:00
Lennart Poettering
39f586873d iovec-util: add iovec_is_valid() helper 2024-01-05 11:10:22 +01:00
Lennart Poettering
33d1febbd7 iovec-util: rework IOVEC_MAKE_STRING() to work with compound initialized input
This avoids the ({}) that IOVEC_MAKE_STRING() so far used and might
cause a memory corruption if the parameter passed in is itself allocated
via a compount initialized array or so.

Also, this makes sure both IOVEC_MAKE_STRING() and IOVEC_MAKE() accept
'const' parameters without this causing a compiler warning.
2024-01-05 11:10:22 +01:00
Yu Watanabe
9e44842a9a string-util: fix typo
Follow-up for 63566c6b6f.
2024-01-05 19:08:12 +09:00
Adrian Vovk
d3c2288c9f stat-util: Add statx version of timespec_load
statx_timestamp is, for all intents and purposes, the same as a struct
timespec. So, we can trivially convert it and call timespec_load on it.

This commit adds helper functions that do just that.
2024-01-04 12:49:14 -05:00
Yu Watanabe
7903567cb7 Merge pull request #30610 from YHNdnzj/logind-serialize-pidref
logind: serialize session leader pidfd to fdstore
2024-01-04 23:25:18 +09:00
Lennart Poettering
96fc8cab2a Merge pull request #30578 from bluca/polkit-varlink
varlink: add glue to allow authenticating varlink connections via polkit
2024-01-04 15:15:45 +01:00
Mike Yuan
2e6f012bf0 strv: rename strv_endswith to endswith_strv and dedup ENDSWITH_SET 2024-01-04 16:51:57 +08:00
Mike Yuan
eba8b54130 string-util: move startswith_strv to strv 2024-01-04 16:49:05 +08:00
Mike Yuan
53190aa693 string-util: use strneq 2024-01-04 16:49:05 +08:00
Mike Yuan
faf0dd4b29 process-util: ensure pidref_is_alive only return ESRCH if not set 2024-01-04 16:19:20 +08:00
Lennart Poettering
2a02a8db91 Merge pull request #26663 from poettering/vpick
add new "vpick" concept for automatically picking newest resource from .v/ dir containing versioned files
2024-01-03 22:17:32 +01:00
Rose
b4a9d19e4e basic: fix overflow detection in sigbus_pop
The current check checks for n_sigbus_queue
being greater than or equal to SIGBUS_QUEUE_MAX,
when it should be just greater than as
n_sigbus_queue being SIGBUS_QUEUE_MAX indicates
that the queue is full, but not overflowed.
2024-01-04 05:26:01 +09:00
Lennart Poettering
cc03788086 stat-util: add inode_type_from_string() helper 2024-01-03 18:38:46 +01:00
Lennart Poettering
63566c6b6f string-util: add strrstr() helper 2024-01-03 18:38:46 +01:00
Lennart Poettering
cb599f881a strv: add new strv_endswith() helper 2024-01-03 18:38:46 +01:00
Lennart Poettering
4e1f0037b8 units: add a tpm2.target synchronization point and small generator that pulls in
Distributions apparently only compile a subset of TPM2 drivers into the
kernel. For those not compiled it but provided as kmod we need a
synchronization point: we must wait before the first TPM2 interaction
until the driver is available and accessible.

This adds a tpm2.target unit as such a synchronization point. It's
ordered after /dev/tpmrm0, and is pulled in by a generator whenever we
detect that the kernel reported a TPM2 to exist but we have no device
for it yet.

This should solve the issue, but might create problems: if there are TPM
devices supported by firmware that we don't have Linux drivers for we'll
hang for a bit. Hence let's add a kernel cmdline switch to disable (or
alternatively force) this logic.

Fixes: #30164
2024-01-03 13:49:02 +01:00
Lennart Poettering
da5e0c442b socket-util: add helper for getting peer pidfd 2024-01-02 17:57:34 +01:00
Lennart Poettering
3dee63b762 process-util: add new pid{ref,}_get_start_time() helper
This also adds a test case that test pidref_safe_fork(), pidref_wait()
and related calls.
2024-01-02 17:57:34 +01:00
Lennart Poettering
f17132260f process-util: add pidref_safe_fork() helper
This combines safe_fork() with pidref_set_pid().

Eventually we really should switch this to use CLONE_PIDFD, but as that
is not wrapped by glibc yet, it's hard. But this is not crucial anyway,
as a child we just forked off can always safely be referenced also by
PID, given the reaping is under our own control.

A simple test case is added in a follow-up commit.
2024-01-02 17:57:34 +01:00
Lennart Poettering
a3f3243613 pidref: add helpers for waiting for pidref processes
A simple test case is added in a follow-up commit.
2024-01-02 17:57:34 +01:00
Mike Yuan
6b9cac874c fd-util: don't eat up errors in fd_cloexec_many
Follow-up for ed18c22c98

Before this commit, a successful fd_cloexec() call would
discard all previously gathered errors.
2023-12-29 14:26:40 +01:00
Mike Yuan
1276e63370 fd-util: modernization 2023-12-28 18:26:52 +08:00
Frantisek Sumsal
c83f4220a1 tree-wide: use IN_SET() more 2023-12-27 11:15:48 +01:00
Mike Yuan
0a0f49556f Merge pull request #30622 from yuwata/space
tree-wide: drop unnecessary space or insert missing space
2023-12-25 17:52:48 +08:00
Yu Watanabe
c01a5c0527 siphash24: introduce siphash24_compress_typesafe() macro
To prevent copy-and-paste mistake.

This also introduce in_addr_hash_func().

No functional change, just refactoring.
2023-12-25 15:38:59 +09:00
Yu Watanabe
07e8c3055d tree-wide: drop several doubled space 2023-12-25 02:13:49 +09:00
Yu Watanabe
b3a9d980f3 tree-wide: drop space between variable and an increment/decrement 2023-12-25 01:56:40 +09:00
Yu Watanabe
fce9e8a168 log: make assert_return() critical when -Dmode=developer
Triggering assert_return() should be a bug in general, and we should
really fix that.  But, previously, it is hard to notice such bug, as
it was not critical.
This is for making CI or our testing environment fail if we unexpectedly
trigger assert_return(). So, hopefully we can easily find such bugs.
2023-12-24 02:03:30 +09:00
Yu Watanabe
93bb67090c log: introduce a knob to make assert_return() critical
These can be used to check if we trigger assert_return()
unexpectedly.

Co-authored-by: Frantisek Sumsal <frantisek@sumsal.cz>
2023-12-24 01:52:26 +09:00
Mike Yuan
dd9c8da865 various: clean up isatty() handling
As per https://github.com/systemd/systemd/pull/30547#discussion_r1434371627
2023-12-22 23:06:49 +08:00
Mike Yuan
76270f5c09 terminal-util: introduce isatty_safe that rejects EBADF 2023-12-22 23:06:48 +08:00
Mike Yuan
d3f818fea6 terminal-util: use RET_GATHER more 2023-12-22 23:04:47 +08:00
Lennart Poettering
dc6522b18f Merge pull request #28658 from H5117/enroll_with_ec
cryptsetup: Add support for EC keys in PKCS#11 tokens
2023-12-21 22:45:40 +01:00