BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v2] bpf: Do not try bpf_msg_push_data with len 0
@ 2022-02-09 15:55 Felix Maurer
  2022-02-09 17:06 ` Yonghong Song
  2022-02-11 13:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 9+ messages in thread
From: Felix Maurer @ 2022-02-09 15:55 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend,
	kpsingh

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.

v2: Add bug description and Fixes tag

Fixes: 6fff607e2f14b ("bpf: sk_msg program helper bpf_msg_push_data")
Signed-off-by: Felix Maurer <fmaurer@redhat.com>
---
 net/core/filter.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/core/filter.c b/net/core/filter.c
index 4603b7cd3cd1..9eb785842258 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2710,6 +2710,9 @@ BPF_CALL_4(bpf_msg_push_data, struct sk_msg *, msg, u32, start,
 	if (unlikely(flags))
 		return -EINVAL;
 
+	if (unlikely(len == 0))
+		return 0;
+
 	/* First find the starting scatterlist element */
 	i = msg->sg.start;
 	do {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-02-11 22:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-09 15:55 [PATCH bpf-next v2] bpf: Do not try bpf_msg_push_data with len 0 Felix Maurer
2022-02-09 17:06 ` Yonghong Song
2022-02-10 15:45   ` Felix Maurer
2022-02-10 18:04     ` Yonghong Song
2022-02-11  3:08       ` Alexei Starovoitov
2022-02-11  6:33         ` John Fastabend
2022-02-11 17:52       ` Felix Maurer
2022-02-11 22:27         ` Yonghong Song
2022-02-11 13:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox