From patchwork Sun Aug 24 17:23:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 4770731 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8220E9F377 for ; Sun, 24 Aug 2014 17:23:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BD3BD20127 for ; Sun, 24 Aug 2014 17:23:51 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id F2C5420121 for ; Sun, 24 Aug 2014 17:23:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 63EC889097; Sun, 24 Aug 2014 10:23:49 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-we0-f170.google.com (mail-we0-f170.google.com [74.125.82.170]) by gabe.freedesktop.org (Postfix) with ESMTP id 2147989097 for ; Sun, 24 Aug 2014 10:23:47 -0700 (PDT) Received: by mail-we0-f170.google.com with SMTP id w62so12362681wes.1 for ; Sun, 24 Aug 2014 10:23:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=vrBWLvmaBhjWlVm6Isna0hWIvkMsNA1UdxxyqK9o0e4=; b=VXxKgo3aG2qcw6iik6SCTYU3JnLAJocRjgHmEGKFfBbqNSRVl2sYuS5edY6/bgBhfV 0F96FEOXQ8jMBFzPWxcJD1S/jFDFy1p74kMCLbBT42/5SgJyYvo6+zrAYX+9USlS4G6r fTAaB0KG+vxXVTeRJLFFoO1IGgqgyME3KKcelO+v4/7rXEan2Y7vHxSZxVGQod0jbjmW XszW+hiMYFVfmfiijbczmBvpHh4+ZO4F44pLTfxqlymwEsg1Z1bnRUgpbF14Pbk5SMZa vUV/odaTSSXZzeXw2kCEvkkDIxlqF6ZX1vqdszoAoWA9enkcygRD0/5k/HS1mxWIkBWo FGBQ== X-Received: by 10.194.172.137 with SMTP id bc9mr17903110wjc.72.1408901027043; Sun, 24 Aug 2014 10:23:47 -0700 (PDT) Received: from david-tp.localdomain (stgt-4d024433.pool.mediaWays.net. [77.2.68.51]) by mx.google.com with ESMTPSA id ex2sm93097080wjd.30.2014.08.24.10.23.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 24 Aug 2014 10:23:46 -0700 (PDT) From: David Herrmann To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm: fix division-by-zero on dumb_create() Date: Sun, 24 Aug 2014 19:23:26 +0200 Message-Id: <1408901006-3751-1-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.1.0 Cc: Daniel Vetter X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Kinda unexpected, but DIV_ROUND_UP() can overflow if passed an argument bigger than UINT_MAX - DIVISOR. Fix this by testing for "!cpp" before using it in the following division. Note that DIV_ROUND_UP() is defined as: #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) ..this will obviously overflow if (n + d - 1) is bigger than UINT_MAX. Reported-by: Tommi Rantala Signed-off-by: David Herrmann Reviewed-by: Rob Clark --- drivers/gpu/drm/drm_crtc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index fe94cc1..55057f7 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -4397,7 +4397,7 @@ int drm_mode_create_dumb_ioctl(struct drm_device *dev, /* overflow checks for 32bit size calculations */ cpp = DIV_ROUND_UP(args->bpp, 8); - if (cpp > 0xffffffffU / args->width) + if (!cpp || cpp > 0xffffffffU / args->width) return -EINVAL; stride = cpp * args->width; if (args->height > 0xffffffffU / stride)