Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d50f851 authored by Pavel Skripkin's avatar Pavel Skripkin Committed by Greg Kroah-Hartman
Browse files

udmabuf: validate ubuf->pagecount



[ Upstream commit 2b6dd600dd72573c23ea180b5b0b2f1813405882 ]

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: fbb0de79 ("Add udmabuf misc device")
Reported-and-tested-by: default avatar <syzbot+2c56b725ec547fa9cb29@syzkaller.appspotmail.com>
Signed-off-by: default avatarPavel Skripkin <paskripkin@gmail.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20211230142649.23022-1-paskripkin@gmail.com


Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 2cf7d537
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -145,6 +145,10 @@ static long udmabuf_create(const struct udmabuf_create_list *head,
		if (ubuf->pagecount > pglimit)
		if (ubuf->pagecount > pglimit)
			goto err;
			goto err;
	}
	}

	if (!ubuf->pagecount)
		goto err;

	ubuf->pages = kmalloc_array(ubuf->pagecount, sizeof(*ubuf->pages),
	ubuf->pages = kmalloc_array(ubuf->pagecount, sizeof(*ubuf->pages),
				    GFP_KERNEL);
				    GFP_KERNEL);
	if (!ubuf->pages) {
	if (!ubuf->pages) {