summaryrefslogtreecommitdiff
path: root/drivers/dma-buf/udmabuf.c
diff options
context:
space:
mode:
authorPavel Skripkin <paskripkin@gmail.com>2021-12-30 17:26:49 +0300
committerGerd Hoffmann <kraxel@redhat.com>2022-01-18 09:52:41 +0300
commit2b6dd600dd72573c23ea180b5b0b2f1813405882 (patch)
treeddd26905a18679cd5860f0b3e1ad926348c7e52e /drivers/dma-buf/udmabuf.c
parent269332997a160b3785690a32d2c5496bce7dae51 (diff)
downloadlinux-2b6dd600dd72573c23ea180b5b0b2f1813405882.tar.xz
udmabuf: validate ubuf->pagecount
Syzbot has reported GPF in sg_alloc_append_table_from_pages(). The problem was in ubuf->pages == ZERO_PTR. ubuf->pagecount is calculated from arguments passed from user-space. If user creates udmabuf with list.size == 0 then ubuf->pagecount will be also equal to zero; it causes kmalloc_array() to return ZERO_PTR. Fix it by validating ubuf->pagecount before passing it to kmalloc_array(). Fixes: fbb0de795078 ("Add udmabuf misc device") Reported-and-tested-by: syzbot+2c56b725ec547fa9cb29@syzkaller.appspotmail.com Signed-off-by: Pavel Skripkin <paskripkin@gmail.com> Link: http://patchwork.freedesktop.org/patch/msgid/20211230142649.23022-1-paskripkin@gmail.com Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'drivers/dma-buf/udmabuf.c')
-rw-r--r--drivers/dma-buf/udmabuf.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index c57a609db75b..e7330684d3b8 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -190,6 +190,10 @@ static long udmabuf_create(struct miscdevice *device,
if (ubuf->pagecount > pglimit)
goto err;
}
+
+ if (!ubuf->pagecount)
+ goto err;
+
ubuf->pages = kmalloc_array(ubuf->pagecount, sizeof(*ubuf->pages),
GFP_KERNEL);
if (!ubuf->pages) {