ptr_ring: fix integer overflow
Subsystems (2)
PATCH 1/1 ptr_ring: fix integer overflow
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.
--- include/linux/ptr_ring.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/ptr_ring.h +2 -0
@@ -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
Signature · 1 line
2.7.4
Quoted 10 lines · Jason Wang
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 returnsZERO_SIZE_PTRwithout 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 [email protected]Cc John Fastabend <[email protected]>Signed-off-by Jason Wang <[email protected]>
Ugh that's just way too ugly.
I'll work on dropping the extra + 1 - but calling this function with -1 size is the real source of the bug. Do you know how come we do that?
Quoted 19 lines
--- include/linux/ptr_ring.h | 2 ++ 1 file changed, 2 insertions(+)include/linux/ptr_ring.h +2
-0@@ -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 Signature · 1 line
2.7.4
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Jason Wang
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 returnsZERO_SIZE_PTRwithout any notice by ptr ring. Try to do producing or consuming on such ring will lead NULL dereference. Fix this detect and fail early.
Quoted 9 lines
Quoted 4 lines
Fixes bcecb4bbf88a ("net: ptr_ring: otherwise safe empty checks can overrun array bounds")Reported-by [email protected]Cc John Fastabend<[email protected]>Signed-off-by Jason Wang<[email protected]>Ugh that's just way too ugly.
I'll work on dropping the extra + 1 - but calling this function with -1 size is the real source of the bug. Do you know how come we do that?
It looks e.g try to change tx_queue_len to UINT_MAX. And we probably can't prevent user form trying to do this?
Thanks
Quoted 20 lines · Jason Wang
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Jason Wang
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 returnsZERO_SIZE_PTRwithout any notice by ptr ring. Try to do producing or consuming on such ring will lead NULL dereference. Fix this detect and fail early.Quoted 9 lines
Quoted 4 lines
Fixes bcecb4bbf88a ("net: ptr_ring: otherwise safe empty checks can overrun array bounds")Reported-by [email protected]Cc John Fastabend<[email protected]>Signed-off-by Jason Wang<[email protected]>Ugh that's just way too ugly.
I'll work on dropping the extra + 1 - but calling this function with -1 size is the real source of the bug. Do you know how come we do that?
Quoted 4 lines
It looks e.g try to change
tx_queue_lentoUINT_MAX. And we probably can't prevent user form trying to do this?Thanks
Right. BTW why net-next? Isn't the crash exploitable in net?
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Jason Wang
Quoted 16 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
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 returnsZERO_SIZE_PTRwithout 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 [email protected]Cc John Fastabend<[email protected]>Signed-off-by Jason Wang<[email protected]>Ugh that's just way too ugly.
I'll work on dropping the extra + 1 - but calling this function with -1 size is the real source of the bug. Do you know how come we do that?
Quoted 6 lines
Quoted 4 lines
It looks e.g try to change
tx_queue_lentoUINT_MAX. And we probably can't prevent user form trying to do this?Thanks
Right. BTW why net-next? Isn't the crash exploitable in net?
Commit bcecb4bbf88a exists only in net-next. And in net we check r->size before trying to dereference the queue.
Thanks
Quoted 22 lines · Jason Wang
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Jason Wang
Quoted 16 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
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 returnsZERO_SIZE_PTRwithout 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 [email protected]Cc John Fastabend<[email protected]>Signed-off-by Jason Wang<[email protected]>Ugh that's just way too ugly.
I'll work on dropping the extra + 1 - but calling this function with -1 size is the real source of the bug. Do you know how come we do that?
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
It looks e.g try to change
tx_queue_lentoUINT_MAX. And we probably can't prevent user form trying to do this?Thanks
Right. BTW why net-next? Isn't the crash exploitable in net?
Commit
bcecb4bbf88aexists only in net-next.
Right you are.
Quoted 4 lines
And in net we check
r->size
before trying to dereference the queue.Thanks
I was wondering what it's about btw. Does anyone really create 0 size rings?
Signature · 1 line
MST
David Miller
maintainerFrom: Jason Wang <[email protected]>
Date: Thu, 25 Jan 2018 15:31:42 +0800
Quoted 10 lines
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 returnsZERO_SIZE_PTRwithout 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 [email protected]Cc John Fastabend <[email protected]>Signed-off-by Jason Wang <[email protected]>
I'm dropping this because I am to understand that Michael Tsirkin's patch series covers this issue.
Let me know if I still need to apply this.
Thanks.
Quoted 9 lines · David Miller
From: Jason Wang <[email protected]>
Date: Thu, 25 Jan 2018 15:31:42 +0800Quoted 6 lines
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 returnsZERO_SIZE_PTRwithout any notice by ptr ring. Try to do producing or consuming on such ring will lead NULL dereference. Fix this detect and fail early.
Quoted 6 lines
Quoted 4 lines
Fixes bcecb4bbf88a ("net: ptr_ring: otherwise safe empty checks can overrun array bounds")Reported-by [email protected]Cc John Fastabend <[email protected]>Signed-off-by Jason Wang <[email protected]>I'm dropping this because I am to understand that Michael Tsirkin's patch series covers this issue.
Yes.
Quoted 4 lines
Let me know if I still need to apply this.
Thanks.
No need for this.
Thanks