All of lore.kernel.org
 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

* Re: [PATCH net-next] ptr_ring: fix integer overflow
  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-29 17:01 ` David Miller
  1 sibling, 1 reply; 8+ messages in thread
From: Michael S. Tsirkin @ 2018-01-25 13:45 UTC (permalink / raw)
  To: Jason Wang; +Cc: linux-kernel, netdev, John Fastabend

On Thu, Jan 25, 2018 at 03:31:42PM +0800, Jason Wang wrote:
> 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>

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?

> ---
>  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	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next] ptr_ring: fix integer overflow
  2018-01-25 13:45 ` Michael S. Tsirkin
@ 2018-01-25 14:17   ` Jason Wang
  2018-01-25 17:31     ` Michael S. Tsirkin
  0 siblings, 1 reply; 8+ messages in thread
From: Jason Wang @ 2018-01-25 14:17 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: linux-kernel, netdev, John Fastabend



On 2018年01月25日 21:45, Michael S. Tsirkin wrote:
> On Thu, Jan 25, 2018 at 03:31:42PM +0800, Jason Wang wrote:
>> 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>
> 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

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

* Re: [PATCH net-next] ptr_ring: fix integer overflow
  2018-01-25 14:17   ` Jason Wang
@ 2018-01-25 17:31     ` Michael S. Tsirkin
  2018-01-26  3:44       ` Jason Wang
  0 siblings, 1 reply; 8+ messages in thread
From: Michael S. Tsirkin @ 2018-01-25 17:31 UTC (permalink / raw)
  To: Jason Wang; +Cc: linux-kernel, netdev, John Fastabend

On Thu, Jan 25, 2018 at 10:17:38PM +0800, Jason Wang wrote:
> 
> 
> On 2018年01月25日 21:45, Michael S. Tsirkin wrote:
> > On Thu, Jan 25, 2018 at 03:31:42PM +0800, Jason Wang wrote:
> > > 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>
> > 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

Right. BTW why net-next? Isn't the crash exploitable in net?

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

* Re: [PATCH net-next] ptr_ring: fix integer overflow
  2018-01-25 17:31     ` Michael S. Tsirkin
@ 2018-01-26  3:44       ` Jason Wang
  2018-01-26 13:51         ` Michael S. Tsirkin
  0 siblings, 1 reply; 8+ messages in thread
From: Jason Wang @ 2018-01-26  3:44 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: linux-kernel, netdev, John Fastabend



On 2018年01月26日 01:31, Michael S. Tsirkin wrote:
> On Thu, Jan 25, 2018 at 10:17:38PM +0800, Jason Wang wrote:
>>
>> On 2018年01月25日 21:45, Michael S. Tsirkin wrote:
>>> On Thu, Jan 25, 2018 at 03:31:42PM +0800, Jason Wang wrote:
>>>> 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>
>>> 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
> 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

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

* Re: [PATCH net-next] ptr_ring: fix integer overflow
  2018-01-26  3:44       ` Jason Wang
@ 2018-01-26 13:51         ` Michael S. Tsirkin
  0 siblings, 0 replies; 8+ messages in thread
From: Michael S. Tsirkin @ 2018-01-26 13:51 UTC (permalink / raw)
  To: Jason Wang; +Cc: linux-kernel, netdev, John Fastabend

On Fri, Jan 26, 2018 at 11:44:22AM +0800, Jason Wang wrote:
> 
> 
> On 2018年01月26日 01:31, Michael S. Tsirkin wrote:
> > On Thu, Jan 25, 2018 at 10:17:38PM +0800, Jason Wang wrote:
> > > 
> > > On 2018年01月25日 21:45, Michael S. Tsirkin wrote:
> > > > On Thu, Jan 25, 2018 at 03:31:42PM +0800, Jason Wang wrote:
> > > > > 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>
> > > > 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
> > Right. BTW why net-next? Isn't the crash exploitable in net?
> > 
> 
> Commit bcecb4bbf88a exists only in net-next.

Right you are.

> 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?

-- 
MST

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

* Re: [PATCH net-next] ptr_ring: fix integer overflow
  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-29 17:01 ` David Miller
  2018-01-30  6:56   ` Jason Wang
  1 sibling, 1 reply; 8+ messages in thread
From: David Miller @ 2018-01-29 17:01 UTC (permalink / raw)
  To: jasowang; +Cc: mst, linux-kernel, netdev, john.fastabend

From: Jason Wang <jasowang@redhat.com>
Date: Thu, 25 Jan 2018 15:31:42 +0800

> 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>

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.

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

* Re: [PATCH net-next] ptr_ring: fix integer overflow
  2018-01-29 17:01 ` David Miller
@ 2018-01-30  6:56   ` Jason Wang
  0 siblings, 0 replies; 8+ messages in thread
From: Jason Wang @ 2018-01-30  6:56 UTC (permalink / raw)
  To: David Miller; +Cc: mst, linux-kernel, netdev, john.fastabend



On 2018年01月30日 01:01, David Miller wrote:
> From: Jason Wang <jasowang@redhat.com>
> Date: Thu, 25 Jan 2018 15:31:42 +0800
>
>> 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>
> I'm dropping this because I am to understand that Michael Tsirkin's patch
> series covers this issue.

Yes.

>
> Let me know if I still need to apply this.
>
> Thanks.

No need for this.

Thanks

^ permalink raw reply	[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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.