X Tutup
Skip to content

Commit 63e8df0

Browse files
committed
pid1: add taint flag if uid/gid userns range too small
This will taint systemd if invoked in containers that do not have the full 16bit range of UIDs defined. we pretty much need uid root…nobody to be defined for a variety of purposes, hence let's add this taint flag. Of course taints are graceful, but it at least communicates the mess in some way...
1 parent 5565604 commit 63e8df0

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

src/core/manager.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#include "terminal-util.h"
8383
#include "time-util.h"
8484
#include "transaction.h"
85+
#include "uid-range.h"
8586
#include "umask-util.h"
8687
#include "unit-name.h"
8788
#include "user-util.h"
@@ -4350,16 +4351,34 @@ int manager_dispatch_user_lookup_fd(sd_event_source *source, int fd, uint32_t re
43504351
return 0;
43514352
}
43524353

4354+
static int short_uid_range(const char *path) {
4355+
_cleanup_free_ UidRange *p = NULL;
4356+
size_t n = 0;
4357+
int r;
4358+
4359+
assert(path);
4360+
4361+
/* Taint systemd if we the UID range assigned to this environment doesn't at least cover 0…65534,
4362+
* i.e. from root to nobody. */
4363+
4364+
r = uid_range_load_userns(&p, &n, path);
4365+
if (ERRNO_IS_NOT_SUPPORTED(r))
4366+
return false;
4367+
if (r < 0)
4368+
return log_debug_errno(r, "Failed to load %s: %m", path);
4369+
4370+
return !uid_range_covers(p, n, 0, 65535);
4371+
}
4372+
43534373
char *manager_taint_string(Manager *m) {
43544374
_cleanup_free_ char *destination = NULL, *overflowuid = NULL, *overflowgid = NULL;
43554375
struct utsname uts;
43564376
char *buf, *e;
43574377
int r;
43584378

4359-
/* Returns a "taint string", e.g. "local-hwclock:var-run-bad".
4360-
* Only things that are detected at runtime should be tagged
4361-
* here. For stuff that is set during compilation, emit a warning
4362-
* in the configuration phase. */
4379+
/* Returns a "taint string", e.g. "local-hwclock:var-run-bad". Only things that are detected at
4380+
* runtime should be tagged here. For stuff that is set during compilation, emit a warning in the
4381+
* configuration phase. */
43634382

43644383
assert(m);
43654384

@@ -4370,7 +4389,9 @@ char *manager_taint_string(Manager *m) {
43704389
"var-run-bad:"
43714390
"overflowuid-not-65534:"
43724391
"overflowgid-not-65534:"
4373-
"old-kernel:"));
4392+
"old-kernel:"
4393+
"short-uid-range:"
4394+
"short-gid-range:"));
43744395
if (!buf)
43754396
return NULL;
43764397

@@ -4396,7 +4417,6 @@ char *manager_taint_string(Manager *m) {
43964417
r = read_one_line_file("/proc/sys/kernel/overflowuid", &overflowuid);
43974418
if (r >= 0 && !streq(overflowuid, "65534"))
43984419
e = stpcpy(e, "overflowuid-not-65534:");
4399-
44004420
r = read_one_line_file("/proc/sys/kernel/overflowgid", &overflowgid);
44014421
if (r >= 0 && !streq(overflowgid, "65534"))
44024422
e = stpcpy(e, "overflowgid-not-65534:");
@@ -4405,6 +4425,11 @@ char *manager_taint_string(Manager *m) {
44054425
if (strverscmp_improved(uts.release, KERNEL_BASELINE_VERSION) < 0)
44064426
e = stpcpy(e, "old-kernel:");
44074427

4428+
if (short_uid_range("/proc/self/uid_map") > 0)
4429+
e = stpcpy(e, "short-uid-range:");
4430+
if (short_uid_range("/proc/self/gid_map") > 0)
4431+
e = stpcpy(e, "short-gid-range:");
4432+
44084433
/* remove the last ':' */
44094434
if (e != buf)
44104435
e[-1] = 0;

0 commit comments

Comments
 (0)
X Tutup