From: Jason Wang <hidden> Date: 2018-02-08 03:59:32
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 | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
From: Jason Wang <hidden> Date: 2018-02-08 03:59:34
We need limit the maximum size of queue, otherwise it may cause
several side effects e.g slab will warn when the size exceeds
KMALLOC_MAX_SIZE. Using KMALLOC_MAX_SIZE still looks too so this patch
tries to limit it to 64K. This value could be revisited if we found a
real case that needs more.
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 | 4 ++++
1 file changed, 4 insertions(+)
@@ -44,6 +44,8 @@ struct ptr_ring {void**queue;};+#define PTR_RING_MAX_ALLOC 65536+/* Note: callers invoking this in a loop must use a compiler barrier,*forexamplecpu_relax().*
@@ -466,6 +468,8 @@ static inline int ptr_ring_consume_batched_bh(struct ptr_ring *r,staticinlinevoid**__ptr_ring_init_queue_alloc(unsignedintsize,gfp_tgfp){+if(size>PTR_RING_MAX_ALLOC)+returnNULL;returnkvmalloc_array(size,sizeof(void*),gfp|__GFP_ZERO);}
From: "Michael S. Tsirkin" <mst@redhat.com> Date: 2018-02-08 04:45:52
On Thu, Feb 08, 2018 at 11:59:24AM +0800, Jason Wang wrote:
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")
I guess the actual patch is the one that switches tun to ptr_ring.
In fact, I think the actual bugfix is patch 2/2. This specific one
just makes kmalloc less likely to fail but that's
not what syzbot reported.
Then I would add this patch on top to make kmalloc less likely to fail.
@@ -466,7 +466,7 @@ static inline int ptr_ring_consume_batched_bh(struct ptr_ring *r,staticinlinevoid**__ptr_ring_init_queue_alloc(unsignedintsize,gfp_tgfp){-returnkcalloc(size,sizeof(void*),gfp);+returnkvmalloc_array(size,sizeof(void*),gfp|__GFP_ZERO);}staticinlinevoid__ptr_ring_set_size(structptr_ring*r,intsize)
This implies a bunch of limitations on the flags. From kvmalloc_node
docs:
* Reclaim modifiers - __GFP_NORETRY and __GFP_NOFAIL are not supported.
* __GFP_RETRY_MAYFAIL is supported, and it should be used only if kmalloc is
* preferable to the vmalloc fallback, due to visible performance drawbacks.
Fine with all the current users, but if we go this way, please add
documentation so future users don't misuse this API.
Alternatively, test flags and call kvmalloc or kcalloc?
From: "Michael S. Tsirkin" <mst@redhat.com> Date: 2018-02-08 04:52:40
On Thu, Feb 08, 2018 at 11:59:25AM +0800, Jason Wang wrote:
quoted hunk
We need limit the maximum size of queue, otherwise it may cause
several side effects e.g slab will warn when the size exceeds
KMALLOC_MAX_SIZE. Using KMALLOC_MAX_SIZE still looks too so this patch
tries to limit it to 64K. This value could be revisited if we found a
real case that needs more.
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 | 4 ++++
1 file changed, 4 insertions(+)
Seems like a weird location for a define. Either put defines on
top of the file, or near where they are used. I prefer the
second option.
+#define PTR_RING_MAX_ALLOC 65536
+
I guess it's an arbitrary number. Seems like a sufficiently large one,
but pls add a comment so readers don't wonder. And please explain what
it does:
/* Callers can create ptr_ring structures with userspace-supplied
* parameters. This sets a limit on the size to make that usecase
* safe. If you ever change this, make sure to audit all callers.
*/
Also I think we should generally use either hex 0x10000 or (1 << 16).
quoted hunk
/* Note: callers invoking this in a loop must use a compiler barrier,
* for example cpu_relax().
*
From: Jason Wang <hidden> Date: 2018-02-08 06:58:44
On 2018年02月08日 12:45, Michael S. Tsirkin wrote:
On Thu, Feb 08, 2018 at 11:59:24AM +0800, Jason Wang wrote:
quoted
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")
I guess the actual patch is the one that switches tun to ptr_ring.
I think not, since the issue was large allocation.
In fact, I think the actual bugfix is patch 2/2. This specific one
just makes kmalloc less likely to fail but that's
not what syzbot reported.
Agree.
Then I would add this patch on top to make kmalloc less likely to fail.
@@ -466,7 +466,7 @@ static inline int ptr_ring_consume_batched_bh(struct ptr_ring *r,staticinlinevoid**__ptr_ring_init_queue_alloc(unsignedintsize,gfp_tgfp){-returnkcalloc(size,sizeof(void*),gfp);+returnkvmalloc_array(size,sizeof(void*),gfp|__GFP_ZERO);}staticinlinevoid__ptr_ring_set_size(structptr_ring*r,intsize)
This implies a bunch of limitations on the flags. From kvmalloc_node
docs:
* Reclaim modifiers - __GFP_NORETRY and __GFP_NOFAIL are not supported.
* __GFP_RETRY_MAYFAIL is supported, and it should be used only if kmalloc is
* preferable to the vmalloc fallback, due to visible performance drawbacks.
Fine with all the current users, but if we go this way, please add
documentation so future users don't misuse this API.
I suspect this is somehow a overkill since this means we need sync with
mm/vmalloc changes in the future to keep it synced.
Alternatively, test flags and call kvmalloc or kcalloc?
Similar to the above issue, I would rather leave it as is.
Thanks
From: Jason Wang <hidden> Date: 2018-02-08 07:11:26
On 2018年02月08日 12:52, Michael S. Tsirkin wrote:
On Thu, Feb 08, 2018 at 11:59:25AM +0800, Jason Wang wrote:
quoted
We need limit the maximum size of queue, otherwise it may cause
several side effects e.g slab will warn when the size exceeds
KMALLOC_MAX_SIZE. Using KMALLOC_MAX_SIZE still looks too so this patch
tries to limit it to 64K. This value could be revisited if we found a
real case that needs more.
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 | 4 ++++
1 file changed, 4 insertions(+)
Seems like a weird location for a define. Either put defines on
top of the file, or near where they are used. I prefer the
second option.
Ok.
quoted
+#define PTR_RING_MAX_ALLOC 65536
+
I guess it's an arbitrary number. Seems like a sufficiently large one,
but pls add a comment so readers don't wonder. And please explain what
it does:
/* Callers can create ptr_ring structures with userspace-supplied
* parameters. This sets a limit on the size to make that usecase
* safe. If you ever change this, make sure to audit all callers.
*/
Also I think we should generally use either hex 0x10000 or (1 << 16).
I agree the number is arbitrary, so I still prefer the KMALLOC_MAX_SIZE
especially consider it was used by pfifo_fast now. Try to limit it to an
arbitrary may break lots of exist setups. E.g just google "txqueuelen
100000" can give me a lots of search results.
We can do any kind of optimization on top but not for -net now.
Thanks
quoted
/* Note: callers invoking this in a loop must use a compiler barrier,
* for example cpu_relax().
*
From: "Michael S. Tsirkin" <mst@redhat.com> Date: 2018-02-08 15:50:55
On Thu, Feb 08, 2018 at 03:11:22PM +0800, Jason Wang wrote:
On 2018年02月08日 12:52, Michael S. Tsirkin wrote:
quoted
On Thu, Feb 08, 2018 at 11:59:25AM +0800, Jason Wang wrote:
quoted
We need limit the maximum size of queue, otherwise it may cause
several side effects e.g slab will warn when the size exceeds
KMALLOC_MAX_SIZE. Using KMALLOC_MAX_SIZE still looks too so this patch
tries to limit it to 64K. This value could be revisited if we found a
real case that needs more.
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 | 4 ++++
1 file changed, 4 insertions(+)
Seems like a weird location for a define. Either put defines on
top of the file, or near where they are used. I prefer the
second option.
Ok.
quoted
quoted
+#define PTR_RING_MAX_ALLOC 65536
+
I guess it's an arbitrary number. Seems like a sufficiently large one,
but pls add a comment so readers don't wonder. And please explain what
it does:
/* Callers can create ptr_ring structures with userspace-supplied
* parameters. This sets a limit on the size to make that usecase
* safe. If you ever change this, make sure to audit all callers.
*/
Also I think we should generally use either hex 0x10000 or (1 << 16).
I agree the number is arbitrary, so I still prefer the KMALLOC_MAX_SIZE
especially consider it was used by pfifo_fast now. Try to limit it to an
arbitrary may break lots of exist setups. E.g just google "txqueuelen
100000" can give me a lots of search results.
We can do any kind of optimization on top but not for -net now.
Thanks
Interesting. I have an idea for fixing this, but maybe
for now KMALLOC_MAX_SIZE does make sense. It's unfortunate that
this value is architecture dependent.
The patch still needs code comments though, and fix the math to
use the proper size.
quoted
quoted
/* Note: callers invoking this in a loop must use a compiler barrier,
* for example cpu_relax().
*
From: David Miller <davem@davemloft.net> Date: 2018-02-08 19:10:00
From: Jason Wang <redacted>
Date: Thu, 8 Feb 2018 11:59:25 +0800
We need limit the maximum size of queue, otherwise it may cause
several side effects e.g slab will warn when the size exceeds
KMALLOC_MAX_SIZE. Using KMALLOC_MAX_SIZE still looks too so this patch
tries to limit it to 64K. This value could be revisited if we found a
real case that needs more.
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-08 19:17:29
On Thu, Feb 08, 2018 at 02:58:40PM +0800, Jason Wang wrote:
On 2018年02月08日 12:45, Michael S. Tsirkin wrote:
quoted
On Thu, Feb 08, 2018 at 11:59:24AM +0800, Jason Wang wrote:
quoted
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")
I guess the actual patch is the one that switches tun to ptr_ring.
I think not, since the issue was large allocation.
quoted
In fact, I think the actual bugfix is patch 2/2. This specific one
just makes kmalloc less likely to fail but that's
not what syzbot reported.
Agree.
quoted
Then I would add this patch on top to make kmalloc less likely to fail.
@@ -466,7 +466,7 @@ static inline int ptr_ring_consume_batched_bh(struct ptr_ring *r,staticinlinevoid**__ptr_ring_init_queue_alloc(unsignedintsize,gfp_tgfp){-returnkcalloc(size,sizeof(void*),gfp);+returnkvmalloc_array(size,sizeof(void*),gfp|__GFP_ZERO);}staticinlinevoid__ptr_ring_set_size(structptr_ring*r,intsize)
This implies a bunch of limitations on the flags. From kvmalloc_node
docs:
* Reclaim modifiers - __GFP_NORETRY and __GFP_NOFAIL are not supported.
* __GFP_RETRY_MAYFAIL is supported, and it should be used only if kmalloc is
* preferable to the vmalloc fallback, due to visible performance drawbacks.
Fine with all the current users, but if we go this way, please add
documentation so future users don't misuse this API.
I suspect this is somehow a overkill since this means we need sync with
mm/vmalloc changes in the future to keep it synced.
quoted
Alternatively, test flags and call kvmalloc or kcalloc?
Similar to the above issue, I would rather leave it as is.
Thanks
How do we prevent someone from inevitably trying to use this with
GFP_ATOMIC?
From: Jason Wang <hidden> Date: 2018-02-09 03:49:16
On 2018年02月09日 03:17, Michael S. Tsirkin wrote:
On Thu, Feb 08, 2018 at 02:58:40PM +0800, Jason Wang wrote:
quoted
On 2018年02月08日 12:45, Michael S. Tsirkin wrote:
quoted
On Thu, Feb 08, 2018 at 11:59:24AM +0800, Jason Wang wrote:
quoted
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")
I guess the actual patch is the one that switches tun to ptr_ring.
I think not, since the issue was large allocation.
quoted
In fact, I think the actual bugfix is patch 2/2. This specific one
just makes kmalloc less likely to fail but that's
not what syzbot reported.
Agree.
quoted
Then I would add this patch on top to make kmalloc less likely to fail.
@@ -466,7 +466,7 @@ static inline int ptr_ring_consume_batched_bh(struct ptr_ring *r,staticinlinevoid**__ptr_ring_init_queue_alloc(unsignedintsize,gfp_tgfp){-returnkcalloc(size,sizeof(void*),gfp);+returnkvmalloc_array(size,sizeof(void*),gfp|__GFP_ZERO);}staticinlinevoid__ptr_ring_set_size(structptr_ring*r,intsize)
This implies a bunch of limitations on the flags. From kvmalloc_node
docs:
* Reclaim modifiers - __GFP_NORETRY and __GFP_NOFAIL are not supported.
* __GFP_RETRY_MAYFAIL is supported, and it should be used only if kmalloc is
* preferable to the vmalloc fallback, due to visible performance drawbacks.
Fine with all the current users, but if we go this way, please add
documentation so future users don't misuse this API.
I suspect this is somehow a overkill since this means we need sync with
mm/vmalloc changes in the future to keep it synced.
quoted
Alternatively, test flags and call kvmalloc or kcalloc?
Similar to the above issue, I would rather leave it as is.
Thanks
How do we prevent someone from inevitably trying to use this with
GFP_ATOMIC?
Well, we somehow can't prevent this even if there's a documentation,
that's why there's a BUG() in vmalloc code I think. And kvmalloc also
requires GFP_KERNEL otherewise another WARN().
So looks like the WARN()/BUG() should be sufficient?
Thanks
Another thing is kvm
From: Jason Wang <hidden> Date: 2018-02-09 03:50:40
On 2018年02月08日 23:50, Michael S. Tsirkin wrote:
On Thu, Feb 08, 2018 at 03:11:22PM +0800, Jason Wang wrote:
quoted
On 2018年02月08日 12:52, Michael S. Tsirkin wrote:
quoted
On Thu, Feb 08, 2018 at 11:59:25AM +0800, Jason Wang wrote:
quoted
We need limit the maximum size of queue, otherwise it may cause
several side effects e.g slab will warn when the size exceeds
KMALLOC_MAX_SIZE. Using KMALLOC_MAX_SIZE still looks too so this patch
tries to limit it to 64K. This value could be revisited if we found a
real case that needs more.
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 | 4 ++++
1 file changed, 4 insertions(+)
Seems like a weird location for a define. Either put defines on
top of the file, or near where they are used. I prefer the
second option.
Ok.
quoted
quoted
+#define PTR_RING_MAX_ALLOC 65536
+
I guess it's an arbitrary number. Seems like a sufficiently large one,
but pls add a comment so readers don't wonder. And please explain what
it does:
/* Callers can create ptr_ring structures with userspace-supplied
* parameters. This sets a limit on the size to make that usecase
* safe. If you ever change this, make sure to audit all callers.
*/
Also I think we should generally use either hex 0x10000 or (1 << 16).
I agree the number is arbitrary, so I still prefer the KMALLOC_MAX_SIZE
especially consider it was used by pfifo_fast now. Try to limit it to an
arbitrary may break lots of exist setups. E.g just google "txqueuelen
100000" can give me a lots of search results.
We can do any kind of optimization on top but not for -net now.
Thanks
Interesting. I have an idea for fixing this, but maybe
for now KMALLOC_MAX_SIZE does make sense. It's unfortunate that
this value is architecture dependent.
The patch still needs code comments though, and fix the math to
use the proper size.
From: Jason Wang <hidden> Date: 2018-02-09 03:51:09
On 2018年02月09日 03:09, David Miller wrote:
From: Jason Wang <redacted>
Date: Thu, 8 Feb 2018 11:59:25 +0800
quoted
We need limit the maximum size of queue, otherwise it may cause
several side effects e.g slab will warn when the size exceeds
KMALLOC_MAX_SIZE. Using KMALLOC_MAX_SIZE still looks too so this patch
tries to limit it to 64K. This value could be revisited if we found a
real case that needs more.
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 03:56:34
On Fri, Feb 09, 2018 at 11:49:12AM +0800, Jason Wang wrote:
On 2018年02月09日 03:17, Michael S. Tsirkin wrote:
quoted
On Thu, Feb 08, 2018 at 02:58:40PM +0800, Jason Wang wrote:
quoted
On 2018年02月08日 12:45, Michael S. Tsirkin wrote:
quoted
On Thu, Feb 08, 2018 at 11:59:24AM +0800, Jason Wang wrote:
quoted
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")
I guess the actual patch is the one that switches tun to ptr_ring.
I think not, since the issue was large allocation.
quoted
In fact, I think the actual bugfix is patch 2/2. This specific one
just makes kmalloc less likely to fail but that's
not what syzbot reported.
Agree.
quoted
Then I would add this patch on top to make kmalloc less likely to fail.
@@ -466,7 +466,7 @@ static inline int ptr_ring_consume_batched_bh(struct ptr_ring *r,staticinlinevoid**__ptr_ring_init_queue_alloc(unsignedintsize,gfp_tgfp){-returnkcalloc(size,sizeof(void*),gfp);+returnkvmalloc_array(size,sizeof(void*),gfp|__GFP_ZERO);}staticinlinevoid__ptr_ring_set_size(structptr_ring*r,intsize)
This implies a bunch of limitations on the flags. From kvmalloc_node
docs:
* Reclaim modifiers - __GFP_NORETRY and __GFP_NOFAIL are not supported.
* __GFP_RETRY_MAYFAIL is supported, and it should be used only if kmalloc is
* preferable to the vmalloc fallback, due to visible performance drawbacks.
Fine with all the current users, but if we go this way, please add
documentation so future users don't misuse this API.
I suspect this is somehow a overkill since this means we need sync with
mm/vmalloc changes in the future to keep it synced.
quoted
Alternatively, test flags and call kvmalloc or kcalloc?
Similar to the above issue, I would rather leave it as is.
Thanks
How do we prevent someone from inevitably trying to use this with
GFP_ATOMIC?
Well, we somehow can't prevent this even if there's a documentation, that's
why there's a BUG() in vmalloc code I think. And kvmalloc also requires
GFP_KERNEL otherewise another WARN().
So looks like the WARN()/BUG() should be sufficient?
Well vmalloc only triggers when you pass in a huge size.
Let's settle for
/* Not all gfp_t flags (besides GFP_KERNEL) are allowed. See
* documentation for vmalloc for which of them are legal.
*/
From: Jason Wang <hidden> Date: 2018-02-09 04:04:57
On 2018年02月09日 11:56, Michael S. Tsirkin wrote:
On Fri, Feb 09, 2018 at 11:49:12AM +0800, Jason Wang wrote:
quoted
On 2018年02月09日 03:17, Michael S. Tsirkin wrote:
quoted
On Thu, Feb 08, 2018 at 02:58:40PM +0800, Jason Wang wrote:
quoted
On 2018年02月08日 12:45, Michael S. Tsirkin wrote:
quoted
On Thu, Feb 08, 2018 at 11:59:24AM +0800, Jason Wang wrote:
quoted
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")
I guess the actual patch is the one that switches tun to ptr_ring.
I think not, since the issue was large allocation.
quoted
In fact, I think the actual bugfix is patch 2/2. This specific one
just makes kmalloc less likely to fail but that's
not what syzbot reported.
Agree.
quoted
Then I would add this patch on top to make kmalloc less likely to fail.
@@ -466,7 +466,7 @@ static inline int ptr_ring_consume_batched_bh(struct ptr_ring *r,staticinlinevoid**__ptr_ring_init_queue_alloc(unsignedintsize,gfp_tgfp){-returnkcalloc(size,sizeof(void*),gfp);+returnkvmalloc_array(size,sizeof(void*),gfp|__GFP_ZERO);}staticinlinevoid__ptr_ring_set_size(structptr_ring*r,intsize)
This implies a bunch of limitations on the flags. From kvmalloc_node
docs:
* Reclaim modifiers - __GFP_NORETRY and __GFP_NOFAIL are not supported.
* __GFP_RETRY_MAYFAIL is supported, and it should be used only if kmalloc is
* preferable to the vmalloc fallback, due to visible performance drawbacks.
Fine with all the current users, but if we go this way, please add
documentation so future users don't misuse this API.
I suspect this is somehow a overkill since this means we need sync with
mm/vmalloc changes in the future to keep it synced.
quoted
Alternatively, test flags and call kvmalloc or kcalloc?
Similar to the above issue, I would rather leave it as is.
Thanks
How do we prevent someone from inevitably trying to use this with
GFP_ATOMIC?
Well, we somehow can't prevent this even if there's a documentation, that's
why there's a BUG() in vmalloc code I think. And kvmalloc also requires
GFP_KERNEL otherewise another WARN().
So looks like the WARN()/BUG() should be sufficient?
Well vmalloc only triggers when you pass in a huge size.
Let's settle for
There's a:
BUG_ON(in_interrupt());
in __get_vm_area_node().
/* Not all gfp_t flags (besides GFP_KERNEL) are allowed. See
* documentation for vmalloc for which of them are legal.
*/