From: Jason Wang <hidden> Date: 2018-02-09 09:45:56
To avoid slab to warn about exceeded size, fail early if queue
occupies more than KMALLOC_MAX_SIZE.
Reported-by: syzbot+e4d4f9ddd4295539735d@syzkaller.appspotmail.com
Fixes: 2e0ab8ca83c12 ("ptr_ring: array based FIFO for pointers")
Signed-off-by: Jason Wang <redacted>
---
include/linux/ptr_ring.h | 2 ++
1 file changed, 2 insertions(+)
From: Jason Wang <hidden> Date: 2018-02-09 09:46:00
This patch switch to use kvmalloc_array() for using a vmalloc()
fallback to help in case kmalloc() fails.
Reported-by: syzbot+e4d4f9ddd4295539735d@syzkaller.appspotmail.com
Fixes: 2e0ab8ca83c12 ("ptr_ring: array based FIFO for pointers")
Signed-off-by: Jason Wang <redacted>
---
include/linux/ptr_ring.h | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
@@ -464,11 +464,14 @@ static inline int ptr_ring_consume_batched_bh(struct ptr_ring *r,__PTR_RING_PEEK_CALL_v;\})+/* Not all gfp_t flags (besides GFP_KERNEL) are allowed. See+*documentationforvmallocforwhichofthemarelegal.+*/staticinlinevoid**__ptr_ring_init_queue_alloc(unsignedintsize,gfp_tgfp){if(size*sizeof(void*)>KMALLOC_MAX_SIZE)returnNULL;-returnkcalloc(size,sizeof(void*),gfp);+returnkvmalloc_array(size,sizeof(void*),gfp|__GFP_ZERO);}staticinlinevoid__ptr_ring_set_size(structptr_ring*r,intsize)
@@ -603,7 +606,7 @@ static inline int ptr_ring_resize(struct ptr_ring *r, int size, gfp_t gfp,spin_unlock(&(r)->producer_lock);spin_unlock_irqrestore(&(r)->consumer_lock,flags);-kfree(old);+kvfree(old);return0;}
@@ -643,7 +646,7 @@ static inline int ptr_ring_resize_multiple(struct ptr_ring **rings,}for(i=0;i<nrings;++i)-kfree(queues[i]);+kvfree(queues[i]);kfree(queues);
@@ -651,7 +654,7 @@ static inline int ptr_ring_resize_multiple(struct ptr_ring **rings,nomem:while(--i>=0)-kfree(queues[i]);+kvfree(queues[i]);kfree(queues);
From: "Michael S. Tsirkin" <mst@redhat.com> Date: 2018-02-09 15:39:13
On Fri, Feb 09, 2018 at 05:45:49PM +0800, Jason Wang wrote:
To avoid slab to warn about exceeded size, fail early if queue
occupies more than KMALLOC_MAX_SIZE.
Reported-by: syzbot+e4d4f9ddd4295539735d@syzkaller.appspotmail.com
Fixes: 2e0ab8ca83c12 ("ptr_ring: array based FIFO for pointers")
Signed-off-by: Jason Wang <redacted>
From: "Michael S. Tsirkin" <mst@redhat.com> Date: 2018-02-09 15:53:53
On Fri, Feb 09, 2018 at 05:45:50PM +0800, Jason Wang wrote:
This patch switch to use kvmalloc_array() for using a vmalloc()
fallback to help in case kmalloc() fails.
Above isn't really saying anything about the motivation, it
just explains what kvmalloc_array does.
How about:
Switch ptr_ring from kmalloc to kvmalloc. This way it can support larger
ring sizes.
Reported-by: syzbot+e4d4f9ddd4295539735d@syzkaller.appspotmail.com
Fixes: 2e0ab8ca83c12 ("ptr_ring: array based FIFO for pointers")
I don't see this as a bugfix - it's more of an enhancement.
Do we need this in net or can we defer this to net-next?
I'm not sure myself. For now
Acked-by: Michael S. Tsirkin <mst@redhat.com>
@@ -464,11 +464,14 @@ static inline int ptr_ring_consume_batched_bh(struct ptr_ring *r,__PTR_RING_PEEK_CALL_v;\})+/* Not all gfp_t flags (besides GFP_KERNEL) are allowed. See+*documentationforvmallocforwhichofthemarelegal.+*/staticinlinevoid**__ptr_ring_init_queue_alloc(unsignedintsize,gfp_tgfp){if(size*sizeof(void*)>KMALLOC_MAX_SIZE)returnNULL;-returnkcalloc(size,sizeof(void*),gfp);+returnkvmalloc_array(size,sizeof(void*),gfp|__GFP_ZERO);}staticinlinevoid__ptr_ring_set_size(structptr_ring*r,intsize)
@@ -603,7 +606,7 @@ static inline int ptr_ring_resize(struct ptr_ring *r, int size, gfp_t gfp,spin_unlock(&(r)->producer_lock);spin_unlock_irqrestore(&(r)->consumer_lock,flags);-kfree(old);+kvfree(old);return0;}
@@ -643,7 +646,7 @@ static inline int ptr_ring_resize_multiple(struct ptr_ring **rings,}for(i=0;i<nrings;++i)-kfree(queues[i]);+kvfree(queues[i]);kfree(queues);
@@ -651,7 +654,7 @@ static inline int ptr_ring_resize_multiple(struct ptr_ring **rings,nomem:while(--i>=0)-kfree(queues[i]);+kvfree(queues[i]);kfree(queues);
From: David Miller <davem@davemloft.net> Date: 2018-02-09 19:29:24
From: Jason Wang <redacted>
Date: Fri, 9 Feb 2018 17:45:49 +0800
To avoid slab to warn about exceeded size, fail early if queue
occupies more than KMALLOC_MAX_SIZE.
Reported-by: syzbot+e4d4f9ddd4295539735d@syzkaller.appspotmail.com
Fixes: 2e0ab8ca83c12 ("ptr_ring: array based FIFO for pointers")
Signed-off-by: Jason Wang <redacted>
From: David Miller <davem@davemloft.net> Date: 2018-02-09 19:29:33
From: Jason Wang <redacted>
Date: Fri, 9 Feb 2018 17:45:50 +0800
This patch switch to use kvmalloc_array() for using a vmalloc()
fallback to help in case kmalloc() fails.
Reported-by: syzbot+e4d4f9ddd4295539735d@syzkaller.appspotmail.com
Fixes: 2e0ab8ca83c12 ("ptr_ring: array based FIFO for pointers")
Signed-off-by: Jason Wang <redacted>
From: Eric Biggers <hidden> Date: 2018-02-10 19:32:07
Hi Jason,
On Fri, Feb 09, 2018 at 05:45:49PM +0800, Jason Wang wrote:
quoted hunk
To avoid slab to warn about exceeded size, fail early if queue
occupies more than KMALLOC_MAX_SIZE.
Reported-by: syzbot+e4d4f9ddd4295539735d@syzkaller.appspotmail.com
Fixes: 2e0ab8ca83c12 ("ptr_ring: array based FIFO for pointers")
Signed-off-by: Jason Wang <redacted>
---
include/linux/ptr_ring.h | 2 ++
1 file changed, 2 insertions(+)
@@ -466,6 +466,8 @@ static inline int ptr_ring_consume_batched_bh(struct ptr_ring *r,staticinlinevoid**__ptr_ring_init_queue_alloc(unsignedintsize,gfp_tgfp){+if(size*sizeof(void*)>KMALLOC_MAX_SIZE)+returnNULL;
Are you sure that size can't be over 0x40000000? The proper way to write this
(safe from integer overflow) would be:
if (size > KMALLOC_MAX_SIZE / sizeof(void *))
return NULL;
- Eric
From: Jason Wang <hidden> Date: 2018-02-11 02:46:01
On 2018年02月09日 23:53, Michael S. Tsirkin wrote:
On Fri, Feb 09, 2018 at 05:45:50PM +0800, Jason Wang wrote:
quoted
This patch switch to use kvmalloc_array() for using a vmalloc()
fallback to help in case kmalloc() fails.
Above isn't really saying anything about the motivation, it
just explains what kvmalloc_array does.
How about:
Switch ptr_ring from kmalloc to kvmalloc. This way it can support larger
ring sizes.
quoted
Reported-by:syzbot+e4d4f9ddd4295539735d@syzkaller.appspotmail.com
Fixes: 2e0ab8ca83c12 ("ptr_ring: array based FIFO for pointers")
I don't see this as a bugfix - it's more of an enhancement.
Do we need this in net or can we defer this to net-next?
Consider they are users of tx_queue_len of more than 1000000 from google
searching. We'd better have this in -net.
Thanks
I'm not sure myself. For now
Acked-by: Michael S. Tsirkin<mst@redhat.com>
From: Jason Wang <hidden> Date: 2018-02-11 02:46:40
On 2018年02月11日 03:32, Eric Biggers wrote:
Hi Jason,
On Fri, Feb 09, 2018 at 05:45:49PM +0800, Jason Wang wrote:
quoted
To avoid slab to warn about exceeded size, fail early if queue
occupies more than KMALLOC_MAX_SIZE.
Reported-by: syzbot+e4d4f9ddd4295539735d@syzkaller.appspotmail.com
Fixes: 2e0ab8ca83c12 ("ptr_ring: array based FIFO for pointers")
Signed-off-by: Jason Wang <redacted>
---
include/linux/ptr_ring.h | 2 ++
1 file changed, 2 insertions(+)
@@ -466,6 +466,8 @@ static inline int ptr_ring_consume_batched_bh(struct ptr_ring *r,staticinlinevoid**__ptr_ring_init_queue_alloc(unsignedintsize,gfp_tgfp){+if(size*sizeof(void*)>KMALLOC_MAX_SIZE)+returnNULL;
Are you sure that size can't be over 0x40000000? The proper way to write this
(safe from integer overflow) would be:
if (size > KMALLOC_MAX_SIZE / sizeof(void *))
return NULL;
- Eric