From patchwork Tue Sep 4 19:07:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 10587841 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1421F14BD for ; Tue, 4 Sep 2018 19:32:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 044BE2A044 for ; Tue, 4 Sep 2018 19:32:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA3202A046; Tue, 4 Sep 2018 19:32:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78AE929E36 for ; Tue, 4 Sep 2018 19:32:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727768AbeIDX64 (ORCPT ); Tue, 4 Sep 2018 19:58:56 -0400 Received: from gateway20.websitewelcome.com ([192.185.50.28]:34374 "EHLO gateway20.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726437AbeIDX64 (ORCPT ); Tue, 4 Sep 2018 19:58:56 -0400 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 3C38C400C7A01 for ; Tue, 4 Sep 2018 14:07:51 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id xGg3fNrceRPojxGg3fmiKH; Tue, 04 Sep 2018 14:07:51 -0500 X-Authority-Reason: nr=8 Received: from [189.250.106.191] (port=49818 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1fxGg2-0015Ok-KE; Tue, 04 Sep 2018 14:07:50 -0500 Date: Tue, 4 Sep 2018 14:07:49 -0500 From: "Gustavo A. R. Silva" To: Gerd Hoffmann , Sumit Semwal Cc: linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] dma-buf/udmabuf: Fix NULL pointer dereference in udmabuf_create Message-ID: <20180904190749.GA9308@embeddedor.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.106.191 X-Source-L: No X-Exim-ID: 1fxGg2-0015Ok-KE X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.106.191]:49818 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 3 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/dma-buf/udmabuf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 8e24204..2e85022 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -194,7 +194,8 @@ static long udmabuf_create(struct udmabuf_create_list *head, while (pgbuf > 0) put_page(ubuf->pages[--pgbuf]); err_free_ubuf: - fput(memfd); + if (memfd) + fput(memfd); kfree(ubuf->pages); kfree(ubuf); return ret;