Commit graph

582 commits

Author SHA1 Message Date
Lennart Poettering 66855de739 tree-wide: make use of errno_or_else() everywhere 2019-07-11 23:20:31 +02:00
Lennart Poettering 6b7b2ed96b core: add type of resource string table 2019-07-11 12:18:51 +02:00
Lennart Poettering 4c2f584230 core: hook up service unit type with the new clean operation
The implementation is pretty straight-foward: when we get a request to
clean some type of resources we fork off a process doing that, and while
it is running we are in the "cleaning" state.
2019-07-11 12:18:51 +02:00
Yu Watanabe 4bbccb02ea tree-wide: introduce strerror_safe() 2019-07-05 02:43:56 +09:00
Michal Sekletar 33fe9e3fd0 execute: drop SYNTHETIC_ERRNO because error code was received from the apply_numa_policy() 2019-06-25 21:52:28 +02:00
Joerg Behrmann fa97f63067 core: factor root_directory application out of apply_working_directory
Fixes: #12498
2019-06-25 22:53:33 +09:00
Lennart Poettering 2193f17c08 core: mention why we do migration for everything but ConfigurationDirectory= 2019-06-25 10:47:46 +02:00
Lennart Poettering cf52c45d6b core: log when we convert from DynamicUser=1 to =0 or vice versa 2019-06-25 10:47:46 +02:00
Lennart Poettering c7e42ceb7a
Merge pull request #12869 from poettering/dynamic-user-re-migrate
DynamicUser=1 state directory back migration
2019-06-25 10:06:03 +02:00
Michal Sekletar b070c7c0e1 core: introduce NUMAPolicy and NUMAMask options
Make possible to set NUMA allocation policy for manager. Manager's
policy is by default inherited to all forked off processes. However, it
is possible to override the policy on per-service basis. Currently we
support, these policies: default, prefer, bind, interleave, local.
See man 2 set_mempolicy for details on each policy.

Overall NUMA policy actually consists of two parts. Policy itself and
bitmask representing NUMA nodes where is policy effective. Node mask can
be specified using related option, NUMAMask. Default mask can be
overwritten on per-service level.
2019-06-24 16:58:54 +02:00
Lennart Poettering 5c6d40d132 core: migrate service directories back from private if needed
Fixes: #12131
2019-06-24 16:20:34 +02:00
Lennart Poettering 3f5b15084e core: add missing space to DynamicUser=1 directory comment
(also line break again)
2019-06-24 16:20:34 +02:00
Yu Watanabe 657ee2d82b tree-wide: replace strjoin() with path_join() 2019-06-21 03:26:16 +09:00
Michal Sekletar e7fca352ba execute: dump CPUAffinity as a range string instead of a list of CPUs
We do this already when printing the property in systemctl so be
consistent and do the same for systemd-analyze dump.
2019-06-03 15:21:52 +02:00
Michal Sekletar 3f09629c22
Merge pull request #12628 from keszybz/dbus-execute
Rework cpu affinity parsing
2019-05-30 12:32:53 +02:00
Zbigniew Jędrzejewski-Szmek 0985c7c4e2 Rework cpu affinity parsing
The CPU_SET_S api is pretty bad. In particular, it has a parameter for the size
of the array, but operations which take two (CPU_EQUAL_S) or even three arrays
(CPU_{AND,OR,XOR}_S) still take just one size. This means that all arrays must
be of the same size, or buffer overruns will occur. This is exactly what our
code would do, if it received an array of unexpected size over the network.
("Unexpected" here means anything different from what cpu_set_malloc() detects
as the "right" size.)

Let's rework this, and store the size in bytes of the allocated storage area.

The code will now parse any number up to 8191, independently of what the current
kernel supports. This matches the kernel maximum setting for any architecture,
to make things more portable.

