From patchwork Wed Apr 11 01:03:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 10334691 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 D53846053C for ; Wed, 11 Apr 2018 01:03:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D20C226253 for ; Wed, 11 Apr 2018 01:03:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6E40285DB; Wed, 11 Apr 2018 01:03:47 +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=-5.2 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 898B326253 for ; Wed, 11 Apr 2018 01:03:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7063D6E0C4; Wed, 11 Apr 2018 01:03:46 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3AC376E0C4 for ; Wed, 11 Apr 2018 01:03:45 +0000 (UTC) Received: by mail-pf0-f195.google.com with SMTP id f15so142810pfn.0 for ; Tue, 10 Apr 2018 18:03:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=a8jzB+4333HGsfDCv6oyqqZ3vgyNG2rzXgC5UtxijMM=; b=MCLY0niVXgBIsKg+Lj5yMjdcC48CxU8bu0GCv25IeVAg77WrXhzoWSHDtOtbz+Dwl1 5QrDf2wBhA19xcyS29AWmA76tpcDk8ZVmjzPA4GJeUjQvqZICm8m0CzMEhC5m94E7IPq 4gJHaI7x9/ft5jmxgsy2f92a0qoZPbfjoBrCoSjzdiR0IruUvwuzsXJ/EdWGFsejUGUH gutbYpJXwqlUlJnT/p57Ixq5q8R3WTdQ/m6R06mvNfxFB4Zx8ID/4/ulMqBUcwKR0pUw YaIzQkQortjgSTYlzY2J/WK48CLFeAxRFzxfbtqbEVr9cOosbJ/AFJc/ziNhuNkUaaH6 pjIA== X-Gm-Message-State: ALQs6tAlbRWgpbaKdpLIyJsUC05zv7l8WRvc0DZgUbE8G6S8cD1gNSwy FDqFC0bpseIVKXO6PdAFgIuctA== X-Google-Smtp-Source: AIpwx48WhLw2FpOAvebqJX4yBI0fI7FA8xg5pAJgXs3DV0EiNMwBQC4CALicNHkF5ulmGCOr8y8s2w== X-Received: by 10.98.174.5 with SMTP id q5mr2134917pff.155.1523408624731; Tue, 10 Apr 2018 18:03:44 -0700 (PDT) Received: from labbott-redhat.redhat.com ([2601:602:9802:a8dc:4eb2:6dae:ab32:e5b0]) by smtp.gmail.com with ESMTPSA id t25sm6525340pfh.184.2018.04.10.18.03.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Apr 2018 18:03:43 -0700 (PDT) From: Laura Abbott To: Russell King , David Airlie Subject: [PATCHv2] drm/i2c: tda998x: Remove VLA usage Date: Tue, 10 Apr 2018 18:03:30 -0700 Message-Id: <20180411010330.17866-1-labbott@redhat.com> X-Mailer: git-send-email 2.14.3 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kees Cook , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, kernel-hardening@lists.openwall.com MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP There's an ongoing effort to remove VLAs[1] from the kernel to eventually turn on -Wvla. The vla in reg_write_range is based on the length of data passed. The one use of a non-constant size for this range is bounded by the size buffer passed to hdmi_infoframe_pack which is a fixed size. Switch to this upper bound. [1] https://lkml.org/lkml/2018/3/7/621 Signed-off-by: Laura Abbott Reviewed-by: Kees Cook --- v2: Switch to make the buffer size more transparent and add a bounds check. --- drivers/gpu/drm/i2c/tda998x_drv.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i2c/tda998x_drv.c b/drivers/gpu/drm/i2c/tda998x_drv.c index 9e67a7b4e3a4..c8b6029b7839 100644 --- a/drivers/gpu/drm/i2c/tda998x_drv.c +++ b/drivers/gpu/drm/i2c/tda998x_drv.c @@ -466,13 +466,22 @@ reg_read_range(struct tda998x_priv *priv, u16 reg, char *buf, int cnt) return ret; } +#define MAX_WRITE_RANGE_BUF 32 + static void reg_write_range(struct tda998x_priv *priv, u16 reg, u8 *p, int cnt) { struct i2c_client *client = priv->hdmi; - u8 buf[cnt+1]; + /* This is the maximum size of the buffer passed in */ + u8 buf[MAX_WRITE_RANGE_BUF + 1]; int ret; + if (cnt > MAX_WRITE_RANGE_BUF) { + dev_err(&client->dev, "Fixed write buffer too small (%d)\n", + MAX_WRITE_RANGE_BUF); + return; + } + buf[0] = REG2ADDR(reg); memcpy(&buf[1], p, cnt); @@ -679,7 +688,7 @@ static void tda998x_write_if(struct tda998x_priv *priv, u8 bit, u16 addr, union hdmi_infoframe *frame) { - u8 buf[32]; + u8 buf[MAX_WRITE_RANGE_BUF]; ssize_t len; len = hdmi_infoframe_pack(frame, buf, sizeof(buf));