Skip to contentSkip to conversation

udmabuf: validate ubuf->pagecount

PATCH Applied Pavel Skripkin 3 participants 4 messages Dec 30, 2021 – Jan 18, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 [email protected]

---

Happy New Year and Merry Christmas! :)

With regards,
Pavel Skripkin

---
 drivers/dma-buf/udmabuf.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/dma-buf/udmabuf.c +4 -0
index c57a609db75b..e7330684d3b8 100644
@@ -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) {
Signature · 1 line
2.34.1
#1 lore raw
Quoted 7 lines · Pavel Skripkin

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.

Quoted 8 lines

Fix it by validating ubuf->pagecount before passing it to kmalloc_array().

Fixes fbb0de795078 ("Add udmabuf misc device")
Reported-and-tested-by [email protected]

---

Gentle ping :)

Quoted 10 lines
---
  drivers/dma-buf/udmabuf.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/dma-buf/udmabuf.c +0 -0
index c57a609db75b..e7330684d3b8 100644

drivers/dma-buf/udmabuf.c static long udmabuf_create(struct miscdevice *device, · line 199

Quoted 10 lines
drivers/dma-buf/udmabuf.c +4 -0
@@ -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) {

With regards,
Pavel Skripkin

#2 lore raw
Quoted 11 lines · Pavel Skripkin
Quoted 10 lines · Pavel Skripkin

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().

Quoted 7 lines
Quoted 5 lines
Fixes fbb0de795078 ("Add udmabuf misc device")
Reported-and-tested-by [email protected]

---

Gentle ping :)

Gerd Hoffmann should pick this one up, pls holler again if it doesn't happen.
-Daniel

Quoted 24 lines
Quoted 11 lines

---
  drivers/dma-buf/udmabuf.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/dma-buf/udmabuf.c +0 -0
index c57a609db75b..e7330684d3b8 100644

drivers/dma-buf/udmabuf.c static long udmabuf_create(struct miscdevice *device, · line 199

Quoted 10 lines
drivers/dma-buf/udmabuf.c +4 -0
@@ -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) {

With regards,
Pavel Skripkin

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
maintainer Applied
#3 lore raw
In reply to Pavel Skripkin
Quoted 7 lines · Pavel Skripkin

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.

Quoted 7 lines

Fix it by validating ubuf->pagecount before passing it to kmalloc_array().

Fixes fbb0de795078 ("Add udmabuf misc device")
Reported-and-tested-by [email protected]

---

Pushed to drm-misc-next.

thanks,
Gerd