All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v2] net/xdp: fix zero-size allocation warning in xskq_create()
@ 2023-10-02 22:29 ` Andrew Kanner
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew Kanner @ 2023-10-02 22:29 UTC (permalink / raw)
  To: bjorn, magnus.karlsson, maciej.fijalkowski, jonathan.lemon,
	davem, edumazet, kuba, pabeni, aleksander.lobakin, xuanzhuo, ast,
	hawk, john.fastabend, daniel
  Cc: linux-kernel-mentees, netdev, bpf, linux-kernel,
	syzbot+fae676d3cf469331fc89, Andrew Kanner

Syzkaller reported the following issue:
 ------------[ cut here ]------------
 WARNING: CPU: 0 PID: 2807 at mm/vmalloc.c:3247 __vmalloc_node_range (mm/vmalloc.c:3361)
 Modules linked in:
 CPU: 0 PID: 2807 Comm: repro Not tainted 6.6.0-rc2+ #12
 Hardware name: Generic DT based system
 unwind_backtrace from show_stack (arch/arm/kernel/traps.c:258)
 show_stack from dump_stack_lvl (lib/dump_stack.c:107 (discriminator 1))
 dump_stack_lvl from __warn (kernel/panic.c:633 kernel/panic.c:680)
 __warn from warn_slowpath_fmt (./include/linux/context_tracking.h:153 kernel/panic.c:700)
 warn_slowpath_fmt from __vmalloc_node_range (mm/vmalloc.c:3361 (discriminator 3))
 __vmalloc_node_range from vmalloc_user (mm/vmalloc.c:3478)
 vmalloc_user from xskq_create (net/xdp/xsk_queue.c:40)
 xskq_create from xsk_setsockopt (net/xdp/xsk.c:953 net/xdp/xsk.c:1286)
 xsk_setsockopt from __sys_setsockopt (net/socket.c:2308)
 __sys_setsockopt from ret_fast_syscall (arch/arm/kernel/entry-common.S:68)

xskq_get_ring_size() uses struct_size() macro to safely calculate the
size of struct xsk_queue and q->nentries of desc members. But the
syzkaller repro was able to set q->nentries with the value initially
taken from copy_from_sockptr() high enough to return SIZE_MAX by
struct_size(). The next PAGE_ALIGN(size) is such case will overflow
the size_t value and set it to 0. This will trigger WARN_ON_ONCE in
vmalloc_user() -> __vmalloc_node_range().

The issue is reproducible on 32-bit arm kernel.

Reported-and-tested-by: syzbot+fae676d3cf469331fc89@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/000000000000c84b4705fb31741e@google.com/T/
Link: https://syzkaller.appspot.com/bug?extid=fae676d3cf469331fc89
Fixes: 9f78bf330a66 ("xsk: support use vaddr as ring")
Signed-off-by: Andrew Kanner <andrew.kanner@gmail.com>
---

Notes (akanner):
    v2:
      - use unlikely() optimization for the case with SIZE_MAX return from
        struct_size(), suggested by Alexander Lobakin
        <aleksander.lobakin@intel.com>
      - cc-ed 4 more maintainers, mentioned by cc_maintainers patchwork
        test
    
    v1: https://lore.kernel.org/all/20230928204440.543-1-andrew.kanner@gmail.com/T/
      - RFC notes:
        It was found that net/xdp/xsk.c:xsk_setsockopt() uses
        copy_from_sockptr() to get the number of entries (int) for cases
        with XDP_RX_RING / XDP_TX_RING and XDP_UMEM_FILL_RING /
        XDP_UMEM_COMPLETION_RING.
    
        Next in xsk_init_queue() there're 2 sanity checks (entries == 0)
        and (!is_power_of_2(entries)) for which -EINVAL will be returned.
    
        After that net/xdp/xsk_queue.c:xskq_create() will calculate the
        size multipling the number of entries (int) with the size of u64,
        at least.
    
        I wonder if there should be the upper bound (e.g. the 3rd sanity
        check inside xsk_init_queue()). It seems that without the upper
        limit it's quiet easy to overflow the allocated size (SIZE_MAX),
        especially for 32-bit architectures, for example arm nodes which
        were used by the syzkaller.
    
        In this patch I added a naive check for SIZE_MAX which helped to
        skip zero-size allocation after overflow, but maybe it's not quite
        right. Please, suggest if you have any thoughts about the
        appropriate limit for the size of these xdp rings.
    
        PS: the initial number of entries is 0x20000000 in syzkaller
        repro: syscall(__NR_setsockopt, (intptr_t)r[0], 0x11b, 3,
        0x20000040, 0x20);
    
        Link:
        https://syzkaller.appspot.com/text?tag=ReproC&x=10910f18280000

 net/xdp/xsk_queue.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/xdp/xsk_queue.c b/net/xdp/xsk_queue.c
index f8905400ee07..b03d1bfb6978 100644
--- a/net/xdp/xsk_queue.c
+++ b/net/xdp/xsk_queue.c
@@ -34,6 +34,9 @@ struct xsk_queue *xskq_create(u32 nentries, bool umem_queue)
 	q->ring_mask = nentries - 1;
 
 	size = xskq_get_ring_size(q, umem_queue);
+	if (unlikely(size == SIZE_MAX))
+		return NULL;
+
 	size = PAGE_ALIGN(size);
 
 	q->ring = vmalloc_user(size);
-- 
2.39.3


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

* [PATCH net-next v2] net/xdp: fix zero-size allocation warning in xskq_create()
@ 2023-10-02 22:29 ` Andrew Kanner
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew Kanner @ 2023-10-02 22:29 UTC (permalink / raw)
  To: bjorn, magnus.karlsson, maciej.fijalkowski, jonathan.lemon,
	davem, edumazet, kuba, pabeni, aleksander.lobakin, xuanzhuo, ast,
	hawk, john.fastabend, daniel
  Cc: netdev, linux-kernel, bpf, linux-kernel-mentees,
	syzbot+fae676d3cf469331fc89

