bpf: fix sanitation rewrite in case of non-pointers
Subsystems (4)
Daniel Borkmann
maintainerPATCH 1/1 bpf: fix sanitation rewrite in case of non-pointers
Marek reported that he saw an issue with the below snippet in that timing measurements where off when loaded as unpriv while results were reasonable when loaded as privileged:
[...]
uint64_t a = bpf_ktime_get_ns();
uint64_t b = bpf_ktime_get_ns();
uint64_t delta = b - a;
if ((int64_t)delta > 0) {
[...]Turns out there is a bug where a corner case is missing in the fix d3bd7413e0ca ("bpf: fix sanitation of alu op with pointer / scalar type from different paths"), namely fixup_bpf_calls() only checks whether aux has a non-zero alu_state, but it also needs to test for the case of BPF_ALU_NON_POINTER since in both occasions we need to skip the masking rewrite (as there is nothing to mask).
---
[ Test case will be routed via bpf-next to avoid useless merge churn
due to test_verifier rework in bpf-next. ]
kernel/bpf/verifier.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +2 -1
@@ -6920,7 +6920,8 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)u32 off_reg; aux = &env->insn_aux_data[i + delta]; -if (!aux->alu_state) +if (!aux->alu_state || + aux->alu_state ==BPF_ALU_NON_POINTER )continue ; isneg = aux->alu_state &BPF_ALU_NEG_VALUE ;
Signature · 1 line
2.17.1
Quoted 36 lines · Daniel Borkmann
Marek reported that he saw an issue with the below snippet in that timing measurements where off when loaded as unpriv while results were reasonable when loaded as privileged:
[...] uint64_t a = bpf_ktime_get_ns(); uint64_t b = bpf_ktime_get_ns(); uint64_t delta = b - a; if ((int64_t)delta > 0) { [...]Turns out there is a bug where a corner case is missing in the fix
d3bd7413e0ca("bpf: fix sanitation of alu op with pointer / scalar type from different paths"), namelyfixup_bpf_calls()only checks whether aux has a non-zeroalu_state, but it also needs to test for the case ofBPF_ALU_NON_POINTERsince in both occasions we need to skip the masking rewrite (as there is nothing to mask).Fixes d3bd7413e0ca ("bpf: fix sanitation of alu op with pointer / scalar type from different paths")Reported-by Marek Majkowski <[email protected]>Reported-by Arthur Fabre <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>---
[ Test case will be routed via bpf-next to avoid useless merge churn
due totest_verifierrework in bpf-next. ]kernel/bpf/verifier.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/bpf/verifier.c +0
-0
kernel/bpf/verifier.c static int fixup_bpf_calls(struct bpf_verifier_env *env) · line 6924
Quoted 6 lines
kernel/bpf/verifier.c +2
-1@@ -6920,7 +6920,8 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)u32 off_reg; aux = &env->insn_aux_data[i + delta]; -if (!aux->alu_state) +if (!aux->alu_state || + aux->alu_state ==BPF_ALU_NON_POINTER )
alu_state is a bitmap. Shall we check "aux->alu_state & BPF_ALU_NON_POINTER" here?
Thanks,
Song
Quoted 6 lines
kernel/bpf/verifier.c +0
-1continue ; isneg = aux->alu_state &BPF_ALU_NEG_VALUE ; --2.17.1
Daniel Borkmann
maintainerQuoted 39 lines · Song Liu
Quoted 38 lines · Daniel Borkmann
Marek reported that he saw an issue with the below snippet in that timing measurements where off when loaded as unpriv while results were reasonable when loaded as privileged:
[...] uint64_t a = bpf_ktime_get_ns(); uint64_t b = bpf_ktime_get_ns(); uint64_t delta = b - a; if ((int64_t)delta > 0) { [...]Turns out there is a bug where a corner case is missing in the fix
d3bd7413e0ca("bpf: fix sanitation of alu op with pointer / scalar type from different paths"), namelyfixup_bpf_calls()only checks whether aux has a non-zeroalu_state, but it also needs to test for the case ofBPF_ALU_NON_POINTERsince in both occasions we need to skip the masking rewrite (as there is nothing to mask).Fixes d3bd7413e0ca ("bpf: fix sanitation of alu op with pointer / scalar type from different paths")Reported-by Marek Majkowski <[email protected]>Reported-by Arthur Fabre <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>---
[ Test case will be routed via bpf-next to avoid useless merge churn
due totest_verifierrework in bpf-next. ]kernel/bpf/verifier.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/bpf/verifier.c +0
-0@@ -6920,7 +6920,8 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)u32 off_reg;
Quoted 7 lines
kernel/bpf/verifier.c static int fixup_bpf_calls(struct bpf_verifier_env *env) · line 6924
Quoted 4 lines
kernel/bpf/verifier.c +2
-1aux = &env->insn_aux_data[i + delta]; -if (!aux->alu_state) +if (!aux->alu_state || + aux->alu_state ==BPF_ALU_NON_POINTER )
alu_stateis a bitmap. Shall we check "aux->alu_state&BPF_ALU_NON_POINTER" here?
The state in this case can only ever be BPF_ALU_NON_POINTER, any other setting from sanitize_val_alu() would be a violation.
Song Liu
Acked-byQuoted 49 lines · Daniel Borkmann
Quoted 39 lines · Song Liu
Quoted 38 lines · Daniel Borkmann
Marek reported that he saw an issue with the below snippet in that timing measurements where off when loaded as unpriv while results were reasonable when loaded as privileged:
[...] uint64_t a = bpf_ktime_get_ns(); uint64_t b = bpf_ktime_get_ns(); uint64_t delta = b - a; if ((int64_t)delta > 0) { [...]Turns out there is a bug where a corner case is missing in the fix
d3bd7413e0ca("bpf: fix sanitation of alu op with pointer / scalar type from different paths"), namelyfixup_bpf_calls()only checks whether aux has a non-zeroalu_state, but it also needs to test for the case ofBPF_ALU_NON_POINTERsince in both occasions we need to skip the masking rewrite (as there is nothing to mask).Fixes d3bd7413e0ca ("bpf: fix sanitation of alu op with pointer / scalar type from different paths")Reported-by Marek Majkowski <[email protected]>Reported-by Arthur Fabre <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>---
[ Test case will be routed via bpf-next to avoid useless merge churn
due totest_verifierrework in bpf-next. ]kernel/bpf/verifier.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/bpf/verifier.c +0
-0@@ -6920,7 +6920,8 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)u32 off_reg;Quoted 7 lines
kernel/bpf/verifier.c static int fixup_bpf_calls(struct bpf_verifier_env *env) · line 6924
Quoted 4 lines
kernel/bpf/verifier.c +2
-1aux = &env->insn_aux_data[i + delta]; -if (!aux->alu_state) +if (!aux->alu_state || + aux->alu_state ==BPF_ALU_NON_POINTER )
alu_stateis a bitmap. Shall we check "aux->alu_state&BPF_ALU_NON_POINTER" here?
Quoted 2 lines
The state in this case can only ever be
BPF_ALU_NON_POINTER, any other setting fromsanitize_val_alu()would be a violation.
I see. Thanks for the explanation.
Alexei Starovoitov
AppliedQuoted 18 lines · Daniel Borkmann
Marek reported that he saw an issue with the below snippet in that timing measurements where off when loaded as unpriv while results were reasonable when loaded as privileged:
[...] uint64_t a = bpf_ktime_get_ns(); uint64_t b = bpf_ktime_get_ns(); uint64_t delta = b - a; if ((int64_t)delta > 0) { [...]Turns out there is a bug where a corner case is missing in the fix
d3bd7413e0ca("bpf: fix sanitation of alu op with pointer / scalar type from different paths"), namelyfixup_bpf_calls()only checks whether aux has a non-zeroalu_state, but it also needs to test for the case ofBPF_ALU_NON_POINTERsince in both occasions we need to skip the masking rewrite (as there is nothing to mask).
Quoted 5 lines
Fixes d3bd7413e0ca ("bpf: fix sanitation of alu op with pointer / scalar type from different paths")Reported-by Marek Majkowski <[email protected]>Reported-by Arthur Fabre <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>
Applied, Thanks
Hello!
Quoted 2 lines · Daniel Borkmann
Marek reported that he saw an issue with the below snippet in that timing measurements where off when loaded as unpriv while results
Were?
Quoted 16 lines
were reasonable when loaded as privileged:
[...] uint64_t a = bpf_ktime_get_ns(); uint64_t b = bpf_ktime_get_ns(); uint64_t delta = b - a; if ((int64_t)delta > 0) { [...]Turns out there is a bug where a corner case is missing in the fix
d3bd7413e0ca("bpf: fix sanitation of alu op with pointer / scalar type from different paths"), namelyfixup_bpf_calls()only checks whether aux has a non-zeroalu_state, but it also needs to test for the case ofBPF_ALU_NON_POINTERsince in both occasions we need to skip the masking rewrite (as there is nothing to mask).
Quoted 5 lines
Fixes d3bd7413e0ca ("bpf: fix sanitation of alu op with pointer / scalar type from different paths")Reported-by Marek Majkowski <[email protected]>Reported-by Arthur Fabre <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>
[...]
MBR, Sergei
Quoted 18 lines · Daniel Borkmann
Marek reported that he saw an issue with the below snippet in that timing measurements where off when loaded as unpriv while results were reasonable when loaded as privileged:
[...] uint64_t a = bpf_ktime_get_ns(); uint64_t b = bpf_ktime_get_ns(); uint64_t delta = b - a; if ((int64_t)delta > 0) { [...]Turns out there is a bug where a corner case is missing in the fix
d3bd7413e0ca("bpf: fix sanitation of alu op with pointer / scalar type from different paths"), namelyfixup_bpf_calls()only checks whether aux has a non-zeroalu_state, but it also needs to test for the case ofBPF_ALU_NON_POINTERsince in both occasions we need to skip the masking rewrite (as there is nothing to mask).
Quoted 6 lines
Fixes d3bd7413e0ca ("bpf: fix sanitation of alu op with pointer / scalar type from different paths")Reported-by Marek Majkowski <[email protected]>Reported-by Arthur Fabre <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>---
Could you please queue it for -stable which has d3bd7413e0ca ("bpf: fix sanitation of alu op with pointer / scalar type from different paths")?
Thanks,
Jakub
Daniel Borkmann
maintainerOn 03/05/2019 03:12 PM, Jakub Sitnicki wrote:
[...]
Quoted 2 lines
Could you please queue it for -stable which has
d3bd7413e0ca("bpf: fix sanitation of alu op with pointer / scalar type from different paths")?
Already done here yesterday morning:
Quoted 3 lines
Thanks,
Jakub
Quoted 8 lines · Daniel Borkmann
On 03/05/2019 03:12 PM, Jakub Sitnicki wrote:
[...]Quoted 2 lines
Could you please queue it for -stable which has
d3bd7413e0ca("bpf: fix sanitation of alu op with pointer / scalar type from different paths")?Already done here yesterday morning:
Ah, you're one step ahead of me. Thank you.