From: Gustavo A. R. Silva Date: Tue, 4 Sep 2018 19:07:49 +0000 (-0500) Subject: dma-buf/udmabuf: Fix NULL pointer dereference in udmabuf_create X-Git-Tag: v4.20-rc1~21^2~33^2~12 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=683a0e630cb463d18e9c158496270dc918cf5437;p=linux-2.6-block.git dma-buf/udmabuf: Fix NULL pointer dereference in udmabuf_create There is a potential execution path in which pointer memfd is NULL when passed as argument to fput(), hence there is a NULL pointer dereference in fput(). Fix this by null checking *memfd* before calling fput(). Addresses-Coverity-ID: 1473174 ("Explicit null dereferenced") Fixes: fbb0de795078 ("Add udmabuf misc device") Signed-off-by: Gustavo A. R. Silva Link: http://patchwork.freedesktop.org/patch/msgid/20180904190749.GA9308@embeddedor.com Signed-off-by: Gerd Hoffmann --- diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 8e24204526cc..2e8502250afe 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -194,7 +194,8 @@ err_put_pages: while (pgbuf > 0) put_page(ubuf->pages[--pgbuf]); err_free_ubuf: - fput(memfd); + if (memfd) + fput(memfd); kfree(ubuf->pages); kfree(ubuf); return ret;