Syzkaller reported the following issue:
 ------------[ cut here ]------------
 WARNING: CPU: 0 PID: 2807 at mm/vmalloc.c:3247 __vmalloc_node_range (mm/vmalloc.c:3361)
 Modules linked in:
 CPU: 0 PID: 2807 Comm: repro Not tainted 6.6.0-rc2+ #12
 Hardware name: Generic DT based system
 unwind_backtrace from show_stack (arch/arm/kernel/traps.c:258)
 show_stack from dump_stack_lvl (lib/dump_stack.c:107 (discriminator 1))
 dump_stack_lvl from __warn (kernel/panic.c:633 kernel/panic.c:680)
 __warn from warn_slowpath_fmt (./include/linux/context_tracking.h:153 kernel/panic.c:700)
 warn_slowpath_fmt from __vmalloc_node_range (mm/vmalloc.c:3361 (discriminator 3))
 __vmalloc_node_range from vmalloc_user (mm/vmalloc.c:3478)
 vmalloc_user from xskq_create (net/xdp/xsk_queue.c:40)
 xskq_create from xsk_setsockopt (net/xdp/xsk.c:953 net/xdp/xsk.c:1286)
 xsk_setsockopt from __sys_setsockopt (net/socket.c:2308)
 __sys_setsockopt from ret_fast_syscall (arch/arm/kernel/entry-common.S:68)

xskq_get_ring_size() uses struct_size() macro to safely calculate the
size of struct xsk_queue and q->nentries of desc members. But the
syzkaller repro was able to set q->nentries with the value initially
taken from copy_from_sockptr() high enough to return SIZE_MAX by
struct_size(). The next PAGE_ALIGN(size) is such case will overflow
the size_t value and set it to 0. This will trigger WARN_ON_ONCE in
vmalloc_user() -> __vmalloc_node_range().

