【问题标题】:How to write a seccomp BPF program to filter the system call instruction pointer如何编写seccomp BPF程序过滤系统调用指令指针
【发布时间】:2020-05-18 18:24:43
【问题描述】:

是否可以编写一个 seccomp-BPF 程序来过滤系统调用指令指针?例如,杀死有系统调用指令执行的进程不是来自libc

【问题讨论】:

  • “系统调用指令指针”是什么意思?系统调用的编号(id)?
  • @pchaigno 我想过滤系统调用指令的指令地址。本质上,这个: __u64 指令指针; /* CPU 指令指针 */
  • instruction_pointerstruct seccomp_data 的一部分,所以我看不出它为什么不起作用。你尝试了什么?看起来BPF_STMT(BPF_LD+BPF_DW+BPF_ABS, offsetof(struct seccomp_data, instruction_pointer)) 应该可以很好地加载您的指针。
  • (快速网络搜索节目variousexamples。)
  • 是的,想解决这个问题,但我刚刚超过了编辑 cmets 的 5 分钟限制 :)。我认为你应该把你的问题编辑变成一个答案并接受它。

标签: linux bpf ebpf seccomp


【解决方案1】:

根据@Qeole 的评论,我实现了这样的 BPF 程序:

/* https://github.com/redpig/seccomp/blob/master/tests/resumption.c */
unsigned long lib_start = 0x700000000000;
struct sock_filter filter[] = {
    /* [0] Load higher 4 bytes of the instruction pointer. */
    BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
        (offsetof(struct seccomp_data, instruction_pointer)) + sizeof(int)),
    BPF_JUMP(BPF_JMP+BPF_JGT+BPF_K, ((__u32*)&lib_start)[1], 0, 1),
    BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),
    BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL),
};

【讨论】:

    猜你喜欢
    • 2013-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-24
    • 2021-08-27
    • 2022-07-10
    • 1970-01-01
    • 2021-07-18
    相关资源
    最近更新 更多