udmabuf: validate ubuf->pagecount
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().
---
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
@@ -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
Quoted 7 lines · Pavel Skripkin
Syzbot has reported GPF in
sg_alloc_append_table_from_pages(). The problem was inubuf->pages==ZERO_PTR.
ubuf->pagecountis calculated from arguments passed from user-space. If user creates udmabuf with list.size == 0 thenubuf->pagecountwill be also equal to zero; it causeskmalloc_array()to returnZERO_PTR.
Quoted 8 lines
Fix it by validating
ubuf->pagecountbefore passing it tokmalloc_array().Fixes fbb0de795078 ("Add udmabuf misc device")Reported-and-tested-by [email protected]Signed-off-by Pavel Skripkin <[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
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
Quoted 11 lines · Pavel Skripkin
Quoted 10 lines · Pavel Skripkin
Syzbot has reported GPF in
sg_alloc_append_table_from_pages(). The problem was inubuf->pages==ZERO_PTR.
ubuf->pagecountis calculated from arguments passed from user-space. If user creates udmabuf with list.size == 0 thenubuf->pagecountwill be also equal to zero; it causeskmalloc_array()to returnZERO_PTR.Fix it by validating
ubuf->pagecountbefore passing it tokmalloc_array().
Quoted 7 lines
Quoted 5 lines
Fixes fbb0de795078 ("Add udmabuf misc device")Reported-and-tested-by [email protected]Signed-off-by Pavel Skripkin <[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
-0drivers/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
Quoted 7 lines · Pavel Skripkin
Syzbot has reported GPF in
sg_alloc_append_table_from_pages(). The problem was inubuf->pages==ZERO_PTR.
ubuf->pagecountis calculated from arguments passed from user-space. If user creates udmabuf with list.size == 0 thenubuf->pagecountwill be also equal to zero; it causeskmalloc_array()to returnZERO_PTR.
Quoted 7 lines
Fix it by validating
ubuf->pagecountbefore passing it tokmalloc_array().Fixes fbb0de795078 ("Add udmabuf misc device")Reported-and-tested-by [email protected]Signed-off-by Pavel Skripkin <[email protected]>---
Pushed to drm-misc-next.
thanks,
Gerd