The issue is reproducible on 32-bit arm kernel.

Reported-and-tested-by: syzbot+fae676d3cf469331fc89@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/000000000000c84b4705fb31741e@google.com/T/
Link: https://syzkaller.appspot.com/bug?extid=fae676d3cf469331fc89
Fixes: 9f78bf330a66 ("xsk: support use vaddr as ring")
Signed-off-by: Andrew Kanner <andrew.kanner@gmail.com>
---

Notes (akanner):
    v2:
      - use unlikely() optimization for the case with SIZE_MAX return from
        struct_size(), suggested by Alexander Lobakin
        <aleksander.lobakin@intel.com>
      - cc-ed 4 more maintainers, mentioned by cc_maintainers patchwork
        test
    
    v1: https://lore.kernel.org/all/20230928204440.543-1-andrew.kanner@gmail.com/T/
      - RFC notes:
        It was found that net/xdp/xsk.c:xsk_setsockopt() uses
        copy_from_sockptr() to get the number of entries (int) for cases
        with XDP_RX_RING / XDP_TX_RING and XDP_UMEM_FILL_RING /
        XDP_UMEM_COMPLETION_RING.
    
        Next in xsk_init_queue() there're 2 sanity checks (entries == 0)
        and (!is_power_of_2(entries)) for which -EINVAL will be returned.
    
        After that net/xdp/xsk_queue.c:xskq_create() will calculate the
        size multipling the number of entries (int) with the size of u64,
        at least.
    
        I wonder if there should be the upper bound (e.g. the 3rd sanity
        check inside xsk_init_queue()). It seems that without the upper
        limit it's quiet easy to overflow the allocated size (SIZE_MAX),
        especially for 32-bit architectures, for example arm nodes which
        were used by the syzkaller.
    
        In this patch I added a naive check for SIZE_MAX which helped to
        skip zero-size allocation after overflow, but maybe it's not quite
        right. Please, suggest if you have any thoughts about the
        appropriate limit for the size of these xdp rings.
    
        PS: the initial number of entries is 0x20000000 in syzkaller
        repro: syscall(__NR_setsockopt, (intptr_t)r[0], 0x11b, 3,
        0x20000040, 0x20);
    
        Link:
        https://syzkaller.appspot.com/text?tag=ReproC&x=10910f18280000

 net/xdp/xsk_queue.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/xdp/xsk_queue.c b/net/xdp/xsk_queue.c
index f8905400ee07..b03d1bfb6978 100644
--- a/net/xdp/xsk_queue.c
+++ b/net/xdp/xsk_queue.c
@@ -34,6 +34,9 @@ struct xsk_queue *xskq_create(u32 nentries, bool umem_queue)
 	q->ring_mask = nentries - 1;
 
 	size = xskq_get_ring_size(q, umem_queue);
+	if (unlikely(size == SIZE_MAX))
+		return NULL;
+
 	size = PAGE_ALIGN(size);
 
 	q->ring = vmalloc_user(size);
-- 
2.39.3

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [PATCH net-next v2] net/xdp: fix zero-size allocation warning in xskq_create()
  2023-10-02 22:29 ` Andrew Kanner
@ 2023-10-03 10:26   ` Alexander Lobakin
  -1 siblings, 0 replies; 8+ messages in thread
From: Alexander Lobakin @ 2023-10-03 10:26 UTC (permalink / raw)
  To: Andrew Kanner
  Cc: bjorn, magnus.karlsson, maciej.fijalkowski, jonathan.lemon,
	davem, edumazet, kuba, pabeni, xuanzhuo, ast, hawk,
	john.fastabend, daniel, linux-kernel-mentees, netdev, bpf,
	linux-kernel, syzbot+fae676d3cf469331fc89

From: Andrew Kanner <andrew.kanner@gmail.com>
Date: Tue,  3 Oct 2023 01:29:40 +0300

