Skip to content

Commit 2b6dd60

Browse files
pskrgagkraxel
authored andcommitted
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: fbb0de7 ("Add udmabuf misc device") Reported-and-tested-by: [email protected] Signed-off-by: Pavel Skripkin <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Gerd Hoffmann <[email protected]>
1 parent 2693329 commit 2b6dd60

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/dma-buf/udmabuf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ static long udmabuf_create(struct miscdevice *device,
190190
if (ubuf->pagecount > pglimit)
191191
goto err;
192192
}
193+
194+
if (!ubuf->pagecount)
195+
goto err;
196+
193197
ubuf->pages = kmalloc_array(ubuf->pagecount, sizeof(*ubuf->pages),
194198
GFP_KERNEL);
195199
if (!ubuf->pages) {

0 commit comments

Comments
 (0)