Received: by 10.213.65.68 with SMTP id h4csp450487imn; Tue, 13 Mar 2018 09:26:09 -0700 (PDT) X-Google-Smtp-Source: AG47ELvvmkNN01gnDfkpzb+9dGaLTMxa6/c1FEHC/BRp+8O84aaaDHwQkF87xeU5ojvol5SDBwz9 X-Received: by 10.98.201.194 with SMTP id l63mr1178838pfk.126.1520958369007; Tue, 13 Mar 2018 09:26:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520958368; cv=none; d=google.com; s=arc-20160816; b=dvEAaWbWaLZset4Bja/DgZVZ/UyowFr3ZGv0I1SpNXEttbRF/I/HY/17eY/thowP41 PkhWrZzex357MUifmy/865Yesft38tqGxEUE3yVI8/VTn2ecAugNzq3NTZN0DMTDmG6p zdvxAe4BgUUfyJ/EyG9F+X4rftI4/4Qyawq1ZsleLhBNTuLI9vPIagToi3ZJ4DLwXCLj hi8qvLKfzssSS6wzUn2KzNx19aPHZi2KsaG8HmCiwCsJ+yeUZ4584qrCJ3o2BIIQwgVY 8q0ZR2YExZrbZIbj4SqzHoD4rKWyyDSNOjFASmL+d3cB8dUm6NywqYsGBPq0GFkFa64u EfHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date :arc-authentication-results; bh=toGK5VHhl/dDtCfJOUpgQKvae323ZgqcAoClYQJnif8=; b=RXOpOVuhNKVghzgjVLSAj5jm0/Ny4tWUr0n9Dgk0EMBRuiVX3Q3oAieK+Kj4sxFuEc 6TVjjUtJTcbC3DZ6TOi4BwBWJxzYzI5oqgxbk7uG57DHhCN/euXpe406AIpCTwmMxpbi rGEnSnrwMtNu0U55Y5O1p1X50dele5sGdSlRr3f+HA+iQXBsGtjK/QHSQjnTymKakwcz MwAUgCHSeC+2HhHZ4W8gBchDq+jm75z1OokIAcg29U8AOrAQ2cB3OIeojSlxS0qiHqmf FdyKWJr1L7t/g72cnKwByU+xVDRFCP/Ic1X5rb+6fIUogoaSlph2cfx/nN/kvd7hgpPS aTxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e127si276855pgc.170.2018.03.13.09.25.54; Tue, 13 Mar 2018 09:26:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933818AbeCMQYP (ORCPT + 99 others); Tue, 13 Mar 2018 12:24:15 -0400 Received: from gateway24.websitewelcome.com ([192.185.51.35]:33902 "EHLO gateway24.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932695AbeCMQYN (ORCPT ); Tue, 13 Mar 2018 12:24:13 -0400 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 9BDFAC739 for ; Tue, 13 Mar 2018 11:24:12 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id vmiie88ihE0sxvmiie7SDz; Tue, 13 Mar 2018 11:24:12 -0500 Received: from [189.175.117.58] (port=57352 helo=embeddedgus) by gator4166.hostgator.com with esmtpa (Exim 4.89_1) (envelope-from ) id 1evmii-002mF9-4E; Tue, 13 Mar 2018 11:24:12 -0500 Date: Tue, 13 Mar 2018 11:24:11 -0500 From: "Gustavo A. R. Silva" To: David Laight , Ben Skeggs , David Airlie Cc: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH v2] drm/nouveau/secboot: remove VLA usage Message-ID: <20180313162411.GA1983@embeddedgus> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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.175.117.58 X-Source-L: No X-Exim-ID: 1evmii-002mF9-4E X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedgus) [189.175.117.58]:57352 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 12 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation to enabling -Wvla, remove VLA. In this particular case directly use macro NVKM_MSGQUEUE_CMDLINE_SIZE instead of local variable cmdline_size. Also, remove cmdline_size as it is not actually useful anymore. The use of stack Variable Length Arrays needs to be avoided, as they can be a vector for stack exhaustion, which can be both a runtime bug or a security flaw. Also, in general, as code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having runtime failures that are hard to debug. Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621 Signed-off-by: Gustavo A. R. Silva --- Changes in v2: - Use sizeof(buf) instead of NVKM_MSGQUEUE_CMDLINE_SIZE. This change is based on the feedback provided by David Laight. Thanks David. drivers/gpu/drm/nouveau/nvkm/subdev/secboot/ls_ucode_msgqueue.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/secboot/ls_ucode_msgqueue.c b/drivers/gpu/drm/nouveau/nvkm/subdev/secboot/ls_ucode_msgqueue.c index 6f10b09..1e1f1c6 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/secboot/ls_ucode_msgqueue.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/secboot/ls_ucode_msgqueue.c @@ -80,12 +80,11 @@ acr_ls_msgqueue_post_run(struct nvkm_msgqueue *queue, struct nvkm_falcon *falcon, u32 addr_args) { struct nvkm_device *device = falcon->owner->device; - u32 cmdline_size = NVKM_MSGQUEUE_CMDLINE_SIZE; - u8 buf[cmdline_size]; + u8 buf[NVKM_MSGQUEUE_CMDLINE_SIZE]; - memset(buf, 0, cmdline_size); + memset(buf, 0, sizeof(buf)); nvkm_msgqueue_write_cmdline(queue, buf); - nvkm_falcon_load_dmem(falcon, buf, addr_args, cmdline_size, 0); + nvkm_falcon_load_dmem(falcon, buf, addr_args, sizeof(buf), 0); /* rearm the queue so it will wait for the init message */ nvkm_msgqueue_reinit(queue); -- 2.7.4