From: Nick Rosbrook Date: Tue, 22 Nov 2022 15:33:55 +0000 (-0500) Subject: oomd: always allow root-owned cgroups to set ManagedOOMPreference X-Git-Tag: v253-rc1~456^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89186093485b52ca957d17842fc1f7c87958454a;p=thirdparty%2Fsystemd.git oomd: always allow root-owned cgroups to set ManagedOOMPreference Commit 652a4efb66a ("oomd: loosen the restriction on ManagedOOMPreference") made the change to allow ManagedOOMPreference on a cgroup candidate when the monitored cgroup and cgroup candidate are owned by the same user. The commit assumed that this check was sufficient to continue allowing ManagedOOMPreference on all cgroups owned by root. However, it caused a regression for unprivileged LXD containers where e.g. /sys/fs/cgroup is owned by nobody (uid=65534). Fix this by explicitly allowing the ManagedOOMPreference if uid == 0 in oomd_fetch_cgroup_oom_preference(). --- diff --git a/src/oom/oomd-util.c b/src/oom/oomd-util.c index 1fc81d18434..70a1dc941e6 100644 --- a/src/oom/oomd-util.c +++ b/src/oom/oomd-util.c @@ -164,7 +164,7 @@ int oomd_fetch_cgroup_oom_preference(OomdCGroupContext *ctx, const char *prefix) if (r < 0) return log_debug_errno(r, "Failed to get owner/group from %s: %m", ctx->path); - if (uid == prefix_uid) { + if (uid == prefix_uid || uid == 0) { /* Ignore most errors when reading the xattr since it is usually unset and cgroup xattrs are only used * as an optional feature of systemd-oomd (and the system might not even support them). */ r = cg_get_xattr_bool(SYSTEMD_CGROUP_CONTROLLER, ctx->path, "user.oomd_avoid");