Skip to content

Commit b35d12b

Browse files
fmaurer-rhgregkh
authored andcommitted
bpf: Do not try bpf_msg_push_data with len 0
commit 4a11678 upstream. If bpf_msg_push_data() is called with len 0 (as it happens during selftests/bpf/test_sockmap), we do not need to do anything and can return early. Calling bpf_msg_push_data() with len 0 previously lead to a wrong ENOMEM error: we later called get_order(copy + len); if len was 0, copy + len was also often 0 and get_order() returned some undefined value (at the moment 52). alloc_pages() caught that and failed, but then bpf_msg_push_data() returned ENOMEM. This was wrong because we are most probably not out of memory and actually do not need any additional memory. Fixes: 6fff607 ("bpf: sk_msg program helper bpf_msg_push_data") Signed-off-by: Felix Maurer <fmaurer@redhat.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Yonghong Song <yhs@fb.com> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/bpf/df69012695c7094ccb1943ca02b4920db3537466.1644421921.git.fmaurer@redhat.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent eca9bd2 commit b35d12b

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎net/core/filter.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,6 +2711,9 @@ BPF_CALL_4(bpf_msg_push_data, struct sk_msg *, msg, u32, start,
27112711
if (unlikely(flags))
27122712
return -EINVAL;
27132713

2714+
if (unlikely(len == 0))
2715+
return 0;
2716+
27142717
/* First find the starting scatterlist element */
27152718
i = msg->sg.start;
27162719
do {

0 commit comments

Comments
 (0)