Commit Graph
6552 Commits
Author SHA1 Message Date
Lennart Poettering 97ac59f18d machine: follow ups for varlink PRs recently merged (#35940)
Follow ups for:
- https://github.com/systemd/systemd/pull/35880
- https://github.com/systemd/systemd/pull/35066
2025-01-10 22:12:22 +01:00
Lennart Poettering fa8b70f2c8 userdb: define new 64K "foreign UID" range (#35932)
This is establish the basic concepts for #35685, in the hope to get this
merged first.

This defines a special, fixed 64K UID range that is supposed to be used
by directory container images on disk, that is mapped to a dynamic UID
range at runtime (via idmapped mounts).

This enables a world where each container can run with a dynamic UID
range, but this in no way leaks onto the disk, thus making supposedly
dynamic, transient UID range assignments persistent.

This is infrastructure later used for the primary part of #35685: unpriv
container execution with directory images inside user's home dirs, that
are assigned to this special "foreign UID range".

This PR only defines the ranges, synthesizes NSS records for them via
userdb, and then exposes them in a new "systemd-dissect --shift" command
that can re-chown a container directory tree into this range (and in
fact any range).

This comes with docs. But no tests. There are tests in #35685 that cover
all this, but they are more comprehensive and also test nspawn's hook-up
with this, hence are excluded from this PR.
2025-01-10 13:49:11 +01:00
Ivan Kruglov 03b89cf213 basic: fixes in read_errno()
follow ups for https://github.com/systemd/systemd/pull/35880
2025-01-10 11:49:49 +01:00
Lennart Poettering 7893362508 process-util: do not unblock unrelated signals while forking
This makes sure when we are blocking signals in preparation for fork()
we'll not temporarily unblock any signals previously set, by mistake.

It's safe for us to block more, but not to unblock signals already
blocked. Fix that.

Fixes: #35470
2025-01-10 16:10:31 +09:00
Ivan Kruglov 64db44f7fb process-util: read_errno() 2025-01-09 10:47:24 +01:00
Lennart Poettering ec0c10fc9d user-classification: add new "foreign" UID range
This makes the UID range configurable via build time options, but of
course it really shouldn't be changed. The default range I picked is
outside even of IPAs current (ridiculously large) allocation ranges,
hence hopefully minimizes conflicts.
2025-01-08 21:41:03 +01:00
Mike Yuan 684e4e5bfb two pidref tweaks (#35918) 2025-01-08 18:58:20 +01:00
nl6720 96963e5615 dissect-image: mount the ESP with fmask=0177 (#35871)
Avoid showing the files on the ESP (i.e. a FAT formatted volume) as
executable by removing the execute permission from them.

IMO this makes the colored output of `ls` more sensible since the file
system will be mounted with `noexec` anyway.

Add a `fstype_can_fmask_dmask` function that checks if a file system
type can use the `fmask` and `dmask` mount options.

This replaces `fstype_can_umask` since it was only used in
`partition_pick_mount_options` which only cares about the file system
support for fmask & dmask now.

It somewhat reduces the coverage of the feature since there are more file
systems that support umask as opposed to those supporting dmask & dmask,
but it should not be much of an issue since fmask & dmask are supported
by vfat, exfat and ntfs3.
2025-01-08 15:19:33 +01:00
Lennart Poettering 0df46f8908 pidref: drop support for kernels lacking waitid(P_PIDFD, …)
Our baseline is not 5.4, which is where P_PIDFD was introduced.
2025-01-08 14:51:19 +01:00
Lennart Poettering 06744cbb52 pidref: copy fd id in pidref_copy() too 2025-01-08 14:51:19 +01:00
Lennart Poettering 2ade821859 namespace-util: add process_is_owned_by_uid() helper 2025-01-07 23:55:34 +01:00
Lennart Poettering 3d57b6692f namespace-util: add helper to get base UID from userns 2025-01-07 23:55:34 +01:00
Lennart Poettering 5b14690a39 namespace-util: slightly tweak proc_mounted() handling in namespace_is_init()
Let's not sloppily eat up errors here.
2025-01-07 23:51:28 +01:00
Lennart Poettering adcc805929 namespace-util: return recognizable error if namespace_open_by_type() fails because ns type not supported
This makes sure the the codepath that derives an nsfd from a pid works
the same for the pidfd case and the non-pidfd case: if we can verify
that /proc/ is mounted but the /proc/$PID/ns/ files are missing, we can
assume the ns type is not supported by the kernel. Hence return the same
ENOPKG error in this case as we already do in the pidfd ioctl based
codepath.
2025-01-07 23:51:28 +01:00
Mike Yuan 16ac586e5a Bump minimum kernel baseline to 5.4, recommended version to 5.7
As requested, a list of kernel version to feature mapping
for kernels older than minimum baseline is also included,
in order to ease potential backport work.
2025-01-07 22:43:45 +01:00
Lennart Poettering 56a07d10a5 xopenat(): introduce new XO_REGULAR flag (#35834)
This is something I think we should have added a long time ago: a
flavour of open() that safely ensures the inode we are opening is a
regular file, before we open it. It does this by means of pinning the
inode via O_PATH first, and after verification actually opening it.

This ports some code over to this, but sooner or later we should
probably use this a lot more, so that we don't accidentally open weird
stuff such as device nodes or pipes, where we should not.
2025-01-07 08:55:56 +01:00
Lennart Poettering 9ed2725867 process-util: a process from a foreign pidns is definitely not our child
Addresses: https://github.com/systemd/systemd/pull/35242#pullrequestreview-2531712318
2025-01-07 08:55:21 +01:00
Yu Watanabe 62e9cd6b09 basic/linux: update kernel headers from v6.13-rc6
This also removes README and moves the explanation about the header
modification to the script.
2025-01-06 23:35:14 +00:00
Lennart Poettering dffafa47ae fs-util: add XO_REGULAR flag for xopenat()
If this flag is set we guarantee that the fd returned refers to a
regular file. If the file exists and is not one, fails.
2025-01-06 23:20:09 +01:00
Lennart Poettering 336acebc77 basic: port various pidfd/pidref helpers to PIDFD_GET_INFO and PIDFD_GET_*_NAMESPACE (#35242)
Supersedes #35308 (cherry-picked one commit and replaced the rest)

(I left a few comments that's folded by GitHub. Please make sure to
check them too.)
2025-01-06 11:23:08 +01:00
Lennart Poettering 7f72184f12 more pidref'ification (#35839)
This is split out of #35264, but makes a ton of sense on its own.
2025-01-06 11:21:43 +01:00
Lennart Poettering dd445d6e99 cgroup-util: add remoteness checks to all cg_pidref_get_xyz() calls 2025-01-06 09:54:41 +01:00
Lennart Poettering 92d78966fd cgroup-util: add pidref counterparts for cg_pid_get_session() + cg_pid_get_owner_uid() 2025-01-06 09:54:41 +01:00
Lennart Poettering b2206fe514 socket-util: introduce getpeerpidref()
This combines getpeercred() and getpeerpidfd() and returns a PidRef
2025-01-06 09:45:57 +01:00
Mike Yuan 9598708a12 cgroup-util: explain why cg_pidref_get_path() cannot be ported over to pidfd helpers (yet)
See also: https://github.com/systemd/systemd/pull/35242#issuecomment-2506686806
2025-01-04 17:48:23 +01:00
Mike Yuan f1ba5c900b cgroup-util: introduce generic cg_path_from_cgroupid() helper
Taken from nsresourced/userns-registry.c userns_destroy_cgroup()
2025-01-04 17:48:22 +01:00
Mike Yuan 223d455670 process-util: make pid_is_unwaited() wrapper around pidref version 2025-01-04 17:48:22 +01:00
Mike Yuan 47f64104d1 process-util: port pidref_get_uid() and pidref_is_my_child() to pidfd helpers 2025-01-04 17:48:22 +01:00
Mike Yuan 85e7bbfaa4 pidfd-util: introduce pidfd_get_{ppid,uid,cgroupid} which goes via PIDFD_GET_INFO too 2025-01-04 17:08:01 +01:00
Mike Yuan dcf0ef3f42 pidfd-util: try to translate pidfd -> pid through ioctl(PIDFD_GET_INFO) 2025-01-04 17:08:01 +01:00
Mike Yuan 92b8e5e72f namespace-util: introduce pidref_in_same_namespace() 2025-01-04 17:08:01 +01:00
Mike Yuan a33f691374 process-util: move namespace_get_leader() to namespace-util
This allows us to drop the hack for recursive includes.
2025-01-04 17:08:00 +01:00
Mike Yuan 4cad58788b namespace-util: hook pidref_namespace_open() up with pidfd_get_namespace()
Supersedes #35308
2025-01-04 17:08:00 +01:00
Mike Yuan 2f7cd6c70a namespace-util: correct assertion in namespace_is_init()
Follow-up for 18ead2b03d
2025-01-04 17:07:59 +01:00
Mike Yuan 07610cafcf namespace-util: modernize fd_is_namespace() and is_our_namespace()
- Make fd_is_namespace() take NamespaceType
- Drop support for kernel without NS_GET_NSTYPE (< 4.11)
- Port is_our_namespace() to namespace_open_by_type()
  (preparation for later commits, where the latter
  would go by pidfd if available, avoiding procfs)
2025-01-04 17:07:59 +01:00
Yu Watanabe 1775337a36 namespace-util: refuse remote pidref in pidref_namespace_open() 2025-01-04 17:07:59 +01:00
Mike Yuan 72661e0091 pidfd-util: introduce helper for obtaining ns fd using PIDFD_GET_*_NAMESPACE directly 2025-01-04 17:07:59 +01:00
Mike Yuan 9a7b20b6a6 errno-util: add ERRNO_IS_IOCTL_NOT_SUPPORTED that checks EINVAL additionally 2025-01-04 17:07:58 +01:00
Mike Yuan 2fa42318c3 pidref: move generic pidfd_get_inode_id() to pidfd-util
Prompted by https://github.com/systemd/systemd/pull/35224/commits/221d6e54c60389f26c2c79dbfa4e83204d2775d7

Also generalize pidfd_check_pidfs() and expose have_pidfs for later use.
2025-01-04 17:07:58 +01:00
Mike Yuan ebddfb0dee basic: introduce missing_pidfd.h 2025-01-04 16:58:13 +01:00
Mike Yuan b234026d09 process-util: extract pidfd-related funcs into pidfd-util.[ch] 2025-01-04 16:58:13 +01:00
Mike Yuan 5734893f82 tree-wide: make sigactions static const 2025-01-04 16:40:53 +01:00
Mike Yuan bed4386e29 signal-util: generalize sigaction_nop_nocldstop 2025-01-04 16:40:53 +01:00
Lennart Poettering 57e55f93bb terminal-util: modernize vtnr_from_tty() a bit 2025-01-03 21:05:58 +01:00
Daan De Meyer d0d647e084 Introduce systemd-pty-forward (#35761)
This allows running a command with tinted terminal background.
2025-01-03 19:34:42 +01:00
Lennart Poettering 8beb8c3e35 fs-util: teach xopenat_full() to pick automatically if given as MODE_INVALID 2025-01-03 12:58:43 +01:00
Daan De Meyer 9fbecf12fb tree-wide: Rename ret_slave to ret_peer 2025-01-03 09:28:13 +01:00
Daan De Meyer de8466e436 random-util: our baseline includes getrandom() (v3.17) now (#35816) 2025-01-03 09:23:06 +01:00
Mike Yuan 1de1282320 terminal-util: introduce terminal_{new,detach}_session helpers
Prompted by #35761
2025-01-02 21:14:38 +01:00
Mike Yuan 217bd588c2 terminal-util: regroup some functions 2025-01-02 20:42:20 +01:00