Skip to content

Commit 437a851

Browse files
eworm-depoettering
authored andcommitted
core: link user keyring to session keyring (#6275)
Commit 74dd6b5 (core: run each system service with a fresh session keyring) broke adding keys to user keyring. Added keys could not be accessed with error message: keyctl_read_alloc: Permission denied So link the user keyring to our session keyring.
1 parent 2240fc5 commit 437a851

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/basic/missing.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,10 @@ typedef int32_t key_serial_t;
10931093
#define KEYCTL_DESCRIBE 6
10941094
#endif
10951095

1096+
#ifndef KEYCTL_LINK
1097+
#define KEYCTL_LINK 8
1098+
#endif
1099+
10961100
#ifndef KEYCTL_READ
10971101
#define KEYCTL_READ 11
10981102
#endif

src/core/execute.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,14 @@ static int setup_keyring(Unit *u, const ExecParameters *p, uid_t uid, gid_t gid)
20992099
return 0;
21002100
}
21012101

2102+
/* Having our own session keyring is nice, but results in keys added
2103+
* to the user keyring being inaccessible with permission denied.
2104+
* So link the user keyring to our session keyring. */
2105+
if (keyctl(KEYCTL_LINK,
2106+
KEY_SPEC_USER_KEYRING,
2107+
keyring, 0, 0) < 0)
2108+
return log_debug_errno(errno, "Failed to link user keyring to session keyring.");
2109+
21022110
/* Populate they keyring with the invocation ID by default. */
21032111
if (!sd_id128_is_null(u->invocation_id)) {
21042112
key_serial_t key;

0 commit comments

Comments
 (0)