2015-05-15 05:44:48 +08:00
|
|
|
/*
|
|
|
|
|
|
|
|
nsjail
|
|
|
|
-----------------------------------------
|
|
|
|
|
|
|
|
Copyright 2014 Google Inc. All Rights Reserved.
|
2016-01-21 03:21:27 +08:00
|
|
|
Copyright 2016 Sergiusz Bazanski. All Rights Reserved.
|
2015-05-15 05:44:48 +08:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
*/
|
2016-01-22 07:11:31 +08:00
|
|
|
|
2016-03-11 09:45:43 +08:00
|
|
|
#ifndef NS_NSJAIL_H
|
|
|
|
#define NS_NSJAIL_H
|
2015-05-15 05:44:48 +08:00
|
|
|
|
2018-02-01 21:19:01 +08:00
|
|
|
#include <linux/filter.h>
|
2017-10-18 20:27:34 +08:00
|
|
|
#include <netinet/ip6.h>
|
2017-10-18 18:33:24 +08:00
|
|
|
#include <signal.h>
|
2017-10-18 20:27:34 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <time.h>
|
2017-11-09 00:20:57 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-02-10 05:35:33 +08:00
|
|
|
#include <vector>
|
|
|
|
|
2017-11-09 00:20:57 +08:00
|
|
|
#if !defined(TEMP_FAILURE_RETRY)
|
|
|
|
#define TEMP_FAILURE_RETRY(expression) \
|
|
|
|
(__extension__({ \
|
|
|
|
long int __result; \
|
|
|
|
do \
|
|
|
|
__result = (long int)(expression); \
|
|
|
|
while (__result == -1L && errno == EINTR); \
|
|
|
|
__result; \
|
|
|
|
}))
|
|
|
|
#endif /* !defined(TEMP_FAILURE_RETRY) */
|
2017-10-18 18:33:24 +08:00
|
|
|
|
|
|
|
static const int nssigs[] = {
|
2017-10-26 06:26:02 +08:00
|
|
|
SIGINT,
|
|
|
|
SIGQUIT,
|
|
|
|
SIGUSR1,
|
|
|
|
SIGALRM,
|
|
|
|
SIGCHLD,
|
|
|
|
SIGTERM,
|
2017-10-18 18:33:24 +08:00
|
|
|
};
|
2016-03-02 00:03:11 +08:00
|
|
|
|
2017-10-18 20:27:34 +08:00
|
|
|
struct pids_t {
|
|
|
|
pid_t pid;
|
|
|
|
time_t start;
|
|
|
|
char remote_txt[64];
|
|
|
|
struct sockaddr_in6 remote_addr;
|
|
|
|
int pid_syscall_fd;
|
|
|
|
TAILQ_ENTRY(pids_t)
|
|
|
|
pointers;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mounts_t {
|
|
|
|
const char* src;
|
|
|
|
const uint8_t* src_content;
|
|
|
|
size_t src_content_len;
|
|
|
|
const char* dst;
|
|
|
|
const char* fs_type;
|
|
|
|
const char* options;
|
|
|
|
uintptr_t flags;
|
|
|
|
bool isDir;
|
|
|
|
bool isSymlink;
|
|
|
|
bool mandatory;
|
|
|
|
bool mounted;
|
|
|
|
TAILQ_ENTRY(mounts_t)
|
|
|
|
pointers;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct idmap_t {
|
|
|
|
uid_t inside_id;
|
|
|
|
uid_t outside_id;
|
|
|
|
size_t count;
|
|
|
|
bool is_newidmap;
|
|
|
|
TAILQ_ENTRY(idmap_t)
|
|
|
|
pointers;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ints_t {
|
|
|
|
int val;
|
|
|
|
TAILQ_ENTRY(ints_t)
|
|
|
|
pointers;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ns_mode_t {
|
|
|
|
MODE_LISTEN_TCP = 0,
|
|
|
|
MODE_STANDALONE_ONCE,
|
|
|
|
MODE_STANDALONE_EXECVE,
|
|
|
|
MODE_STANDALONE_RERUN
|
|
|
|
};
|
|
|
|
|
|
|
|
struct charptr_t {
|
|
|
|
const char* val;
|
|
|
|
TAILQ_ENTRY(charptr_t)
|
|
|
|
pointers;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum llevel_t {
|
|
|
|
DEBUG = 0,
|
|
|
|
INFO,
|
|
|
|
WARNING,
|
|
|
|
ERROR,
|
|
|
|
FATAL,
|
|
|
|
HELP,
|
|
|
|
HELP_BOLD,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nsjconf_t {
|
|
|
|
const char* exec_file;
|
2017-10-18 23:57:52 +08:00
|
|
|
bool use_execveat;
|
|
|
|
int exec_fd;
|
|
|
|
const char** argv;
|
2017-10-18 20:27:34 +08:00
|
|
|
const char* hostname;
|
|
|
|
const char* cwd;
|
2017-10-18 23:57:52 +08:00
|
|
|
const char* chroot;
|
2017-10-18 20:27:34 +08:00
|
|
|
int port;
|
|
|
|
const char* bindhost;
|
|
|
|
int log_fd;
|
|
|
|
const char* logfile;
|
|
|
|
enum llevel_t loglevel;
|
|
|
|
bool daemonize;
|
|
|
|
time_t tlimit;
|
|
|
|
size_t max_cpus;
|
|
|
|
bool keep_env;
|
|
|
|
bool keep_caps;
|
|
|
|
bool disable_no_new_privs;
|
2017-10-25 21:44:35 +08:00
|
|
|
uint64_t rl_as;
|
|
|
|
uint64_t rl_core;
|
|
|
|
uint64_t rl_cpu;
|
|
|
|
uint64_t rl_fsize;
|
|
|
|
uint64_t rl_nofile;
|
|
|
|
uint64_t rl_nproc;
|
|
|
|
uint64_t rl_stack;
|
2017-10-18 20:27:34 +08:00
|
|
|
unsigned long personality;
|
|
|
|
bool clone_newnet;
|
|
|
|
bool clone_newuser;
|
|
|
|
bool clone_newns;
|
|
|
|
bool clone_newpid;
|
|
|
|
bool clone_newipc;
|
|
|
|
bool clone_newuts;
|
|
|
|
bool clone_newcgroup;
|
|
|
|
enum ns_mode_t mode;
|
|
|
|
bool is_root_rw;
|
|
|
|
bool is_silent;
|
|
|
|
bool skip_setsid;
|
|
|
|
unsigned int max_conns_per_ip;
|
|
|
|
size_t tmpfs_size;
|
|
|
|
bool mount_proc;
|
|
|
|
const char* proc_path;
|
|
|
|
bool is_proc_rw;
|
|
|
|
bool iface_no_lo;
|
|
|
|
const char* iface_vs;
|
|
|
|
const char* iface_vs_ip;
|
|
|
|
const char* iface_vs_nm;
|
|
|
|
const char* iface_vs_gw;
|
|
|
|
const char* cgroup_mem_mount;
|
|
|
|
const char* cgroup_mem_parent;
|
|
|
|
size_t cgroup_mem_max;
|
|
|
|
const char* cgroup_pids_mount;
|
|
|
|
const char* cgroup_pids_parent;
|
2017-10-25 21:50:24 +08:00
|
|
|
unsigned int cgroup_pids_max;
|
2017-10-25 16:15:03 +08:00
|
|
|
const char* cgroup_net_cls_mount;
|
|
|
|
const char* cgroup_net_cls_parent;
|
|
|
|
unsigned int cgroup_net_cls_classid;
|
2018-02-04 11:15:19 +08:00
|
|
|
const char* cgroup_cpu_mount;
|
|
|
|
const char* cgroup_cpu_parent;
|
|
|
|
unsigned int cgroup_cpu_ms_per_sec;
|
2018-01-31 23:04:39 +08:00
|
|
|
const char* kafel_file_path;
|
|
|
|
const char* kafel_string;
|
2018-02-01 21:19:01 +08:00
|
|
|
struct sock_fprog seccomp_fprog;
|
2017-10-18 20:27:34 +08:00
|
|
|
long num_cpus;
|
2017-10-20 04:39:37 +08:00
|
|
|
uid_t orig_uid;
|
2017-10-18 20:27:34 +08:00
|
|
|
TAILQ_HEAD(udmaplist, idmap_t)
|
|
|
|
uids;
|
|
|
|
TAILQ_HEAD(gdmaplist, idmap_t)
|
|
|
|
gids;
|
|
|
|
TAILQ_HEAD(envlist, charptr_t)
|
|
|
|
envs;
|
|
|
|
TAILQ_HEAD(pidslist, pids_t)
|
|
|
|
pids;
|
|
|
|
TAILQ_HEAD(mountptslist, mounts_t)
|
|
|
|
mountpts;
|
2018-02-10 05:47:00 +08:00
|
|
|
std::vector<int> openfds;
|
2018-02-10 05:35:33 +08:00
|
|
|
std::vector<int> caps;
|
2017-10-18 20:27:34 +08:00
|
|
|
};
|
|
|
|
|
2017-10-09 05:00:45 +08:00
|
|
|
#endif /* _NSJAIL_H */
|