1 From 1e3883563faf35dea24bdd07d08d5659211bdeb5 Mon Sep 17 00:00:00 2001
2 From: Andy Fiddaman <illumos@fiddaman.net>
3 Date: Fri, 30 Dec 2022 18:06:57 +0000
4 Subject: Drop unnecessary privileges
7 os-posix.c | 41 +++++++++++++++++++++++++++++++++++++++++
8 1 file changed, 41 insertions(+)
10 diff --git a/os-posix.c b/os-posix.c
11 index 4858650c3e..26b7741023 100644
20 /* Needed early for CONFIG_BSD etc. */
21 #include "net/slirp.h"
22 @@ -263,6 +264,45 @@ void os_daemonize(void)
27 + * In case qemu is started as root, drop unnecessary privileges.
30 +illumos_drop_privileges(void)
32 + priv_set_t *privs, *wantedprivs;
34 + privs = priv_allocset();
35 + wantedprivs = priv_allocset();
37 + if (privs == NULL || wantedprivs == NULL) {
38 + error_report("Unable to allocate privilege sets");
42 + if (getppriv(PRIV_PERMITTED, privs) != 0) {
43 + error_report("Failed to retrieve current privileges");
47 + priv_basicset(wantedprivs);
48 + priv_delset(wantedprivs, PRIV_FILE_LINK_ANY);
49 + priv_delset(wantedprivs, PRIV_PROC_INFO);
50 + priv_delset(wantedprivs, PRIV_PROC_SESSION);
51 + priv_addset(wantedprivs, PRIV_NET_RAWACCESS); /* VNIC net backend */
52 + priv_intersect(wantedprivs, privs);
54 + if (setppriv(PRIV_SET, PRIV_PERMITTED, privs) != 0 ||
55 + setppriv(PRIV_SET, PRIV_INHERITABLE, privs) != 0 ||
56 + setppriv(PRIV_SET, PRIV_LIMIT, privs) != 0) {
57 + error_report("Failed to reduce privileges");
61 + priv_freeset(wantedprivs);
62 + priv_freeset(privs);
65 void os_setup_post(void)
68 @@ -280,6 +320,7 @@ void os_setup_post(void)
72 + illumos_drop_privileges();