From patchwork Wed Mar 12 20:45:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 3821421 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 26C07BF540 for ; Thu, 13 Mar 2014 00:29:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 63177201E4 for ; Thu, 13 Mar 2014 00:29:11 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 85E8220165 for ; Thu, 13 Mar 2014 00:29:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2A922FAD05; Wed, 12 Mar 2014 17:29:08 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com [209.85.212.169]) by gabe.freedesktop.org (Postfix) with ESMTP id 69792FAC61 for ; Wed, 12 Mar 2014 13:44:12 -0700 (PDT) Received: by mail-wi0-f169.google.com with SMTP id hm4so2719816wib.2 for ; Wed, 12 Mar 2014 13:44:10 -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:in-reply-to:references; bh=/bflBJxgn8VUsqcQcxj1hekR0YdDchcSLzxFLmDkXUs=; b=ebL/axAjxDQRSZQwg0CbsxlOProdXW7gQKpJBqOosBFFTsxs26GrhQXiYkiHIcSXcF hDdClrP/MQhmFnG9s23UeDg0tjkUAo6jHGuXfIc0zXgsNBquYJKGYU4zBt2KQEk79LHo dQSb607K1HGVtBzYXiOW6/+Pbaw5Cu0nzBuxbolPi+SBGKwV/1Oh+0bjfunQ7pB4L6ac hCh7GuZWxS1mVZFeP7c7yiNr7z00VurQZxaxjZUs8iARxyqE6hzmnGG+vToVP4nj7Vp9 TvpuxRF4HF+c/+7Shs0VAwZfF2ywj8VkpkBEVOmJX1z/b0qH6qKrVge1r0KchzEVFDws yTNw== X-Received: by 10.180.189.139 with SMTP id gi11mr9318627wic.53.1394657050087; Wed, 12 Mar 2014 13:44:10 -0700 (PDT) Received: from localhost.localdomain (cpc20-stap10-2-0-cust563.12-2.cable.virginm.net. [82.20.130.52]) by mx.google.com with ESMTPSA id f3sm1104689wiv.2.2014.03.12.13.44.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Mar 2014 13:44:08 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/3] nouveau: sanitise NOUVEAU_LIBDRM_*_LIMIT_PERCENT input Date: Wed, 12 Mar 2014 20:45:44 +0000 Message-Id: <1394657145-2638-2-git-send-email-emil.l.velikov@gmail.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1394657145-2638-1-git-send-email-emil.l.velikov@gmail.com> References: <1394657145-2638-1-git-send-email-emil.l.velikov@gmail.com> X-Mailman-Approved-At: Wed, 12 Mar 2014 17:28:51 -0700 Cc: emil.l.velikov@gmail.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org 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 Current handling relies on atoi which does not detect errors additionally, any integer value will be considered as a valid percent. Resolve that by using strtol and limiting the value within the 5-100 (percent) range. Signed-off-by: Emil Velikov --- nouveau/nouveau.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/nouveau/nouveau.c b/nouveau/nouveau.c index d6013db..06cd804 100644 --- a/nouveau/nouveau.c +++ b/nouveau/nouveau.c @@ -76,7 +76,7 @@ nouveau_device_wrap(int fd, int close, struct nouveau_device **pdev) struct nouveau_device *dev = &nvdev->base; uint64_t chipset, vram, gart, bousage; drmVersionPtr ver; - int ret; + int ret, limit; char *tmp; #ifdef DEBUG @@ -121,16 +121,22 @@ nouveau_device_wrap(int fd, int close, struct nouveau_device **pdev) nvdev->close = close; + nvdev->vram_limit_percent = 80; tmp = getenv("NOUVEAU_LIBDRM_VRAM_LIMIT_PERCENT"); - if (tmp) - nvdev->vram_limit_percent = atoi(tmp); - else - nvdev->vram_limit_percent = 80; + if (tmp) { + limit = strtol(tmp, NULL, 10); + if (limit >= 5 && limit <= 100) + nvdev->vram_limit_percent = limit; + } + + nvdev->gart_limit_percent = 80; tmp = getenv("NOUVEAU_LIBDRM_GART_LIMIT_PERCENT"); - if (tmp) - nvdev->gart_limit_percent = atoi(tmp); - else - nvdev->gart_limit_percent = 80; + if (tmp) { + limit = strtol(tmp, NULL, 10); + if (limit >= 5 && limit <= 100) + nvdev->gart_limit_percent = limit; + } + DRMINITLISTHEAD(&nvdev->bo_list); nvdev->base.object.oclass = NOUVEAU_DEVICE_CLASS; nvdev->base.lib_version = 0x01000000;