> Syzkaller reported the following issue:
>  ------------[ cut here ]------------
>  WARNING: CPU: 0 PID: 2807 at mm/vmalloc.c:3247 __vmalloc_node_range (mm/vmalloc.c:3361)
>  Modules linked in:
>  CPU: 0 PID: 2807 Comm: repro Not tainted 6.6.0-rc2+ #12
>  Hardware name: Generic DT based system
>  unwind_backtrace from show_stack (arch/arm/kernel/traps.c:258)
>  show_stack from dump_stack_lvl (lib/dump_stack.c:107 (discriminator 1))
>  dump_stack_lvl from __warn (kernel/panic.c:633 kernel/panic.c:680)
>  __warn from warn_slowpath_fmt (./include/linux/context_tracking.h:153 kernel/panic.c:700)
>  warn_slowpath_fmt from __vmalloc_node_range (mm/vmalloc.c:3361 (discriminator 3))
>  __vmalloc_node_range from vmalloc_user (mm/vmalloc.c:3478)
>  vmalloc_user from xskq_create (net/xdp/xsk_queue.c:40)
>  xskq_create from xsk_setsockopt (net/xdp/xsk.c:953 net/xdp/xsk.c:1286)
>  xsk_setsockopt from __sys_setsockopt (net/socket.c:2308)
>  __sys_setsockopt from ret_fast_syscall (arch/arm/kernel/entry-common.S:68)
> 
> xskq_get_ring_size() uses struct_size() macro to safely calculate the
> size of struct xsk_queue and q->nentries of desc members. But the
> syzkaller repro was able to set q->nentries with the value initially
> taken from copy_from_sockptr() high enough to return SIZE_MAX by
> struct_size(). The next PAGE_ALIGN(size) is such case will overflow
> the size_t value and set it to 0. This will trigger WARN_ON_ONCE in
> vmalloc_user() -> __vmalloc_node_range().
> 
> The issue is reproducible on 32-bit arm kernel.
> 
> Reported-and-tested-by: syzbot+fae676d3cf469331fc89@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/all/000000000000c84b4705fb31741e@google.com/T/
> Link: https://syzkaller.appspot.com/bug?extid=fae676d3cf469331fc89
> Fixes: 9f78bf330a66 ("xsk: support use vaddr as ring")
> Signed-off-by: Andrew Kanner <andrew.kanner@gmail.com>

Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com>

[...]

Thanks,
Olek

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

