Skip to content

Commit

Permalink
net/qrtr: restrict user-controlled length in qrtr_tun_write_iter()
Browse files Browse the repository at this point in the history
syzbot found WARNING in qrtr_tun_write_iter [1] when write_iter length
exceeds KMALLOC_MAX_SIZE causing order >= MAX_ORDER condition.

Additionally, there is no check for 0 length write.

[1]
WARNING: mm/page_alloc.c:5011
[..]
Call Trace:
 alloc_pages_current+0x18c/0x2a0 mm/mempolicy.c:2267
 alloc_pages include/linux/gfp.h:547 [inline]
 kmalloc_order+0x2e/0xb0 mm/slab_common.c:837
 kmalloc_order_trace+0x14/0x120 mm/slab_common.c:853
 kmalloc include/linux/slab.h:557 [inline]
 kzalloc include/linux/slab.h:682 [inline]
 qrtr_tun_write_iter+0x8a/0x180 net/qrtr/tun.c:83
 call_write_iter include/linux/fs.h:1901 [inline]

Reported-by: [email protected]
Signed-off-by: Sabyrzhan Tasbolatov <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
novitoll authored and kuba-moo committed Feb 4, 2021
1 parent a4dc7ee commit 2a80c15
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions net/qrtr/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ static ssize_t qrtr_tun_write_iter(struct kiocb *iocb, struct iov_iter *from)
ssize_t ret;
void *kbuf;

if (!len)
return -EINVAL;

if (len > KMALLOC_MAX_SIZE)
return -ENOMEM;

kbuf = kzalloc(len, GFP_KERNEL);
if (!kbuf)
return -ENOMEM;
Expand Down

0 comments on commit 2a80c15

Please sign in to comment.