History

bpf: fix integer overflows

There were various issues related to the limited size of integers used in the verifier: - `off + size` overflow in __check_map_access() - `off + reg->off` overflow in check_mem_access() - `off + reg->var_off.value` overflow or 32-bit truncation of `reg->var_off.value` in check_mem_access() - 32-bit truncation in check_stack_boundary() Make sure that any integer math cannot overflow by not allowing pointer math with large values. Also reduce the scope of "scalar op scalar" tracking.

Alexei Starovoitov committed 8 years ago

Commit bb7f0f91 parent 179d1c52 files · +50 −2Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/bpf_verifier.h+2−2
@@ -15,11 +15,11 @@ · 14 unmodified lines
1515 * In practice this is far bigger than any realistic pointer offset; this limit
1616 * ensures that umax_value + (int)off + (int)size cannot overflow a u64.
1717 */
18−#define BPF_MAX_VAR_OFF (1ULL << 31)
18+#define BPF_MAX_VAR_OFF (1 << 29)
1919 /* Maximum variable size permitted for ARG_CONST_SIZE[_OR_ZERO]. This ensures
2020 * that converting umax_value to int cannot overflow.
2121 */
22−#define BPF_MAX_VAR_SIZ INT_MAX
22+#define BPF_MAX_VAR_SIZ (1 << 29)
2323
2424 /* Liveness marks, used for registers and spilled-regs (in stack slots).
2525 * Read marks propagate upwards until they find a write mark; they record that