From: Joanne Koong Date: Fri, 22 Jul 2022 22:01:05 +0000 (-0700) Subject: bpf: Fix bpf_xdp_pointer return pointer X-Git-Tag: v5.18.18~594 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d249081b51b930f2e35ba8a53ea4793a81fc7b84;p=thirdparty%2Fkernel%2Fstable.git bpf: Fix bpf_xdp_pointer return pointer [ Upstream commit bbd52178e249fe893ef4a9b87cde5b6c473b0a7c ] For the case where offset + len == size, bpf_xdp_pointer should return a valid pointer to the addr because that access is permitted. We should only return NULL in the case where offset + len exceeds size. Fixes: 3f364222d032 ("net: xdp: introduce bpf_xdp_pointer utility routine") Signed-off-by: Joanne Koong Signed-off-by: Daniel Borkmann Acked-by: Martin KaFai Lau Acked-by: Lorenzo Bianconi Link: https://lore.kernel.org/bpf/20220722220105.2065466-1-joannelkoong@gmail.com Signed-off-by: Sasha Levin --- diff --git a/net/core/filter.c b/net/core/filter.c index 5db4fae23925f..a98f34cb5aee7 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -3917,7 +3917,7 @@ static void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len) offset -= frag_size; } out: - return offset + len < size ? addr + offset : NULL; + return offset + len <= size ? addr + offset : NULL; } BPF_CALL_4(bpf_xdp_load_bytes, struct xdp_buff *, xdp, u32, offset,