Received: by 10.223.185.116 with SMTP id b49csp9913wrg; Thu, 8 Mar 2018 11:59:38 -0800 (PST) X-Google-Smtp-Source: AG47ELs5c/zinRg4A5iEqbNupyE39GSgRQgmZGH2a7DBs+6AwcqXHgLWwAjgBBrpro8zzulr9DFI X-Received: by 2002:a17:902:5a88:: with SMTP id r8-v6mr25894659pli.426.1520539178319; Thu, 08 Mar 2018 11:59:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520539178; cv=none; d=google.com; s=arc-20160816; b=yrXJBuOPjgRUqa5eJRkBhUAufQ6V5+vPW24rQKnqpkPNArk3xjr6SLKkDmPA6bfPjS 5p5vTzhNSLT6cBlNlrZAJ8cJEsJsxmNdAN8kechbulIQYnAVyTCYirv4Zw5go0h0qr0s p3ev+qpBfXox1ehrW1eyT1pnbdYezPKCHVwVYx3yaMUdS+LqAAMk1A6PxbHW3PuKOYRj y+2yJiPN27NX3I+WzFWnCkr2qKjBOo8fNsqlz6B27K3ft4OECdTWc3eQNL2yPnDBF4az qLxGtHf/HrEEJRM8kSauOGHGV12Li8SsFmdnHTIA1POgBwHkKsIS4t6I5ZXfIbmDD3tD C4Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=ObEYIUGJZnqsJGgYrCUN16yurp+9JcGuckyrphW0bMo=; b=aaP0xRv8X8YrygAvFMk61rkG8u2/SMt1v5rkA7ReFKT/27xQtmjU60muf4+YlxZ+yE B41ne8s8riYHLGUq7+JbreALRP+r1zMT5dgzIvRe150thPozCWEw1k5r3o9W8hB/Zwub Ty/z8EgNa6sxoYSLNls5/NcWoJZ/XQXj/nd8gYoofURlUODlhyY1qpI0rpGF3Jxk49y7 gA+Wyvy04TQtIy4dTr+L/HZbu4BOzv/8NyiCFOrcrUgKy2SQXAyhn0IDnVYMa964k2/y rHc+hoH216oHsiaN4j0yiOWuRgNLS3Yy/0oFVV8mbAg5aX0xSEwOp7dXzltDOKM+RSyU DHBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=caSKc9N5; dkim=fail header.i=@chromium.org header.s=google header.b=hSWmOaAh; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l29-v6si15875688pli.25.2018.03.08.11.59.24; Thu, 08 Mar 2018 11:59:38 -0800 (PST) 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; dkim=fail header.i=@google.com header.s=20161025 header.b=caSKc9N5; dkim=fail header.i=@chromium.org header.s=google header.b=hSWmOaAh; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932258AbeCHT56 (ORCPT + 99 others); Thu, 8 Mar 2018 14:57:58 -0500 Received: from mail-ua0-f194.google.com ([209.85.217.194]:46672 "EHLO mail-ua0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752296AbeCHTw2 (ORCPT ); Thu, 8 Mar 2018 14:52:28 -0500 Received: by mail-ua0-f194.google.com with SMTP id d1so651362ual.13 for ; Thu, 08 Mar 2018 11:52:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=ObEYIUGJZnqsJGgYrCUN16yurp+9JcGuckyrphW0bMo=; b=caSKc9N5ux3HPySBOnwmjkvq7hPSbWXxCcvvour/S3dBoEbq3vncImI2qvFqG0oAYD //2XT6cfsw6VUx8PyCw09fV1Aewo95Umy5yrtWWPhUBh678sVo/Bv4A9ToypERGqsDUu uxesJN26niGCjoI5fojF7o7AjVtVNhR+zr2Cgh13KQPb236iLm6IWsaB68b3CYOzQqHs 0jFYGloQszoMPnpA135f/vtZ/rS/PzMmKNik8DQIuEbhZhkWG5A6wHXZ0D4UVuDsmH/5 nDuWE6i3NBuXYFL/r0cXssgbyQXrkMERG2z3ZAdYv6QJ+hrKSheoMKXWaAwDAYxTIQQi aVEA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=ObEYIUGJZnqsJGgYrCUN16yurp+9JcGuckyrphW0bMo=; b=hSWmOaAh61rQplhc+hxKDIZt2rkRrvBvK/tUPitA/E3P0TXUvntxpHz7gcLai2hwNA hUv4xcddr0SC9JFEilyWQj3VgtDF1w6VFrJfMy8IquZDKA/VYMxMjNohgJFj/szR0fQu PZy8u+cKXZjxLmxakexzC6qQREDV0KzyF7Hks= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=ObEYIUGJZnqsJGgYrCUN16yurp+9JcGuckyrphW0bMo=; b=HA7DICFI9oewV9xqTMmJDP/TLQU0dKP8V1ePahjnfNdIuimCkx+UZeWC/sX0EHe6C6 k32GtjMQEOKT9+J20M6x6wbWEL7pipKS9WMOHZEPQhtqTlZeN5YK3KXvHWMsGEF1l1Al LP6AB1jXqXxEU6fjl1ru6AxS1m9a3gisPd+ye3oaR5tm+n/pQ0xnOrKXZNRfdzzvKyWr IiqPOYgmIxs+l7saKBfitP/3RTjnwrEKRzJq23LrPSvn05V/+Wrn+OpVmkCiYG0bKmfJ ce9VxzW68it3EyrCjgL39IBgDYhoiAnFEv9DbvqmshrTqeu6qEIVHyBTQt2P/mGJnVNp geMg== X-Gm-Message-State: APf1xPDavkQQ/XwDuAXiVcP7mxHprL1H2MHNyVPPGSFsypGSTD6+35of DAhdLq/dCE3OlOG6rGjZp58om9dAj4HEv8jJ/qYZOA== X-Received: by 10.159.36.243 with SMTP id 106mr19694286uar.83.1520538746893; Thu, 08 Mar 2018 11:52:26 -0800 (PST) MIME-Version: 1.0 Received: by 10.31.242.140 with HTTP; Thu, 8 Mar 2018 11:52:25 -0800 (PST) In-Reply-To: <20180308132225.13229-1-steve@sk2.org> References: <20180308132225.13229-1-steve@sk2.org> From: Kees Cook Date: Thu, 8 Mar 2018 11:52:25 -0800 X-Google-Sender-Auth: RtijaSJhp2eJFMmhAfykDWGoDBM Message-ID: Subject: Re: [PATCH] aic7xxx/aic79xx: remove VLAs To: Stephen Kitt Cc: hare , linux-scsi@vger.kernel.org, Kernel Hardening , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 8, 2018 at 5:22 AM, Stephen Kitt wrote: > In preparation to enabling -Wvla, remove VLAs and replace them with > fixed-length arrays instead. > > The arrays fixed here, using the number of constant sections, aren't > really VLAs, but they appear so to the compiler. Since we know at > build-time how many critical sections there are, we might as well use > a pre-processor-level constant instead. > > This was prompted by https://lkml.org/lkml/2018/3/7/621 > > Signed-off-by: Stephen Kitt > --- > drivers/scsi/aic7xxx/aic79xx_core.c | 8 ++++---- > drivers/scsi/aic7xxx/aic79xx_seq.h_shipped | 3 +-- > drivers/scsi/aic7xxx/aic7xxx_core.c | 8 ++++---- > drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped | 3 +-- > drivers/scsi/aic7xxx/aicasm/aicasm.c | 6 ++++-- > 5 files changed, 14 insertions(+), 14 deletions(-) > > diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c b/drivers/scsi/aic7xxx/aic79xx_core.c > index b560f396ee99..034f4eebb160 100644 > --- a/drivers/scsi/aic7xxx/aic79xx_core.c > +++ b/drivers/scsi/aic7xxx/aic79xx_core.c > @@ -9338,9 +9338,9 @@ ahd_dumpseq(struct ahd_softc* ahd) > static void > ahd_loadseq(struct ahd_softc *ahd) > { > - struct cs cs_table[num_critical_sections]; > - u_int begin_set[num_critical_sections]; > - u_int end_set[num_critical_sections]; > + struct cs cs_table[NUM_CRITICAL_SECTIONS]; > + u_int begin_set[NUM_CRITICAL_SECTIONS]; > + u_int end_set[NUM_CRITICAL_SECTIONS]; > const struct patch *cur_patch; > u_int cs_count; > u_int cur_cs; > @@ -9456,7 +9456,7 @@ ahd_loadseq(struct ahd_softc *ahd) > * Move through the CS table until we find a CS > * that might apply to this instruction. > */ > - for (; cur_cs < num_critical_sections; cur_cs++) { > + for (; cur_cs < NUM_CRITICAL_SECTIONS; cur_cs++) { > if (critical_sections[cur_cs].end <= i) { > if (begin_set[cs_count] == TRUE > && end_set[cs_count] == FALSE) { > diff --git a/drivers/scsi/aic7xxx/aic79xx_seq.h_shipped b/drivers/scsi/aic7xxx/aic79xx_seq.h_shipped > index 4b51e232392f..20fb9ca9e271 100644 > --- a/drivers/scsi/aic7xxx/aic79xx_seq.h_shipped > +++ b/drivers/scsi/aic7xxx/aic79xx_seq.h_shipped > @@ -1186,5 +1186,4 @@ static const struct cs { > { 759, 763 } > }; > > -static const int num_critical_sections = sizeof(critical_sections) > - / sizeof(*critical_sections); > +#define NUM_CRITICAL_SECTIONS 14 The compiler doesn't treat "const" as a literal, hence the need to change this. However, you can still use the sizeof (actually, this is exactly ARRAY_SIZE()). Perhaps: #define NUM_CRITICAL_SECTIONS ARRAY_SIZE(critical_sections) ? Otherwise, looks great! -Kees -- Kees Cook Pixel Security