From: Alexei Starovoitov const_reg_xfer() calls bpf_map_direct_read() before the main pass checks the alignment of the load. So the offset is not always a multiple of the size. Fixes: f1606dd0ac49 ("bpf: Add bpf_compute_const_regs() and bpf_prune_dead_branches() passes") Signed-off-by: Alexei Starovoitov --- kernel/bpf/verifier.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 219173a46110..13c53df386bc 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -6379,13 +6380,13 @@ int bpf_map_direct_read(struct bpf_map *map, int off, int size, u64 *val, *val = is_ldsx ? (s64)*(s8 *)ptr : (u64)*(u8 *)ptr; break; case sizeof(u16): - *val = is_ldsx ? (s64)*(s16 *)ptr : (u64)*(u16 *)ptr; + *val = is_ldsx ? (s64)get_unaligned((s16 *)ptr) : (u64)get_unaligned((u16 *)ptr); break; case sizeof(u32): - *val = is_ldsx ? (s64)*(s32 *)ptr : (u64)*(u32 *)ptr; + *val = is_ldsx ? (s64)get_unaligned((s32 *)ptr) : (u64)get_unaligned((u32 *)ptr); break; case sizeof(u64): - *val = *(u64 *)ptr; + *val = get_unaligned((u64 *)ptr); break; default: return -EINVAL; -- 2.55.0