我使用 seccomp 记录 'ping' 使用的系统调用。当我运行它时,它总是注意到
套接字:不允许操作。
我可以很好地在 bash 中运行 ping,但是在程序中加载 seccomp 过滤器后没有工作。
但是如果我用root运行同样的程序,它会运行得很好。
这是在具有 4.15.0-54-generic 内核的 Ubuntu 18.04 中运行的。
我试过用root用户运行程序,然后在子进程中,我用setuid(1000)设置为普通用户,还是不行。
如果我不使用 fork,它仍然会注意到没有预设。
如果我将 seccomp 默认操作更改为 SCMP_ACT_ALLOW,它仍然不起作用。
这是C的一个简单代码。
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <signal.h>
#include <seccomp.h>
#include <unistd.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/wait.h>
void child() {
setuid(1000);
scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_LOG);
if (seccomp_load(ctx) != 0) {
printf("SCMP LAOD ERR!");
} else {
seccomp_release(ctx);
}
execl("/bin/ping", "ping", "-c", "1", "172.16.1.1", NULL);
printf("EXEC FAIL");
}
int main(){
int p = fork();
if (p < 0) {
printf("Frok ERROR!");
exit(1);
}
if ( p == 0 ) {
child();
} else {
struct rusage usage;
int status;
if (wait4(p, &status, WSTOPPED, &usage) == -1) {
kill(p, SIGKILL);
}
}
}
我gcc main.c -o main.out -lseccomp
用来编译它。
英语不是我的第一语言,我对我的语法感到抱歉。