Fixes #12605.
2019-05-29 10:20:42 +02:00
Lennart Poettering 1802d5f2cf terminal-util: reset access mode in vt_restore(), too
Only changing ownership back to root is not enough we also need to
change the access mode, otherwise the user might have set 666 first, and
thus allow everyone access before and after the chown().
2019-05-24 15:07:55 +02:00
Lennart Poettering 4b3b5bc71b tree-wide: port various places over to use chmod_and_chown()
Doing this properly is hard, hence let's unify the code.
2019-05-24 15:07:55 +02:00
Lennart Poettering ccc16c7842 core: prefer SCMP_ACT_KILL_PROCESS for SystemCallFilter= behaviour
If we have it, use it. It makes a ton more sense.

Fixes: #11967
2019-05-24 10:48:28 +02:00
Zbigniew Jędrzejewski-Szmek 7cc5ef5f18 pid1: improve message when setting up namespace fails
I covered the most obvious paths: those where there's a clear problem
with a path specified by the user.

Prints something like this (at error level):
May 21 20:00:01.040418 systemd[125871]: bad-workdir.service: Failed to set up mount namespacing: /run/systemd/unit-root/etc/tomcat9/Catalina: No such file or directory
May 21 20:00:01.040456 systemd[125871]: bad-workdir.service: Failed at step NAMESPACE spawning /bin/true: No such file or directory

Fixes #10972.
2019-05-22 16:28:02 +02:00
Ben Boeckel 5238e95759 codespell: fix spelling errors 2019-04-29 16:47:18 +02:00
Lennart Poettering f69567cbe2 core: expose SUID/SGID restriction as new unit setting RestrictSUIDSGID= 2019-04-02 16:56:48 +02:00
Zbigniew Jędrzejewski-Szmek e1af3bc62a
Merge pull request #12106 from poettering/nosuidns
add "nosuid" flag to exec directory mounts of DynamicUser=1 services
2019-03-26 08:58:00 +01:00
Lennart Poettering 607b358ef2 core: drop suid/sgid bit of files/dirs when doing recursive chown
This adds some extra paranoia: when we recursively chown a directory for
use with DynamicUser=1 services we'll now drop suid/sgid from all files
we chown().

Of course, such files should not exist in the first place, and noone
should get access to those dirs who isn't root anyway, but let's better
be safe than sorry, and drop everything we come across.
2019-03-26 08:29:37 +01:00
Lennart Poettering 9ce4e4b0f6 namespace: when DynamicUser=1 is set, mount StateDirectory= bind mounts "nosuid"
Add even more suid/sgid protection to DynamicUser= envionments: the
state directories we bind mount from the host will now have the nosuid
flag set, to disable the effect of nosuid on them.
2019-03-25 19:57:15 +01:00
Lennart Poettering 6f765baf23 core: rework how we reset the TTY after use by a service
This makes two changes:

1. Instead of resetting the configured service TTY each time after a
   process exited, let's do so only when the service goes back to "dead"
   state. This should be preferable in case the started processes leave
   background child processes around that still reference the TTY.

2. chmod() and chown() the TTY at the same time. This should make it
   safe to run "systemd-run -p DynamicUser=1 -p StandardInput=tty -p
   TTYPath=/dev/tty8 /bin/bash" without leaving a TTY owned by a dynamic
   user around.
2019-03-20 21:28:02 +01:00
Lennart Poettering 6c0ae73956 execute: split check if we might touch a tty out of exec_context_may_touch_console()
Some simple refactoring that'll come handy in a later commit.
2019-03-20 21:20:00 +01:00
Lennart Poettering 955f1c852e execute: use path_equal() to compare tty names
After all they might be strings such as pts/1 which we really should
consider the same as pts//1.
2019-03-20 21:18:59 +01:00
Lennart Poettering 08f6769675 execute: generalize uid/gid handling in two cases for any kind of uid/gid 2019-03-19 16:57:33 +01:00
Lennart Poettering 206e9864de core: change ownership/mode of the execution directories also for static users
It's probably unexpected if we do a recursive chown() when dynamic users
are used but not on static users.

hence, let's tweak the logic slightly, and recursively chown in both
cases, except when operating on the configuration directory.

