mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-10-14 02:22:03 +08:00
In linux run the server in it's own container with separate IPC and PID namespace
This commit is contained in:
@@ -278,6 +278,28 @@ AC_LIB_HAVE_LINKFLAGS(seccomp,, [#include <seccomp.h>], [seccomp_init(0);])
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
AC_ARG_ENABLE(linux-namespaces,
|
||||||
|
AS_HELP_STRING([--disable-linux-namespaces], [disable support for different namespaces in Linux]),
|
||||||
|
linux_ns_enabled=$enableval, linux_ns_enabled=yes)
|
||||||
|
|
||||||
|
if [ test "$linux_ns_enabled" = "yes" ];then
|
||||||
|
AC_MSG_CHECKING([for Linux namespaces])
|
||||||
|
dnl We use Linux namespaces only in the platforms clone() works as expected
|
||||||
|
AC_LINK_IFELSE([AC_LANG_PROGRAM([
|
||||||
|
#include <sched.h>],[
|
||||||
|
#if defined(__i386__) || defined(__arm__) || defined(__x86_64__) || defined(__mips__)
|
||||||
|
unshare(CLONE_NEWPID|CLONE_NEWIPC);
|
||||||
|
#else
|
||||||
|
# error 1
|
||||||
|
#endif])],
|
||||||
|
[AC_MSG_RESULT(yes)
|
||||||
|
AC_DEFINE([ENABLE_LINUX_NS], 1, [Enable Linux namespaces support])
|
||||||
|
linux_ns_enabled=yes],
|
||||||
|
[AC_MSG_RESULT(no)
|
||||||
|
linux_ns_enabled=no
|
||||||
|
])
|
||||||
|
fi
|
||||||
|
|
||||||
AC_ARG_ENABLE(systemd,
|
AC_ARG_ENABLE(systemd,
|
||||||
AS_HELP_STRING([--disable-systemd], [disable systemd support]),
|
AS_HELP_STRING([--disable-systemd], [disable systemd support]),
|
||||||
systemd_enabled=$enableval, systemd_enabled=yes)
|
systemd_enabled=$enableval, systemd_enabled=yes)
|
||||||
@@ -429,6 +451,7 @@ AC_MSG_NOTICE([
|
|||||||
|
|
||||||
Experimental options:
|
Experimental options:
|
||||||
seccomp: ${seccomp_enabled}
|
seccomp: ${seccomp_enabled}
|
||||||
|
Linux namespaces: ${linux_ns_enabled}
|
||||||
Anyconnect compat: ${anyconnect_enabled}
|
Anyconnect compat: ${anyconnect_enabled}
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|||||||
@@ -937,6 +937,9 @@ void print_version(tOptions *opts, tOptDesc *desc)
|
|||||||
#ifdef HAVE_LIBSECCOMP
|
#ifdef HAVE_LIBSECCOMP
|
||||||
fprintf(stderr, "seccomp, ");
|
fprintf(stderr, "seccomp, ");
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ENABLE_LINUX_NS
|
||||||
|
fprintf(stderr, "Linux-NS, ");
|
||||||
|
#endif
|
||||||
#ifdef HAVE_LIBWRAP
|
#ifdef HAVE_LIBWRAP
|
||||||
fprintf(stderr, "tcp-wrappers, ");
|
fprintf(stderr, "tcp-wrappers, ");
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+2
-1
@@ -1122,7 +1122,7 @@ int main(int argc, char** argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pid = fork();
|
pid = safe_fork();
|
||||||
if (pid == 0) { /* child */
|
if (pid == 0) { /* child */
|
||||||
/* close any open descriptors, and erase
|
/* close any open descriptors, and erase
|
||||||
* sensitive data before running the worker
|
* sensitive data before running the worker
|
||||||
@@ -1168,6 +1168,7 @@ int main(int argc, char** argv)
|
|||||||
exit(0);
|
exit(0);
|
||||||
} else if (pid == -1) {
|
} else if (pid == -1) {
|
||||||
fork_failed:
|
fork_failed:
|
||||||
|
mslog(s, NULL, LOG_ERR, "fork failed");
|
||||||
close(cmd_fd[0]);
|
close(cmd_fd[0]);
|
||||||
} else { /* parent */
|
} else { /* parent */
|
||||||
/* add_proc */
|
/* add_proc */
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
# include <sys/prctl.h>
|
# include <sys/prctl.h>
|
||||||
|
# include <sched.h>
|
||||||
|
# include <sys/syscall.h>
|
||||||
#endif
|
#endif
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
@@ -49,6 +51,20 @@ void pr_set_undumpable(const char *mod)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid_t safe_fork(void)
|
||||||
|
{
|
||||||
|
#if defined(__linux__) && defined(ENABLE_LINUX_NS)
|
||||||
|
long ret;
|
||||||
|
int flags = SIGCHLD|CLONE_NEWPID|CLONE_NEWNET|CLONE_NEWIPC;
|
||||||
|
ret = syscall(SYS_clone, flags, 0, 0, 0);
|
||||||
|
if (ret == 0 && syscall(SYS_getpid)!= 1)
|
||||||
|
return -1;
|
||||||
|
return ret;
|
||||||
|
#else
|
||||||
|
return fork();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
SIGHANDLER_T ocsignal(int signum, SIGHANDLER_T handler)
|
SIGHANDLER_T ocsignal(int signum, SIGHANDLER_T handler)
|
||||||
{
|
{
|
||||||
struct sigaction new_action, old_action;
|
struct sigaction new_action, old_action;
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ typedef void (*sighandler_t)(int);
|
|||||||
# define SIGHANDLER_T sighandler_t
|
# define SIGHANDLER_T sighandler_t
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
pid_t safe_fork(void);
|
||||||
void pr_set_undumpable(const char* mod);
|
void pr_set_undumpable(const char* mod);
|
||||||
void kill_on_parent_kill(int sig);
|
void kill_on_parent_kill(int sig);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user