Patch "xdp: Fix zero-size allocation warning in xskq_create()" has been added to the 6.5-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    xdp: Fix zero-size allocation warning in xskq_create()

to the 6.5-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     xdp-fix-zero-size-allocation-warning-in-xskq_create.patch
and it can be found in the queue-6.5 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit c8af6ed533380cc8e936ad6847b1c057fdd2c560
Author: Andrew Kanner <andrew.kanner@xxxxxxxxx>
Date:   Sat Oct 7 10:51:49 2023 +0300

    xdp: Fix zero-size allocation warning in xskq_create()
    
    [ Upstream commit a12bbb3cccf03b12847de0f7a6772127f90936ac ]
    
    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.
    
    Fixes: 9f78bf330a66 ("xsk: support use vaddr as ring")
    Reported-by: syzbot+fae676d3cf469331fc89@xxxxxxxxxxxxxxxxxxxxxxxxx
    Closes: https://lore.kernel.org/all/000000000000c84b4705fb31741e@xxxxxxxxxx/T/
    Reported-by: syzbot+b132693e925cbbd89e26@xxxxxxxxxxxxxxxxxxxxxxxxx
    Closes: https://lore.kernel.org/all/000000000000e20df20606ebab4f@xxxxxxxxxx/T/
    Signed-off-by: Andrew Kanner <andrew.kanner@xxxxxxxxx>
    Signed-off-by: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
    Tested-by: syzbot+fae676d3cf469331fc89@xxxxxxxxxxxxxxxxxxxxxxxxx
    Acked-by: Magnus Karlsson <magnus.karlsson@xxxxxxxxx>
    Link: https://syzkaller.appspot.com/bug?extid=fae676d3cf469331fc89
    Link: https://lore.kernel.org/bpf/20231007075148.1759-1-andrew.kanner@xxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/xdp/xsk_queue.c b/net/xdp/xsk_queue.c
index f8905400ee07a..d2c2640300171 100644
--- a/net/xdp/xsk_queue.c
+++ b/net/xdp/xsk_queue.c
@@ -34,6 +34,16 @@ struct xsk_queue *xskq_create(u32 nentries, bool umem_queue)
 	q->ring_mask = nentries - 1;
 
 	size = xskq_get_ring_size(q, umem_queue);
+
+	/* size which is overflowing or close to SIZE_MAX will become 0 in
+	 * PAGE_ALIGN(), checking SIZE_MAX is enough due to the previous
+	 * is_power_of_2(), the rest will be handled by vmalloc_user()
+	 */
+	if (unlikely(size == SIZE_MAX)) {
+		kfree(q);
+		return NULL;
+	}
+
 	size = PAGE_ALIGN(size);
 
 	q->ring = vmalloc_user(size);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux