seccomp_init的作用就是初始化 scmp_filter_ctx结构。
需要注意的是,任何其他libseccomp中的函数调用,必须在seccomp_init之后。
- 函数定义
scmp_filter_ctx seccomp_init(uint32_t def_action);
- 返回值
成功返回scmp_filter_ctx(过滤器上下文) ctx;
失败返回NULL
- 参数说明
def_action用于指定默认行为,有效动作值如下:(当线程调用了seccomp
过滤规则中没有相关配置规则的系统调用时触发)
- SCMP_ACT_KILL
线程将会被内核以SIGSYS信号终止;
- SCMP_ACT_KILL_PROCESS
整个进程被终止;
- SCMP_ACT_TRAP
线程将会抛出一个SIGSYS信号;
- SCMP_ACT_ERRNO(uint16_t errno)
线程调用与筛选规则匹配的系统调用时,它将收到一个errno的返回值;
- SCMP_ACT_TRACE(uint16_t msg_num)
略
- SCMP_ACT_LOG
不会对调用系统调用的线程产生任何影响,但系统调用会被记录到日志。
- SCMP_ACT_ALLOW
不会对调用系统调用的线程产生任何影响。
seccomp_rule_addXXX
函数说明:
这个函数组都会向当前seccomp过滤器添加新的过滤规则。
调用应用程序提供的所有过滤器规则被组合成一个联合,并带有额外的逻辑来消除冗余的系统调用过滤器。
例如,如果添加了一条规则,该规则允许给定的系统调用具有一组特定的参数值,
然后又添加了一条规则,该规则允许相同的系统调用而不管参数值如何,
那么第一个更具体的规则将有效地从过滤器中删除第二个更通用的规则。
函数定义
int seccomp_rule_add(scmp_filter_ctx ctx, uint32_t action,
int syscall, unsigned int arg_cnt, …);
int seccomp_rule_add_exact(scmp_filter_ctx ctx, uint32_t action,
int syscall, unsigned int arg_cnt, …);
int seccomp_rule_add_array(scmp_filter_ctx ctx,
uint32_t action, int syscall,
unsigned int arg_cnt,
const struct scmp_arg_cmp *arg_array);
int seccomp_rule_add_exact_array(scmp_filter_ctx ctx,
uint32_t action, int syscall,
unsigned int arg_cnt,
const struct scmp_arg_cmp *arg_array);
参数说明
-
- action有效动作值如下:(当线程调用了
seccomp
过滤规则中有相关配置规则的系统调用时触发)
- action有效动作值如下:(当线程调用了