【发布时间】:2019-08-14 02:55:15
【问题描述】:
我使用 seccomp 记录 'ping' 使用的系统调用。当我运行它时,它总是会注意到
socket:不允许操作。
我可以在bash中很好地运行ping,但是在程序中加载seccomp过滤器后没有工作。
但是如果我用root运行同样的程序,它会运行得很好。
这是在带有 4.15.0-54-generic 内核的 Ubuntu 18.04 中运行的。
我试过用Root用户运行程序,然后在子进程中,我用setuid(1000)设置为普通用户,还是不行。
如果我不使用fork,它仍然会注意到no premitted。
如果我将 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编译它。
英语不是我的第一语言,我很抱歉我的语法问题。
【问题讨论】:
-
不确定,但The inherent fragility of seccomp() 引起了我的注意。 (来自那些了解 Linux 内核的人)