LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH] libbpf:fix use empty function pointers in ringbuf_poll
@ 2023-06-05  3:34 Xin Liu
  2023-06-05 17:26 ` Stanislav Fomichev
  0 siblings, 1 reply; 8+ messages in thread
From: Xin Liu @ 2023-06-05  3:34 UTC (permalink / raw)
  To: daniel
  Cc: andrii, ast, bpf, davem, edumazet, hsinweih, jakub,
	john.fastabend, kuba, linux-kernel, liuxin350, netdev, pabeni,
	syzbot+49f6cef45247ff249498, syzkaller-bugs, yanan, wuchangye,
	xiesongyang, kongweibin2, zhangmingyi5

From: zhangmingyi <zhangmingyi5@huawei.com>

The sample_cb of the ring_buffer__new interface can transfer NULL. However,
the system does not check whether sample_cb is NULL during 
ring_buffer__poll, null pointer is used.

Signed-off-by: zhangmingyi <zhangmingyi5@huawei.com>
---
 tools/lib/bpf/ringbuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c
index 02199364db13..3661338a1d2e 100644
--- a/tools/lib/bpf/ringbuf.c
+++ b/tools/lib/bpf/ringbuf.c
@@ -248,7 +248,7 @@ static int64_t ringbuf_process_ring(struct ring *r)
 			got_new_data = true;
 			cons_pos += roundup_len(len);
 
-			if ((len & BPF_RINGBUF_DISCARD_BIT) == 0) {
+			if (r->sample_cb && ((len & BPF_RINGBUF_DISCARD_BIT) == 0)) {
 				sample = (void *)len_ptr + BPF_RINGBUF_HDR_SZ;
 				err = r->sample_cb(r->ctx, sample, len);
 				if (err < 0) {
-- 
2.33.0


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

end of thread, other threads:[~2023-06-09 18:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-05  3:34 [PATCH] libbpf:fix use empty function pointers in ringbuf_poll Xin Liu
2023-06-05 17:26 ` Stanislav Fomichev
2023-06-08 12:58   ` zhangmingyi
2023-06-08 16:27     ` Stanislav Fomichev
2023-06-08 17:38       ` Andrii Nakryiko
2023-06-09  9:36         ` zhangmingyi
2023-06-09 16:55           ` Stanislav Fomichev
2023-06-09 18:23             ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).