netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] ptr_ring: fix integer overflow
@ 2018-01-25  7:31 Jason Wang
  2018-01-25 13:45 ` Michael S. Tsirkin
  2018-01-29 17:01 ` David Miller
  0 siblings, 2 replies; 8+ messages in thread
From: Jason Wang @ 2018-01-25  7:31 UTC (permalink / raw)
  To: mst, linux-kernel, netdev; +Cc: Jason Wang, John Fastabend

We try to allocate one more entry for lockless peeking. The adding
operation may overflow which causes zero to be passed to kmalloc().
In this case, it returns ZERO_SIZE_PTR without any notice by ptr
ring. Try to do producing or consuming on such ring will lead NULL
dereference. Fix this detect and fail early.

Fixes: bcecb4bbf88a ("net: ptr_ring: otherwise safe empty checks can overrun array bounds")
Reported-by: syzbot+87678bcf753b44c39b67@syzkaller.appspotmail.com
Cc: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 include/linux/ptr_ring.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/ptr_ring.h b/include/linux/ptr_ring.h
index 9ca1726..3f99484 100644
--- a/include/linux/ptr_ring.h
+++ b/include/linux/ptr_ring.h
@@ -453,6 +453,8 @@ static inline int ptr_ring_consume_batched_bh(struct ptr_ring *r,
 
 static inline void **__ptr_ring_init_queue_alloc(unsigned int size, gfp_t gfp)
 {
+	if (unlikely(size + 1 == 0))
+		return NULL;
 	/* Allocate an extra dummy element at end of ring to avoid consumer head
 	 * or produce head access past the end of the array. Possible when
 	 * producer/consumer operations and __ptr_ring_peek operations run in
-- 
2.7.4

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

end of thread, other threads:[~2018-01-30  6:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-25  7:31 [PATCH net-next] ptr_ring: fix integer overflow Jason Wang
2018-01-25 13:45 ` Michael S. Tsirkin
2018-01-25 14:17   ` Jason Wang
2018-01-25 17:31     ` Michael S. Tsirkin
2018-01-26  3:44       ` Jason Wang
2018-01-26 13:51         ` Michael S. Tsirkin
2018-01-29 17:01 ` David Miller
2018-01-30  6:56   ` Jason Wang

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 NNTP newsgroup(s).