core: use setreuid/setregid trick to create session keyring with right ownership...
authorDimitri John Ledkov <xnox@ubuntu.com>
Tue, 27 Mar 2018 10:58:10 +0000 (11:58 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Mar 2018 10:58:10 +0000 (12:58 +0200)
commite64c2d0b5fbd8ab75d8f73f5820696ee15c8c6f0
treeb8f15f6b9bdc6039dfcca8e6408a17868190ab2d
parent96d4d0244bf6eabfd3598177101046653cb70e64
core: use setreuid/setregid trick to create session keyring with right ownership (#8447)

Re-use the hacks used to link user keyring, when creating the session
keyring. This way changing ownership of the keyring is not required, and thus
incovation_id can be correctly created in restricted environments.

Creating invocation_id with root permissions works and linking it into session
keyring works, as at that point session keyring is possessed.

Simple way to validate this is with following commands:

$ journalctl -f &
$ sudo systemd-run --uid 1000 /bin/sh -c 'keyctl describe @s; keyctl list @s; keyctl read `keyctl search @s user invocation_id`'

which now works in LXD containers as well as on the host.

Fixes: https://github.com/systemd/systemd/issues/7655
src/core/execute.c