Skip to content

Commit b267a81

Browse files
pskrgaggregkh
authored andcommitted
udmabuf: validate ubuf->pagecount
[ Upstream commit 2b6dd60 ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 56722aa commit b267a81

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
@@ -181,6 +181,10 @@ static long udmabuf_create(struct miscdevice *device,
181181
if (ubuf->pagecount > pglimit)
182182
goto err;
183183
}
184+
185+
if (!ubuf->pagecount)
186+
goto err;
187+
184188
ubuf->pages = kmalloc_array(ubuf->pagecount, sizeof(*ubuf->pages),
185189
GFP_KERNEL);
186190
if (!ubuf->pages) {

0 commit comments

Comments
 (0)