* Re: [PATCH net-next v2] net/xdp: fix zero-size allocation warning in xskq_create()
@ 2023-10-03 10:26   ` Alexander Lobakin
  0 siblings, 0 replies; 8+ messages in thread
From: Alexander Lobakin @ 2023-10-03 10:26 UTC (permalink / raw)
  To: Andrew Kanner
  Cc: xuanzhuo, maciej.fijalkowski, hawk, daniel, netdev,
	john.fastabend, bjorn, ast, edumazet, linux-kernel,
	jonathan.lemon, kuba, bpf, pabeni, linux-kernel-mentees, davem,
	magnus.karlsson, syzbot+fae676d3cf469331fc89

From: Andrew Kanner <andrew.kanner@gmail.com>
Date: Tue,  3 Oct 2023 01:29:40 +0300

> Syzkaller reported the following issue:
>  ------------[ cut here ]------------
>  WARNING: CPU: 0 PID: 2807 at mm/vmalloc.c:3247 __vmalloc_node_range (mm/vmalloc.c:3361)
>  Modules linked in:
>  CPU: 0 PID: 2807 Comm: repro Not tainted 6.6.0-rc2+ #12
>  Hardware name: Generic DT based system
>  unwind_backtrace from show_stack (arch/arm/kernel/traps.c:258)
>  show_stack from dump_stack_lvl (lib/dump_stack.c:107 (discriminator 1))
>  dump_stack_lvl from __warn (kernel/panic.c:633 kernel/panic.c:680)
>  __warn from warn_slowpath_fmt (./include/linux/context_tracking.h:153 kernel/panic.c:700)
>  warn_slowpath_fmt from __vmalloc_node_range (mm/vmalloc.c:3361 (discriminator 3))
>  __vmalloc_node_range from vmalloc_user (mm/vmalloc.c:3478)
>  vmalloc_user from xskq_create (net/xdp/xsk_queue.c:40)
>  xskq_create from xsk_setsockopt (net/xdp/xsk.c:953 net/xdp/xsk.c:1286)
>  xsk_setsockopt from __sys_setsockopt (net/socket.c:2308)
>  __sys_setsockopt from ret_fast_syscall (arch/arm/kernel/entry-common.S:68)
> 
> xskq_get_ring_size() uses struct_size() macro to safely calculate the
> size of struct xsk_queue and q->nentries of desc members. But the
> syzkaller repro was able to set q->nentries with the value initially
> taken from copy_from_sockptr() high enough to return SIZE_MAX by
> struct_size(). The next PAGE_ALIGN(size) is such case will overflow
> the size_t value and set it to 0. This will trigger WARN_ON_ONCE in
> vmalloc_user() -> __vmalloc_node_range().
> 
> The issue is reproducible on 32-bit arm kernel.
> 
> Reported-and-tested-by: syzbot+fae676d3cf469331fc89@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/all/000000000000c84b4705fb31741e@google.com/T/
> Link: https://syzkaller.appspot.com/bug?extid=fae676d3cf469331fc89
> Fixes: 9f78bf330a66 ("xsk: support use vaddr as ring")
> Signed-off-by: Andrew Kanner <andrew.kanner@gmail.com>

Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com>

[...]

Thanks,
Olek
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [PATCH net-next v2] net/xdp: fix zero-size allocation warning in xskq_create()
  2023-10-02 22:29 ` Andrew Kanner
