Commit 12ee6d75 authored by Eric Dumazet's avatar Eric Dumazet Committed by Greg Kroah-Hartman

ptr_ring: use kmalloc_array()


[ Upstream commit 81fbfe8a ]

As found by syzkaller, malicious users can set whatever tx_queue_len
on a tun device and eventually crash the kernel.

Lets remove the ALIGN(XXX, SMP_CACHE_BYTES) thing since a small
ring buffer is not fast anyway.

Fixes: 2e0ab8ca ("ptr_ring: array based FIFO for pointers")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reported-by: default avatarDmitry Vyukov <dvyukov@google.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent cb445bfc
...@@ -371,9 +371,9 @@ static inline void *ptr_ring_consume_bh(struct ptr_ring *r) ...@@ -371,9 +371,9 @@ static inline void *ptr_ring_consume_bh(struct ptr_ring *r)
__PTR_RING_PEEK_CALL_v; \ __PTR_RING_PEEK_CALL_v; \
}) })
static inline void **__ptr_ring_init_queue_alloc(int size, gfp_t gfp) static inline void **__ptr_ring_init_queue_alloc(unsigned int size, gfp_t gfp)
{ {
return kzalloc(ALIGN(size * sizeof(void *), SMP_CACHE_BYTES), gfp); return kcalloc(size, sizeof(void *), gfp);
} }
static inline void __ptr_ring_set_size(struct ptr_ring *r, int size) static inline void __ptr_ring_set_size(struct ptr_ring *r, int size)
...@@ -462,7 +462,8 @@ static inline int ptr_ring_resize(struct ptr_ring *r, int size, gfp_t gfp, ...@@ -462,7 +462,8 @@ static inline int ptr_ring_resize(struct ptr_ring *r, int size, gfp_t gfp,
* In particular if you consume ring in interrupt or BH context, you must * In particular if you consume ring in interrupt or BH context, you must
* disable interrupts/BH when doing so. * disable interrupts/BH when doing so.
*/ */
static inline int ptr_ring_resize_multiple(struct ptr_ring **rings, int nrings, static inline int ptr_ring_resize_multiple(struct ptr_ring **rings,
unsigned int nrings,
int size, int size,
gfp_t gfp, void (*destroy)(void *)) gfp_t gfp, void (*destroy)(void *))
{ {
...@@ -470,7 +471,7 @@ static inline int ptr_ring_resize_multiple(struct ptr_ring **rings, int nrings, ...@@ -470,7 +471,7 @@ static inline int ptr_ring_resize_multiple(struct ptr_ring **rings, int nrings,
void ***queues; void ***queues;
int i; int i;
queues = kmalloc(nrings * sizeof *queues, gfp); queues = kmalloc_array(nrings, sizeof(*queues), gfp);
if (!queues) if (!queues)
goto noqueues; goto noqueues;
......
...@@ -162,7 +162,8 @@ static inline int skb_array_resize(struct skb_array *a, int size, gfp_t gfp) ...@@ -162,7 +162,8 @@ static inline int skb_array_resize(struct skb_array *a, int size, gfp_t gfp)
} }
static inline int skb_array_resize_multiple(struct skb_array **rings, static inline int skb_array_resize_multiple(struct skb_array **rings,
int nrings, int size, gfp_t gfp) int nrings, unsigned int size,
gfp_t gfp)
{ {
BUILD_BUG_ON(offsetof(struct skb_array, ring)); BUILD_BUG_ON(offsetof(struct skb_array, ring));
return ptr_ring_resize_multiple((struct ptr_ring **)rings, return ptr_ring_resize_multiple((struct ptr_ring **)rings,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment