From 056a037761891b714ab76da263329afd3f62bc3c Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 2 Jul 2026 17:48:52 +0200 Subject: [PATCH] Abort on privilege switch failures unless errno is EPERM --- os/unix.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/os/unix.c b/os/unix.c index 3753a115..28ab58d4 100644 --- a/os/unix.c +++ b/os/unix.c @@ -1411,10 +1411,22 @@ void os_privileges_acquire(void) { if (can_switch) { if (seteuid(0) != 0) { - os_syslog(OS_LVL_INFO, "failed to acquire privileges, errno=%s(%d)", strerror(errno), errno); + if (errno == EPERM) { + /* If EPERM, process lacks permission to switch privileges (e.g. dropped capabilities); continue with active privileges */ + os_syslog(OS_LVL_INFO, "permission denied to acquire privileges, continuing with active privileges"); + } else { + os_syslog(OS_LVL_INFO, "failed to acquire privileges, errno=%s(%d)", strerror(errno), errno); + os_abort(); + } } if (setegid(0) != 0) { - os_syslog(OS_LVL_INFO, "failed to acquire group privileges, errno=%s(%d)", strerror(errno), errno); + if (errno == EPERM) { + /* If EPERM, process lacks permission to switch privileges (e.g. dropped capabilities); continue with active privileges */ + os_syslog(OS_LVL_INFO, "permission denied to acquire group privileges, continuing with active privileges"); + } else { + os_syslog(OS_LVL_INFO, "failed to acquire group privileges, errno=%s(%d)", strerror(errno), errno); + os_abort(); + } } } } @@ -1423,10 +1435,26 @@ void os_privileges_release(void) { if (can_switch) { if (setegid(unpriv_gid) != 0) { - os_syslog(OS_LVL_INFO, "failed to release group privileges, errno=%s(%d)", strerror(errno), errno); + if (errno == EPERM) { + /* + * If EPERM, process lacks permission to switch privileges (e.g. dropped capabilities); continue with active privileges + */ + os_syslog(OS_LVL_INFO, "permission denied to release group privileges, continuing with active privileges"); + } else { + os_syslog(OS_LVL_INFO, "failed to release group privileges, errno=%s(%d)", strerror(errno), errno); + os_abort(); + } } if (seteuid(unpriv_uid) != 0) { - os_syslog(OS_LVL_INFO, "failed to release privileges, errno=%s(%d)", strerror(errno), errno); + if (errno == EPERM) { + /* + * If EPERM, process lacks permission to switch privileges (e.g. dropped capabilities); continue with active privileges + */ + os_syslog(OS_LVL_INFO, "permission denied to release privileges, continuing with active privileges"); + } else { + os_syslog(OS_LVL_INFO, "failed to release privileges, errno=%s(%d)", strerror(errno), errno); + os_abort(); + } } } }