Skip to content

Commit a67b291

Browse files
pskrgagsmb49
authored andcommitted
udmabuf: validate ubuf->pagecount
BugLink: https://bugs.launchpad.net/bugs/1971497 [ 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]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent d4c4150 commit a67b291

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
@@ -145,6 +145,10 @@ static long udmabuf_create(const struct udmabuf_create_list *head,
145145
if (ubuf->pagecount > pglimit)
146146
goto err;
147147
}
148+
149+
if (!ubuf->pagecount)
150+
goto err;
151+
148152
ubuf->pages = kmalloc_array(ubuf->pagecount, sizeof(*ubuf->pages),
149153
GFP_KERNEL);
150154
if (!ubuf->pages) {

0 commit comments

Comments
 (0)