Fixes: #11842
2019-03-19 16:57:33 +01:00
Lennart Poettering d484580ca6 execute: remove one redundant comparison check 2019-03-19 16:52:28 +01:00
Lennart Poettering 40cd2ecc26 execute: also do the private/ symlink dance when runtime dir preservation is requested
In that case it's not safe to leave a regular dir around, hence, move it
to private/ too.
2019-03-19 16:52:28 +01:00
Lennart Poettering edbfeb1204 execute: use path_join() where appropriate 2019-03-19 16:52:28 +01:00
Lennart Poettering 7bc4bf4a69 execute: use path_join() where appropriate 2019-03-13 17:38:43 +01:00
Lennart Poettering 0a9707187b util: split out memcmp()/memset() related calls into memory-util.[ch]
Just some source rearranging.
2019-03-13 12:16:43 +01:00
Lennart Poettering 9e73208afc execute: no need to synthesize $HOME for uid==0 again, get_home_dir() already does that 2019-03-12 16:10:55 +01:00
Lennart Poettering 7bbead1d0b execute: simplify paths we set as HOME/SHELL for invoked programs 2019-03-12 16:10:55 +01:00
Zbigniew Jędrzejewski-Szmek fb6692ed33
Merge pull request #11927 from poettering/network-namespace-path
Add NetworkNamespacePath= to unit files
2019-03-12 14:29:14 +01:00
Lennart Poettering 4cea310fc7 execute: remove one aa profile output from context dump
The same data is output a few lines further up already, drop one.
2019-03-11 11:05:22 +09:00
Lennart Poettering a8d08f39d1 core: add new setting NetworkNamespacePath= for configuring a netns by path for a service
Fixes: #2741
2019-03-07 16:55:23 +01:00
Lennart Poettering da6bc6ed05 execute: no need to check for NULL when function right after does anyway 2019-03-07 16:55:19 +01:00
Lennart Poettering 2fa3742d96 execute: make things a tiny bit shorter 2019-03-07 16:53:45 +01:00
Lennart Poettering 8e8009dc50 execute: use structured initialization 2019-03-07 16:53:45 +01:00
Anita Zhang 7ca69792e5 core: add ':' prefix to ExecXYZ= skip env var substitution 2019-02-20 17:58:14 +01:00
Lennart Poettering eb5149ba74
Merge pull request #11682 from topimiettinen/private-utsname
core: ProtectHostname feature
2019-02-20 14:12:15 +01:00
Topi Miettinen aecd5ac621 core: ProtectHostname= feature
Let services use a private UTS namespace. In addition, a seccomp filter is
installed on set{host,domain}name and a ro bind mounts on
/proc/sys/kernel/{host,domain}name.
2019-02-20 10:50:44 +02:00
Franck Bui 37ed15d7ed namespace: make MountFlags=shared work again
Since commit 0722b35934, the root mountpoint is
unconditionnally turned to slave which breaks units that are using explicitly
MountFlags=shared (and no other options that would implicitly require a slave
root mountpoint).

Here is a test case:

  $ systemctl cat test-shared-mount-flag.service
  # /etc/systemd/system/test-shared-mount-flag.service
  [Service]
  Type=simple
  ExecStartPre=/usr/bin/mkdir -p /mnt/tmp
  ExecStart=/bin/sh -c "/usr/bin/mount -t tmpfs -o size=10M none /mnt/tmp && sleep infinity"
  ExecStop=-/bin/sh -c "/usr/bin/umount /mnt/tmp"
  MountFlags=shared

  $ systemctl start test-shared-mount-flag.service
  $ findmnt /mnt/tmp
  $

Mount on /mnt/tmp is not visible from the host although MountFlags=shared was
used.

This patch fixes that and turns the root mountpoint to slave when it's really
required.
2019-02-20 06:20:40 +09:00
Taro Yamada 6cff72eb0a Add a warning about the difference in permissions between existing directories and unit settings.
To follows the intent of 30c81ce, this change does not execute chmod() and just add warnings.
2019-01-29 09:52:21 +09:00
Taro Yamada ff9e7900c0 Revert "Fixes #11128"
This reverts commit 0bf05f0122 because it breaks 30c81ce.
Please see #11540.
2019-01-27 13:43:30 +09:00
Taro Yamada 0bf05f0122 Fixes #11128 2019-01-22 11:14:51 +01:00