@ 2023-10-04 22:49   ` Daniel Borkmann via Linux-kernel-mentees
  -1 siblings, 0 replies; 8+ messages in thread
From: Daniel Borkmann @ 2023-10-04 22:49 UTC (permalink / raw)
  To: Andrew Kanner, bjorn, magnus.karlsson, maciej.fijalkowski,
	jonathan.lemon, davem, edumazet, kuba, pabeni,
	aleksander.lobakin, xuanzhuo, ast, hawk, john.fastabend
  Cc: linux-kernel-mentees, netdev, bpf, linux-kernel,
	syzbot+fae676d3cf469331fc89

On 10/3/23 12:29 AM, Andrew Kanner wrote:
> Syzkaller reported the following issue:
>   ------------[ cut here ]------------
>   WARNING: CPU: 0 PID: 2807 at mm/vmalloc.c:3247 __vmalloc_node_range (mm/vmalloc.c:3361)
>   Modules linked in:
>   CPU: 0 PID: 2807 Comm: repro Not tainted 6.6.0-rc2+ #12
>   Hardware name: Generic DT based system
>   unwind_backtrace from show_stack (arch/arm/kernel/traps.c:258)
>   show_stack from dump_stack_lvl (lib/dump_stack.c:107 (discriminator 1))
>   dump_stack_lvl from __warn (kernel/panic.c:633 kernel/panic.c:680)
>   __warn from warn_slowpath_fmt (./include/linux/context_tracking.h:153 kernel/panic.c:700)
>   warn_slowpath_fmt from __vmalloc_node_range (mm/vmalloc.c:3361 (discriminator 3))
>   __vmalloc_node_range from vmalloc_user (mm/vmalloc.c:3478)
>   vmalloc_user from xskq_create (net/xdp/xsk_queue.c:40)
>   xskq_create from xsk_setsockopt (net/xdp/xsk.c:953 net/xdp/xsk.c:1286)
>   xsk_setsockopt from __sys_setsockopt (net/socket.c:2308)
>   __sys_setsockopt from ret_fast_syscall (arch/arm/kernel/entry-common.S:68)
> 
> xskq_get_ring_size() uses struct_size() macro to safely calculate the
> size of struct xsk_queue and q->nentries of desc members. But the
> syzkaller repro was able to set q->nentries with the value initially
> taken from copy_from_sockptr() high enough to return SIZE_MAX by
> struct_size(). The next PAGE_ALIGN(size) is such case will overflow
> the size_t value and set it to 0. This will trigger WARN_ON_ONCE in
> vmalloc_user() -> __vmalloc_node_range().
> 
> The issue is reproducible on 32-bit arm kernel.
> 
> Reported-and-tested-by: syzbot+fae676d3cf469331fc89@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/all/000000000000c84b4705fb31741e@google.com/T/
> Link: https://syzkaller.appspot.com/bug?extid=fae676d3cf469331fc89
> Fixes: 9f78bf330a66 ("xsk: support use vaddr as ring")
> Signed-off-by: Andrew Kanner <andrew.kanner@gmail.com>

I guess also:

Reported-by: syzbot+b132693e925cbbd89e26@syzkaller.appspotmail.com

Moreover, this fix is needed in bpf/net tree (as opposed to *-next tree), right?

>   net/xdp/xsk_queue.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/net/xdp/xsk_queue.c b/net/xdp/xsk_queue.c
> index f8905400ee07..b03d1bfb6978 100644
> --- a/net/xdp/xsk_queue.c
> +++ b/net/xdp/xsk_queue.c
> @@ -34,6 +34,9 @@ struct xsk_queue *xskq_create(u32 nentries, bool umem_queue)
>   	q->ring_mask = nentries - 1;
>   
>   	size = xskq_get_ring_size(q, umem_queue);
> +	if (unlikely(size == SIZE_MAX))
> +		return NULL;

Doesn't this leak q here ?

>   	size = PAGE_ALIGN(size);
>   
>   	q->ring = vmalloc_user(size);
> 


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

* Re: [PATCH net-next v2] net/xdp: fix zero-size allocation warning in xskq_create()
@ 2023-10-04 22:49   ` Daniel Borkmann via Linux-kernel-mentees
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Borkmann via Linux-kernel-mentees @ 2023-10-04 22:49 UTC (permalink / raw)
  To: Andrew Kanner, bjorn, magnus.karlsson, maciej.fijalkowski,
	jonathan.lemon, davem, edumazet, kuba, pabeni,
	aleksander.lobakin, xuanzhuo, ast, hawk, john.fastabend
  Cc: netdev, bpf, linux-kernel-mentees, linux-kernel,
	syzbot+fae676d3cf469331fc89

