net/qrtr: restrict user-controlled length in qrtr_tun_write_iter()
authorSabyrzhan Tasbolatov <snovitoll@gmail.com>
Tue, 2 Feb 2021 09:20:59 +0000 (15:20 +0600)
committerJakub Kicinski <kuba@kernel.org>
Thu, 4 Feb 2021 00:29:06 +0000 (16:29 -0800)
commit2a80c15812372e554474b1dba0b1d8e467af295d
tree153898b70dc17995b02f7da69b1fabb49ed5eb7c
parenta4dc7eee9106a9d2a6e08b442db19677aa9699c7
net/qrtr: restrict user-controlled length in qrtr_tun_write_iter()

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: syzbot+c2a7e5c5211605a90865@syzkaller.appspotmail.com
Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
Link: https://lore.kernel.org/r/20210202092059.1361381-1-snovitoll@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/qrtr/tun.c