Skip to content

Commit 9d2be44

Browse files
joestringerborkmann
authored andcommitted
bpf: Reuse canonical string formatter for ctx errs
The array "reg_type_str" provides canonical formatting of register types, however a couple of places would previously check whether a register represented the context and write the name "context" directly. An upcoming commit will add another pointer type to these statements, so to provide more accurate error messages in the verifier, update these error messages to use "reg_type_str" instead. Signed-off-by: Joe Stringer <joe@wand.net.nz> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent aad2eea commit 9d2be44

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

kernel/bpf/verifier.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,8 +1763,7 @@ static int check_xadd(struct bpf_verifier_env *env, int insn_idx, struct bpf_ins
17631763
if (is_ctx_reg(env, insn->dst_reg) ||
17641764
is_pkt_reg(env, insn->dst_reg)) {
17651765
verbose(env, "BPF_XADD stores into R%d %s is not allowed\n",
1766-
insn->dst_reg, is_ctx_reg(env, insn->dst_reg) ?
1767-
"context" : "packet");
1766+
insn->dst_reg, reg_type_str[insn->dst_reg]);
17681767
return -EACCES;
17691768
}
17701769

@@ -4871,8 +4870,8 @@ static int do_check(struct bpf_verifier_env *env)
48714870
return err;
48724871

48734872
if (is_ctx_reg(env, insn->dst_reg)) {
4874-
verbose(env, "BPF_ST stores into R%d context is not allowed\n",
4875-
insn->dst_reg);
4873+
verbose(env, "BPF_ST stores into R%d %s is not allowed\n",
4874+
insn->dst_reg, reg_type_str[insn->dst_reg]);
48764875
return -EACCES;
48774876
}
48784877

tools/testing/selftests/bpf/test_verifier.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,7 +3276,7 @@ static struct bpf_test tests[] = {
32763276
BPF_ST_MEM(BPF_DW, BPF_REG_1, offsetof(struct __sk_buff, mark), 0),
32773277
BPF_EXIT_INSN(),
32783278
},
3279-
.errstr = "BPF_ST stores into R1 context is not allowed",
3279+
.errstr = "BPF_ST stores into R1 inv is not allowed",
32803280
.result = REJECT,
32813281
.prog_type = BPF_PROG_TYPE_SCHED_CLS,
32823282
},
@@ -3288,7 +3288,7 @@ static struct bpf_test tests[] = {
32883288
BPF_REG_0, offsetof(struct __sk_buff, mark), 0),
32893289
BPF_EXIT_INSN(),
32903290
},
3291-
.errstr = "BPF_XADD stores into R1 context is not allowed",
3291+
.errstr = "BPF_XADD stores into R1 inv is not allowed",
32923292
.result = REJECT,
32933293
.prog_type = BPF_PROG_TYPE_SCHED_CLS,
32943294
},
@@ -5266,7 +5266,7 @@ static struct bpf_test tests[] = {
52665266
.errstr_unpriv = "R2 leaks addr into mem",
52675267
.result_unpriv = REJECT,
52685268
.result = REJECT,
5269-
.errstr = "BPF_XADD stores into R1 context is not allowed",
5269+
.errstr = "BPF_XADD stores into R1 inv is not allowed",
52705270
},
52715271
{
52725272
"leak pointer into ctx 2",
@@ -5281,7 +5281,7 @@ static struct bpf_test tests[] = {
52815281
.errstr_unpriv = "R10 leaks addr into mem",
52825282
.result_unpriv = REJECT,
52835283
.result = REJECT,
5284-
.errstr = "BPF_XADD stores into R1 context is not allowed",
5284+
.errstr = "BPF_XADD stores into R1 inv is not allowed",
52855285
},
52865286
{
52875287
"leak pointer into ctx 3",
@@ -12230,7 +12230,7 @@ static struct bpf_test tests[] = {
1223012230
BPF_EXIT_INSN(),
1223112231
},
1223212232
.result = REJECT,
12233-
.errstr = "BPF_XADD stores into R2 packet",
12233+
.errstr = "BPF_XADD stores into R2 ctx",
1223412234
.prog_type = BPF_PROG_TYPE_XDP,
1223512235
},
1223612236
{

0 commit comments

Comments
 (0)