Skip to content

Commit

Permalink
chore: Check CAP_SYS_ADMIN in ot_util_process_privileged
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihe774 committed Dec 20, 2024
1 parent 1bd9aa6 commit f9bf9ac
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/libotutil/ot-unix-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/prctl.h>
#include <linux/prctl.h>
#include <linux/capability.h>
#include <unistd.h>

/* Ensure that a pathname component @name does not contain the special Unix
Expand Down Expand Up @@ -107,5 +110,12 @@ ot_util_path_split_validate (const char *path, GPtrArray **out_components, GErro
gboolean
ot_util_process_privileged (void)
{
return geteuid() == 0;
if (geteuid() != 0)
return FALSE;

// https://github.com/containers/bootc/blob/c88fcfd6e145863408bde7d4706937dd323f64e2/lib/src/cli.rs#L621
if (prctl (PR_CAPBSET_READ, CAP_SYS_ADMIN) != 1)
return FALSE;

return TRUE;
}

0 comments on commit f9bf9ac

Please sign in to comment.