Skip to content

Commit 9e49e88

Browse files
Daniel Borkmanndavem330
authored andcommitted
filter: add XOR instruction for use with X/K
SKF_AD_ALU_XOR_X has been added a while ago, but as an 'ancillary' operation that is invoked through a negative offset in K within BPF load operations. Since BPF_MOD has recently been added, BPF_XOR should also be part of the common ALU operations. Removing SKF_AD_ALU_XOR_X might not be an option since this is exposed to user space. Signed-off-by: Daniel Borkmann <daniel.borkmann@tik.ee.ethz.ch> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 718cffc commit 9e49e88

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎include/linux/filter.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
7575
#define BPF_RSH 0x70
7676
#define BPF_NEG 0x80
7777
#define BPF_MOD 0x90
78+
#define BPF_XOR 0xa0
7879

7980
#define BPF_JA 0x00
8081
#define BPF_JEQ 0x10
@@ -204,6 +205,8 @@ enum {
204205
BPF_S_ALU_AND_X,
205206
BPF_S_ALU_OR_K,
206207
BPF_S_ALU_OR_X,
208+
BPF_S_ALU_XOR_K,
209+
BPF_S_ALU_XOR_X,
207210
BPF_S_ALU_LSH_K,
208211
BPF_S_ALU_LSH_X,
209212
BPF_S_ALU_RSH_K,

‎net/core/filter.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
187187
case BPF_S_ALU_OR_K:
188188
A |= K;
189189
continue;
190+
case BPF_S_ANC_ALU_XOR_X:
191+
case BPF_S_ALU_XOR_X:
192+
A ^= X;
193+
continue;
194+
case BPF_S_ALU_XOR_K:
195+
A ^= K;
196+
continue;
190197
case BPF_S_ALU_LSH_X:
191198
A <<= X;
192199
continue;
@@ -334,9 +341,6 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
334341
case BPF_S_ANC_CPU:
335342
A = raw_smp_processor_id();
336343
continue;
337-
case BPF_S_ANC_ALU_XOR_X:
338-
A ^= X;
339-
continue;
340344
case BPF_S_ANC_NLATTR: {
341345
struct nlattr *nla;
342346

@@ -483,6 +487,8 @@ int sk_chk_filter(struct sock_filter *filter, unsigned int flen)
483487
[BPF_ALU|BPF_AND|BPF_X] = BPF_S_ALU_AND_X,
484488
[BPF_ALU|BPF_OR|BPF_K] = BPF_S_ALU_OR_K,
485489
[BPF_ALU|BPF_OR|BPF_X] = BPF_S_ALU_OR_X,
490+
[BPF_ALU|BPF_XOR|BPF_K] = BPF_S_ALU_XOR_K,
491+
[BPF_ALU|BPF_XOR|BPF_X] = BPF_S_ALU_XOR_X,
486492
[BPF_ALU|BPF_LSH|BPF_K] = BPF_S_ALU_LSH_K,
487493
[BPF_ALU|BPF_LSH|BPF_X] = BPF_S_ALU_LSH_X,
488494
[BPF_ALU|BPF_RSH|BPF_K] = BPF_S_ALU_RSH_K,

0 commit comments

Comments
 (0)