On 10/3/23 12:29 AM, Andrew Kanner wrote:
> Syzkaller reported the following issue:
>   ------------[ cut here ]------------
>   WARNING: CPU: 0 PID: 2807 at mm/vmalloc.c:3247 __vmalloc_node_range (mm/vmalloc.c:3361)
>   Modules linked in:
>   CPU: 0 PID: 2807 Comm: repro Not tainted 6.6.0-rc2+ #12
>   Hardware name: Generic DT based system
>   unwind_backtrace from show_stack (arch/arm/kernel/traps.c:258)
>   show_stack from dump_stack_lvl (lib/dump_stack.c:107 (discriminator 1))
>   dump_stack_lvl from __warn (kernel/panic.c:633 kernel/panic.c:680)
>   __warn from warn_slowpath_fmt (./include/linux/context_tracking.h:153 kernel/panic.c:700)
>   warn_slowpath_fmt from __vmalloc_node_range (mm/vmalloc.c:3361 (discriminator 3))
>   __vmalloc_node_range from vmalloc_user (mm/vmalloc.c:3478)
>   vmalloc_user from xskq_create (net/xdp/xsk_queue.c:40)
>   xskq_create from xsk_setsockopt (net/xdp/xsk.c:953 net/xdp/xsk.c:1286)
>   xsk_setsockopt from __sys_setsockopt (net/socket.c:2308)
>   __sys_setsockopt from ret_fast_syscall (arch/arm/kernel/entry-common.S:68)
> 
> xskq_get_ring_size() uses struct_size() macro to safely calculate the
> size of struct xsk_queue and q->nentries of desc members. But the
> syzkaller repro was able to set q->nentries with the value initially
> taken from copy_from_sockptr() high enough to return SIZE_MAX by
> struct_size(). The next PAGE_ALIGN(size) is such case will overflow
> the size_t value and set it to 0. This will trigger WARN_ON_ONCE in
> vmalloc_user() -> __vmalloc_node_range().
> 
> The issue is reproducible on 32-bit arm kernel.
> 
> Reported-and-tested-by: syzbot+fae676d3cf469331fc89@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/all/000000000000c84b4705fb31741e@google.com/T/
> Link: https://syzkaller.appspot.com/bug?extid=fae676d3cf469331fc89
> Fixes: 9f78bf330a66 ("xsk: support use vaddr as ring")
> Signed-off-by: Andrew Kanner <andrew.kanner@gmail.com>

I guess also:

Reported-by: syzbot+b132693e925cbbd89e26@syzkaller.appspotmail.com

Moreover, this fix is needed in bpf/net tree (as opposed to *-next tree), right?

>   net/xdp/xsk_queue.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/net/xdp/xsk_queue.c b/net/xdp/xsk_queue.c
> index f8905400ee07..b03d1bfb6978 100644
> --- a/net/xdp/xsk_queue.c
> +++ b/net/xdp/xsk_queue.c
> @@ -34,6 +34,9 @@ struct xsk_queue *xskq_create(u32 nentries, bool umem_queue)
>   	q->ring_mask = nentries - 1;
>   
>   	size = xskq_get_ring_size(q, umem_queue);
> +	if (unlikely(size == SIZE_MAX))
> +		return NULL;

Doesn't this leak q here ?

>   	size = PAGE_ALIGN(size);
>   
>   	q->ring = vmalloc_user(size);
> 

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [PATCH net-next v2] net/xdp: fix zero-size allocation warning in xskq_create()
  2023-10-04 22:49   ` Daniel Borkmann via Linux-kernel-mentees
@ 2023-10-05  7:35     ` Andrew Kanner
  -1 siblings, 0 replies; 8+ messages in thread
From: Andrew Kanner @ 2023-10-05  7:35 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: bjorn, magnus.karlsson, maciej.fijalkowski, jonathan.lemon,
	davem, edumazet, kuba, pabeni, aleksander.lobakin, xuanzhuo, ast,
	hawk, john.fastabend, linux-kernel-mentees, netdev, bpf,
	linux-kernel, syzbot+fae676d3cf469331fc89

On Thu, Oct 05, 2023 at 12:49:23AM +0200, Daniel Borkmann wrote:
[...]
> > 
> > Reported-and-tested-by: syzbot+fae676d3cf469331fc89@syzkaller.appspotmail.com
> > Closes: https://lore.kernel.org/all/000000000000c84b4705fb31741e@google.com/T/
> > Link: https://syzkaller.appspot.com/bug?extid=fae676d3cf469331fc89
> > Fixes: 9f78bf330a66 ("xsk: support use vaddr as ring")
> > Signed-off-by: Andrew Kanner <andrew.kanner@gmail.com>
> 
> I guess also:
> 
> Reported-by: syzbot+b132693e925cbbd89e26@syzkaller.appspotmail.com
> 
> Moreover, this fix is needed in bpf/net tree (as opposed to *-next tree), right?
>

Seems, so - I will check.

