From patchwork Tue May 23 06:39:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeffy Chen X-Patchwork-Id: 9741977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2EE1D6034C for ; Tue, 23 May 2017 06:40:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2055728786 for ; Tue, 23 May 2017 06:40:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 151592879F; Tue, 23 May 2017 06:40:34 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CD41128786 for ; Tue, 23 May 2017 06:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=hQq5GqxZO2GXd5x7jhlDR0eLro1fpSxBA25spWEVhZc=; b=J2Q bH0RsaF8yJi0RyTi1k6RWEb5TivRUMBoi7ovNQrmQJNd2uSUIAef28je/t/JTnD+spKkl6XtnHx/n t4e4g8DKuwijbsLMYR3RNbozpXHBqLe28Sf8lS8ZuJMZs7eybV9k5NZAjpCNpp2OOm+19fsdjGRy7 8LjDIBtK+5qIXBNBwcw+eXkRnrPGfIgKY4aXiuzcq0XSiAFYTSsTx7pXeWRECvn4+yhOdDiVE6RDn qLNC0qzxxhkhaswa+eY+hEyEutDcJgWuwkfbWd+VZ2nIBWXi/ByS380y3gGlb5784frAqC4QQQSo3 aTjD+QUQLdSlSVFKpmGrDXl8xEMC1hQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dD3Ue-0007VL-Mp; Tue, 23 May 2017 06:40:32 +0000 Received: from regular1.263xmail.com ([211.150.99.135]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dD3US-00066x-T1; Tue, 23 May 2017 06:40:22 +0000 Received: from jeffy.chen?rock-chips.com (unknown [192.168.167.152]) by regular1.263xmail.com (Postfix) with ESMTP id 60E331E1E5; Tue, 23 May 2017 14:39:52 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTP id 16782393; Tue, 23 May 2017 14:39:48 +0800 (CST) X-RL-SENDER: jeffy.chen@rock-chips.com X-FST-TO: linux-kernel@vger.kernel.org X-SENDER-IP: 103.29.142.67 X-LOGIN-NAME: jeffy.chen@rock-chips.com X-UNIQUE-TAG: <0bae9100edcc0038593b05c82201e63c> X-ATTACHMENT-NUM: 0 X-SENDER: cjf@rock-chips.com X-DNS-TYPE: 0 Received: from localhost (unknown [103.29.142.67]) by smtp.263.net (Postfix) whith ESMTP id 10072UC4OJH; Tue, 23 May 2017 14:39:52 +0800 (CST) From: Jeffy Chen To: linux-kernel@vger.kernel.org Subject: [PATCH] drm/rockchip: Don't allow zero sized gem buffer Date: Tue, 23 May 2017 14:39:43 +0800 Message-Id: <1495521583-29151-1-git-send-email-jeffy.chen@rock-chips.com> X-Mailer: git-send-email 2.1.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170522_234021_125018_BC896E83 X-CRM114-Status: UNSURE ( 6.04 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , David Airlie , Jeffy Chen , dri-devel@lists.freedesktop.org, tfiga@chromium.org, linux-rockchip@lists.infradead.org, seanpaul@chromium.org, linux-arm-kernel@lists.infradead.org, Mark Yao MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The system would crash when trying to alloc zero sized gem buffer: [ 6.712435] Unable to handle kernel NULL pointer dereference at virtual address 00000010 <--ZERO_SIZE_PTR ... [ 6.757502] PC is at sg_alloc_table_from_pages+0x170/0x1ec Signed-off-by: Jeffy Chen --- drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c index df9e570..8917922 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c @@ -315,6 +315,11 @@ struct rockchip_gem_object * struct drm_gem_object *obj; int ret; + if (!size) { + DRM_ERROR("gem buffer size is zero\n"); + return ERR_PTR(-EINVAL); + } + size = round_up(size, PAGE_SIZE); rk_obj = kzalloc(sizeof(*rk_obj), GFP_KERNEL);