bpf_prog03: Add regression test for sign extension bug
PATCH 1/1 bpf_prog03: Add regression test for sign extension bug
Signed-off-by Richard Palethorpe <[email protected]>
--- include/lapi/bpf.h | 13 ++ runtest/cve | 1 + runtest/syscalls | 1 + testcases/kernel/syscalls/bpf/.gitignore | 1 + testcases/kernel/syscalls/bpf/bpf_common.h | 15 ++ testcases/kernel/syscalls/bpf/bpf_map01.c | 13 +- testcases/kernel/syscalls/bpf/bpf_prog02.c | 11 +- testcases/kernel/syscalls/bpf/bpf_prog03.c | 191 +++++++++++++++++++++ 8 files changed, 224 insertions(+), 22 deletions(-) create mode 100644 testcases/kernel/syscalls/bpf/bpf_prog03.c
include/lapi/bpf.h +13 -0
@@ -21,8 +21,11 @@#define BPF_LDX 0x01#define BPF_ST 0x02#define BPF_STX 0x03 +#define BPF_ALU 0x04#define BPF_JMP 0x05 +#define BPF_JNE 0x50/* jump != */ +#define BPF_SIZE (code) ((code) & 0x18)#define BPF_W 0x00/* 32-bit */ #define BPF_DW 0x18/* double word (64-bit) */
@@ -34,6 +37,8 @@#define BPF_OP (code) ((code) & 0xf0)#define BPF_ADD 0x00#define BPF_SUB 0x10 +#define BPF_LSH 0x60 +#define BPF_RSH 0x70#define BPF_JEQ 0x10
@@ -521,6 +526,14 @@ enum bpf_func_id { .off = 0, \ .imm = IMM }) +#define BPF_MOV32_IMM (DST ,IMM ) \ + ((struct bpf_insn) { \ + .code = BPF_ALU | BPF_MOV | BPF_K, \ + .dst_reg = DST, \ + .src_reg = 0, \ + .off = 0, \ + .imm = IMM }) +#define BPF_EMIT_CALL (FUNC ) \ ((struct bpf_insn) { \ .code = BPF_JMP | BPF_CALL, \
runtest/cve +1 -0
@@ -33,6 +33,7 @@ cve-2017-1000364 stack_clash cve-2017-5754 meltdown cve-2017-17052 cve-2017-17052 cve-2017-16939 cve-2017-16939 +cve-2017-16995 bpf_prog03 cve-2017-17053 cve-2017-17053 cve-2017-18075 pcrypt_aead01 cve-2017-1000380 snd_timer01
runtest/syscalls +1 -0
@@ -35,6 +35,7 @@ bind03 bind03 bpf_map01 bpf_map01 bpf_prog01 bpf_prog01 bpf_prog02 bpf_prog02 +bpf_prog03 bpf_prog03 brk01 brk01
testcases/kernel/syscalls/bpf/.gitignore +1 -0
@@ -1,3 +1,4 @@ bpf_map01 bpf_prog01 bpf_prog02 +bpf_prog03
testcases/kernel/syscalls/bpf/bpf_common.h +15 -0
@@ -28,4 +28,19 @@ void rlimit_bump_memlock(void) } } +int bpf_map_create (union bpf_attr *attr) +{ +TEST (bpf (BPF_MAP_CREATE , attr,sizeof (*attr))); +if (TST_RET ==-1 ) { +if (TST_ERR ==EPERM ) { +tst_brk (TCONF |TTERRNO , +"bpf() requires CAP_SYS_ADMIN on this system" ); + }else { +tst_brk (TBROK |TTERRNO ,"Failed to create array map" ); + } + } + +return TST_RET ; +} +#endif
testcases/kernel/syscalls/bpf/bpf_map01.c +1 -12
@@ -50,19 +50,8 @@ void run(unsigned int n) attr->value_size =VAL_SZ ; attr->max_entries =1 ; -TEST (bpf (BPF_MAP_CREATE , attr,sizeof (*attr))); -if (TST_RET ==-1 ) { -if (TST_ERR ==EPERM ) { -tst_brk (TCONF |TTERRNO , -"bpf() requires CAP_SYS_ADMIN on this system" ); - }else { -tst_res (TFAIL |TTERRNO ,"Failed to create %s map" , - map_types[n].name); -return ; - } - } + fd =bpf_map_create (attr);tst_res (TPASS ,"Created %s map" , map_types[n].name); - fd =TST_RET ;memset (attr,0 ,sizeof (*attr)); attr->map_fd = fd;
testcases/kernel/syscalls/bpf/bpf_prog02.c +1 -10
@@ -111,16 +111,7 @@ static void run(void) attr->value_size =8 ; attr->max_entries =2 ; -TEST (bpf (BPF_MAP_CREATE , attr,sizeof (*attr))); -if (TST_RET ==-1 ) { -if (TST_ERR ==EPERM ) { -tst_brk (TCONF |TTERRNO , -"bpf() requires CAP_SYS_ADMIN on this system" ); - }else { -tst_brk (TBROK |TTERRNO ,"Failed to create array map" ); - } - } - map_fd =TST_RET ; + map_fd =bpf_map_create (attr); prog_fd =load_prog (map_fd);
testcases/kernel/syscalls/bpf/bpf_prog03.c new file +191 -0
191 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH 1/1 bpf_prog03: Add regression test for sign extension bug
Hi!
Applied, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]