On Sat, Aug 24, 2024 at 12:20:30AM GMT, Daniel Borkmann wrote: > Lonial found an issue that despite user- and BPF-side frozen BPF map > (like in case of .rodata), it was still possible to write into it from > a BPF program side through specific helpers having ARG_PTR_TO_{LONG,INT} > as arguments. > > In check_func_arg() when the argument is as mentioned, the meta->raw_mode > is never set. Later, check_helper_mem_access(), under the case of > PTR_TO_MAP_VALUE as register base type, it assumes BPF_READ for the > subsequent call to check_map_access_type() and given the BPF map is > read-only it succeeds. > > The helpers really need to be annotated as ARG_PTR_TO_{LONG,INT} | MEM_UNINIT > when results are written into them as opposed to read out of them. The > latter indicates that it's okay to pass a pointer to uninitialized memory > as the memory is written to anyway. > > Fixes: 57c3bb725a3d ("bpf: Introduce ARG_PTR_TO_{INT,LONG} arg types") > Reported-by: Lonial Con <kongln9170@xxxxxxxxx> > Signed-off-by: Daniel Borkmann <daniel@xxxxxxxxxxxxx> [...] check_raw_mode_ok() might need an update as well since it currently does not take ARG_PTR_TO_{LONG,INT} | MEM_UNINIT into account. Aside from that LGTM (for this patch). Acked-by: Shung-Hsi Yu <shung-hsi.yu@xxxxxxxx> As a future refactoring it seems like we'd be better off turning ARG_PTR_TO_{LONG,INT} into the more generalized ARG_PTR_TO_FIXED_SIZE_MEM?