> >   net/xdp/xsk_queue.c | 3 +++
> >   1 file changed, 3 insertions(+)
> > 
> > diff --git a/net/xdp/xsk_queue.c b/net/xdp/xsk_queue.c
> > index f8905400ee07..b03d1bfb6978 100644
> > --- a/net/xdp/xsk_queue.c
> > +++ b/net/xdp/xsk_queue.c
> > @@ -34,6 +34,9 @@ struct xsk_queue *xskq_create(u32 nentries, bool umem_queue)
> >   	q->ring_mask = nentries - 1;
> >   	size = xskq_get_ring_size(q, umem_queue);
> > +	if (unlikely(size == SIZE_MAX))
> > +		return NULL;
> 
> Doesn't this leak q here ?
> 
> >   	size = PAGE_ALIGN(size);
> >   	q->ring = vmalloc_user(size);
> > 
> 

It is.
Thanks, Daniel, I will fix it in v3. 

pw-bot: cr

--
Andrew Kanner

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

* Re: [PATCH net-next v2] net/xdp: fix zero-size allocation warning in xskq_create()
@ 2023-10-05  7:35     ` Andrew Kanner
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew Kanner @ 2023-10-05  7:35 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: xuanzhuo, maciej.fijalkowski, hawk, netdev, john.fastabend,
	bjorn, ast, aleksander.lobakin, edumazet, linux-kernel,
	jonathan.lemon, kuba, bpf, pabeni, linux-kernel-mentees, davem,
	magnus.karlsson, syzbot+fae676d3cf469331fc89

On Thu, Oct 05, 2023 at 12:49:23AM +0200, Daniel Borkmann wrote:
[...]
> > 
> > Reported-and-tested-by: syzbot+fae676d3cf469331fc89@syzkaller.appspotmail.com
> > Closes: https://lore.kernel.org/all/000000000000c84b4705fb31741e@google.com/T/
> > Link: https://syzkaller.appspot.com/bug?extid=fae676d3cf469331fc89
> > Fixes: 9f78bf330a66 ("xsk: support use vaddr as ring")
> > Signed-off-by: Andrew Kanner <andrew.kanner@gmail.com>
> 
> I guess also:
> 
> Reported-by: syzbot+b132693e925cbbd89e26@syzkaller.appspotmail.com
> 
> Moreover, this fix is needed in bpf/net tree (as opposed to *-next tree), right?
>

Seems, so - I will check.

> >   net/xdp/xsk_queue.c | 3 +++
> >   1 file changed, 3 insertions(+)
> > 
> > diff --git a/net/xdp/xsk_queue.c b/net/xdp/xsk_queue.c
> > index f8905400ee07..b03d1bfb6978 100644
> > --- a/net/xdp/xsk_queue.c
> > +++ b/net/xdp/xsk_queue.c
> > @@ -34,6 +34,9 @@ struct xsk_queue *xskq_create(u32 nentries, bool umem_queue)
> >   	q->ring_mask = nentries - 1;
> >   	size = xskq_get_ring_size(q, umem_queue);
> > +	if (unlikely(size == SIZE_MAX))
> > +		return NULL;
> 
> Doesn't this leak q here ?
> 
> >   	size = PAGE_ALIGN(size);
> >   	q->ring = vmalloc_user(size);
> > 
> 

It is.
Thanks, Daniel, I will fix it in v3. 

pw-bot: cr

--
Andrew Kanner
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

end of thread, other threads:[~2023-10-05 16:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-02 22:29 [PATCH net-next v2] net/xdp: fix zero-size allocation warning in xskq_create() Andrew Kanner
2023-10-02 22:29 ` Andrew Kanner
2023-10-03 10:26 ` Alexander Lobakin
2023-10-03 10:26   ` Alexander Lobakin
2023-10-04 22:49 ` Daniel Borkmann
2023-10-04 22:49   ` Daniel Borkmann via Linux-kernel-mentees
2023-10-05  7:35   ` Andrew Kanner
2023-10-05  7:35     ` Andrew Kanner

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.