Commit e688c3d
bpf: Fix register equivalence tracking.
The 64-bit JEQ/JNE handling in reg_set_min_max() was clearing reg->id in either
true or false branch. In the case 'if (reg->id)' check was done on the other
branch the counter part register would have reg->id == 0 when called into
find_equal_scalars(). In such case the helper would incorrectly identify other
registers with id == 0 as equivalent and propagate the state incorrectly.
Fix it by preserving ID across reg_set_min_max().
In other words any kind of comparison operator on the scalar register
should preserve its ID to recognize:
r1 = r2
if (r1 == 20) {
#1 here both r1 and r2 == 20
} else if (r2 < 20) {
#2 here both r1 and r2 < 20
}
The patch is addressing #1 case. The #2 was working correctly already.
Fixes: 7574883 ("bpf: Propagate scalar ranges through register assignments.")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Tested-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20201014175608.1416-1-alexei.starovoitov@gmail.com1 parent ccdf7fa commit e688c3d
File tree
2 files changed
+51
-13
lines changed- kernel/bpf
- tools/testing/selftests/bpf/verifier
2 files changed
+51
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1010 | 1010 | | |
1011 | 1011 | | |
1012 | 1012 | | |
1013 | | - | |
1014 | | - | |
1015 | | - | |
1016 | | - | |
| 1013 | + | |
| 1014 | + | |
1017 | 1015 | | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
1021 | 1016 | | |
1022 | 1017 | | |
1023 | 1018 | | |
| |||
1030 | 1025 | | |
1031 | 1026 | | |
1032 | 1027 | | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
1033 | 1039 | | |
1034 | 1040 | | |
1035 | 1041 | | |
| |||
7001 | 7007 | | |
7002 | 7008 | | |
7003 | 7009 | | |
7004 | | - | |
7005 | | - | |
7006 | | - | |
| 7010 | + | |
| 7011 | + | |
| 7012 | + | |
| 7013 | + | |
| 7014 | + | |
| 7015 | + | |
| 7016 | + | |
7007 | 7017 | | |
7008 | 7018 | | |
7009 | 7019 | | |
7010 | 7020 | | |
7011 | | - | |
| 7021 | + | |
7012 | 7022 | | |
7013 | 7023 | | |
7014 | 7024 | | |
| |||
7551 | 7561 | | |
7552 | 7562 | | |
7553 | 7563 | | |
7554 | | - | |
| 7564 | + | |
| 7565 | + | |
7555 | 7566 | | |
7556 | 7567 | | |
7557 | 7568 | | |
| |||
7563 | 7574 | | |
7564 | 7575 | | |
7565 | 7576 | | |
7566 | | - | |
| 7577 | + | |
| 7578 | + | |
7567 | 7579 | | |
7568 | 7580 | | |
7569 | 7581 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
0 commit comments