aboutgitcodebugslistschat
path: root/util.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-09-12 22:24:03 +1000
committerStefano Brivio <sbrivio@redhat.com>2022-09-13 05:31:51 +0200
commitd72a1e7bb96b461eb47d921436f7fe344e7b268a (patch)
tree907c832672c6f241aac406b6b3dc72ebaa879f64 /util.c
parent5d3b50c1006590c4b5aab7339203880caa8f2525 (diff)
downloadpasst-d72a1e7bb96b461eb47d921436f7fe344e7b268a.tar
passt-d72a1e7bb96b461eb47d921436f7fe344e7b268a.tar.gz
passt-d72a1e7bb96b461eb47d921436f7fe344e7b268a.tar.bz2
passt-d72a1e7bb96b461eb47d921436f7fe344e7b268a.tar.lz
passt-d72a1e7bb96b461eb47d921436f7fe344e7b268a.tar.xz
passt-d72a1e7bb96b461eb47d921436f7fe344e7b268a.tar.zst
passt-d72a1e7bb96b461eb47d921436f7fe344e7b268a.zip
Move self-isolation code into a separate file
passt/pasta contains a number of routines designed to isolate passt from the rest of the system for security. These are spread through util.c and passt.c. Move them together into a new isolation.c file. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'util.c')
-rw-r--r--util.c51
1 files changed, 0 insertions, 51 deletions
diff --git a/util.c b/util.c
index ce88aee..f709838 100644
--- a/util.c
+++ b/util.c
@@ -13,30 +13,17 @@
*/
#include <sched.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <net/ethernet.h>
-#include <net/if.h>
-#include <netinet/tcp.h>
-#include <netinet/udp.h>
#include <sys/epoll.h>
-#include <sys/prctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
#include <fcntl.h>
#include <syslog.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include <errno.h>
-#include <pwd.h>
-#include <grp.h>
-
-#include <linux/capability.h>
#include "util.h"
#include "passt.h"
@@ -468,44 +455,6 @@ void procfs_scan_listen(struct ctx *c, uint8_t proto, int ip_version, int ns,
}
/**
- * drop_caps() - Drop capabilities we might have except for CAP_NET_BIND_SERVICE
- */
-void drop_caps(void)
-{
- int i;
-
- for (i = 0; i < 64; i++) {
- if (i == CAP_NET_BIND_SERVICE)
- continue;
-
- prctl(PR_CAPBSET_DROP, i, 0, 0, 0);
- }
-}
-
-/**
- * drop_root() - Switch to given UID and GID
- * @uid: User ID to switch to
- * @gid: Group ID to switch to
- */
-void drop_root(uid_t uid, gid_t gid)
-{
- if (setgroups(0, NULL)) {
- /* If we don't start with CAP_SETGID, this will EPERM */
- if (errno != EPERM) {
- err("Can't drop supplementary groups: %s",
- strerror(errno));
- exit(EXIT_FAILURE);
- }
- }
-
- if (!setgid(gid) && !setuid(uid))
- return;
-
- err("Can't change user/group, exiting");
- exit(EXIT_FAILURE);
-}
-
-/**
* ns_enter() - Enter configured user (unless already joined) and network ns
* @c: Execution context
*