0

我正在使用 seccomp BPF,需要将跳转语句(始终为条件跳转/跳转)的跳转值(jt/ jf/ k)设置为存储在累加器中的值。这可能吗?我有一种预感,它不是,因为 BPF 验证器在加载过滤器之前无法检查跳转值。如果没有,是否有任何解决方法?

struct sock_filter filter = 
  {
    BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, nr)),
    BPF_STMT(BPF_JMP | BPF_JA, /* Value stored in the accumulator */),
    ...
  }

我试着看这里,但我想不出任何办法。我对 BPF 的了解也相当初级,并且只在 seccomp 的范围内。你能帮助我吗?谢谢你的时间。

4

1 回答 1

1

不,BPF 不支持间接分支指令。seccomp-bpf 和 eBPF 中使用的 cBPF 都没有。


对于 cBPF,您可以在文档中查看这一点。您将看到指令被定义为:

struct sock_filter { /* Filter block */
    __u16   code;    /* Actual filter code */
    __u8    jt;      /* Jump true */
    __u8    jf;      /* Jump false */
    __u32   k;       /* Generic multiuse field */
};

其中jtjfk可以解释为跳转偏移量,具体取决于所使用的特定跳转指令。在所有情况下,它们都被解释为立即值而不是寄存器号:

   6               L                    Jump label L
   7               #k,Lt,Lf             Jump to Lt if true, otherwise jump to Lf
   8               x/%x,Lt,Lf           Jump to Lt if true, otherwise jump to Lf
   9               #k,Lt                Jump to Lt if predicate is true
  10               x/%x,Lt              Jump to Lt if predicate is true
于 2021-07-26T17:41:28.037 回答