|
@@ -2592,6 +2592,29 @@ static struct bpf_test tests[] = {
|
|
|
.result = ACCEPT,
|
|
|
.prog_type = BPF_PROG_TYPE_SCHED_CLS,
|
|
|
},
|
|
|
+ {
|
|
|
+ "context stores via ST",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_1, offsetof(struct __sk_buff, mark), 0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .errstr = "BPF_ST stores into R1 context is not allowed",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_SCHED_CLS,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "context stores via XADD",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_RAW_INSN(BPF_STX | BPF_XADD | BPF_W, BPF_REG_1,
|
|
|
+ BPF_REG_0, offsetof(struct __sk_buff, mark), 0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .errstr = "BPF_XADD stores into R1 context is not allowed",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_SCHED_CLS,
|
|
|
+ },
|
|
|
{
|
|
|
"direct packet access: test1",
|
|
|
.insns = {
|
|
@@ -4312,7 +4335,8 @@ static struct bpf_test tests[] = {
|
|
|
.fixup_map1 = { 2 },
|
|
|
.errstr_unpriv = "R2 leaks addr into mem",
|
|
|
.result_unpriv = REJECT,
|
|
|
- .result = ACCEPT,
|
|
|
+ .result = REJECT,
|
|
|
+ .errstr = "BPF_XADD stores into R1 context is not allowed",
|
|
|
},
|
|
|
{
|
|
|
"leak pointer into ctx 2",
|
|
@@ -4326,7 +4350,8 @@ static struct bpf_test tests[] = {
|
|
|
},
|
|
|
.errstr_unpriv = "R10 leaks addr into mem",
|
|
|
.result_unpriv = REJECT,
|
|
|
- .result = ACCEPT,
|
|
|
+ .result = REJECT,
|
|
|
+ .errstr = "BPF_XADD stores into R1 context is not allowed",
|
|
|
},
|
|
|
{
|
|
|
"leak pointer into ctx 3",
|
|
@@ -6707,7 +6732,7 @@ static struct bpf_test tests[] = {
|
|
|
BPF_JMP_IMM(BPF_JA, 0, 0, -7),
|
|
|
},
|
|
|
.fixup_map1 = { 4 },
|
|
|
- .errstr = "unbounded min value",
|
|
|
+ .errstr = "R0 invalid mem access 'inv'",
|
|
|
.result = REJECT,
|
|
|
},
|
|
|
{
|
|
@@ -8608,6 +8633,127 @@ static struct bpf_test tests[] = {
|
|
|
.prog_type = BPF_PROG_TYPE_XDP,
|
|
|
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
|
|
|
},
|
|
|
+ {
|
|
|
+ "check deducing bounds from const, 1",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 1),
|
|
|
+ BPF_JMP_IMM(BPF_JSGE, BPF_REG_0, 1, 0),
|
|
|
+ BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .result = REJECT,
|
|
|
+ .errstr = "R0 tried to subtract pointer from scalar",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "check deducing bounds from const, 2",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 1),
|
|
|
+ BPF_JMP_IMM(BPF_JSGE, BPF_REG_0, 1, 1),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ BPF_JMP_IMM(BPF_JSLE, BPF_REG_0, 1, 1),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ BPF_ALU64_REG(BPF_SUB, BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .result = ACCEPT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "check deducing bounds from const, 3",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_JMP_IMM(BPF_JSLE, BPF_REG_0, 0, 0),
|
|
|
+ BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .result = REJECT,
|
|
|
+ .errstr = "R0 tried to subtract pointer from scalar",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "check deducing bounds from const, 4",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_JMP_IMM(BPF_JSLE, BPF_REG_0, 0, 1),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ BPF_JMP_IMM(BPF_JSGE, BPF_REG_0, 0, 1),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ BPF_ALU64_REG(BPF_SUB, BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .result = ACCEPT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "check deducing bounds from const, 5",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_JMP_IMM(BPF_JSGE, BPF_REG_0, 0, 1),
|
|
|
+ BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .result = REJECT,
|
|
|
+ .errstr = "R0 tried to subtract pointer from scalar",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "check deducing bounds from const, 6",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_JMP_IMM(BPF_JSGE, BPF_REG_0, 0, 1),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .result = REJECT,
|
|
|
+ .errstr = "R0 tried to subtract pointer from scalar",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "check deducing bounds from const, 7",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, ~0),
|
|
|
+ BPF_JMP_IMM(BPF_JSGE, BPF_REG_0, 0, 0),
|
|
|
+ BPF_ALU64_REG(BPF_SUB, BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
|
|
|
+ offsetof(struct __sk_buff, mark)),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .result = REJECT,
|
|
|
+ .errstr = "dereference of modified ctx ptr",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "check deducing bounds from const, 8",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, ~0),
|
|
|
+ BPF_JMP_IMM(BPF_JSGE, BPF_REG_0, 0, 1),
|
|
|
+ BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
|
|
|
+ offsetof(struct __sk_buff, mark)),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .result = REJECT,
|
|
|
+ .errstr = "dereference of modified ctx ptr",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "check deducing bounds from const, 9",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_JMP_IMM(BPF_JSGE, BPF_REG_0, 0, 0),
|
|
|
+ BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .result = REJECT,
|
|
|
+ .errstr = "R0 tried to subtract pointer from scalar",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "check deducing bounds from const, 10",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_JMP_IMM(BPF_JSLE, BPF_REG_0, 0, 0),
|
|
|
+ /* Marks reg as unknown. */
|
|
|
+ BPF_ALU64_IMM(BPF_NEG, BPF_REG_0, 0),
|
|
|
+ BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .result = REJECT,
|
|
|
+ .errstr = "math between ctx pointer and register with unbounded min value is not allowed",
|
|
|
+ },
|
|
|
{
|
|
|
"bpf_exit with invalid return code. test1",
|
|
|
.insns = {
|