Received: by 10.223.185.116 with SMTP id b49csp73768wrg; Thu, 8 Mar 2018 13:06:53 -0800 (PST) X-Google-Smtp-Source: AG47ELuOQJ04XHfvK2sNWoYFRUK4bu/TSQC7Ff71xzBnnV98pHjpctm48gTLUI17OfMCv65zBYin X-Received: by 10.99.120.201 with SMTP id t192mr22152121pgc.39.1520543213807; Thu, 08 Mar 2018 13:06:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520543213; cv=none; d=google.com; s=arc-20160816; b=p9TwphBCVP9GrL/VKevb6Dnxoyo+PkS0zZH+xUP4HnkdqHBR/kZ0WZBMvjV17Xb48U ORsBmL42X8ITD5MF8ewdF5p92AamqTnbLe8+aZ2WN0QQ/KBd+/Cs/DI2oVMwEn3t/rCw PFgtLLLKcNU+QAi9WPfdJTbNaZu4gA3ox7+6Ko8VPSEFkUV6zqpsaZWmwMow+l17RUbi R7K79lO9w4izWpZKsScUWKjq2Es6gas59Qj2yzxg/zFeSxfnDb0NqR8XMUNDkObEWnhF WyX7gz596uoHBEYH08nxHVG0SWlUxSy1vmNWLhBw6hKea85XV/vaSWRhwF0FWQ9QEmBk bCYA== 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=nkMydW90jqy7Wjaiptus6u2nLIsSiAKrExZvyRn16Vg=; b=b6iDSl+g9STxb5OiTKnDc2vR23y2uH5vvc32cQacg9aeK3xqs2/crX1IoSzTsyt4tz 6yBsIS80JsjW5cYodJ3TQM1zAFmYDeFiVgnWIcwt90DKoBkeleKlAZczu22Rt+f43Sye oc7ucurkQDMkRVIWsoo9FnqGo+ffx7XZ4fduyH9rSVOZYmuAj9PgNWmLVuMA6f8fLtlW k9E14vHImMr3AAIRo5tIFwMGZZfNRsdPDjTWZTp6sENyiHoLV0IWB3VS7lVMeIqWRVGc EcBbDdQScLk1j8mEP+4bL+ayM79ixszXwZFgTuQ5YzwY0b1BXFGlF9S4GMSY1xPKp+zL FpQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=eLD52diV; dkim=fail header.i=@chromium.org header.s=google header.b=dM//aTf8; 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 i5si13591996pgc.521.2018.03.08.13.06.38; Thu, 08 Mar 2018 13:06:53 -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=eLD52diV; dkim=fail header.i=@chromium.org header.s=google header.b=dM//aTf8; 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 S1751237AbeCHVET (ORCPT + 99 others); Thu, 8 Mar 2018 16:04:19 -0500 Received: from mail-vk0-f68.google.com ([209.85.213.68]:34156 "EHLO mail-vk0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751030AbeCHVER (ORCPT ); Thu, 8 Mar 2018 16:04:17 -0500 Received: by mail-vk0-f68.google.com with SMTP id z190so807461vkg.1 for ; Thu, 08 Mar 2018 13:04:17 -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=nkMydW90jqy7Wjaiptus6u2nLIsSiAKrExZvyRn16Vg=; b=eLD52diV7dlgVGB4F4hQ2vS9vgHW01WiiAdfERHdkmlYUbn5OeM3xVFl3fwecPQw01 QGb+aiBODDce2YTxaBAK8VGRntL1+cqtPAmYtiG9ln9gFfQWX/REKmZmgfUHHhzxdq7D /gS61dPxmqrk1ISoGn0oFh9WXBuI2k3FLjhAncK7WDwJ9rlqUOZn++WE4sbVUvYsMmmB aH0JZI1j3nHj44gAowiRaaq0QOhzaCgXp9sRMND18xwKLmXsjmR/f9wc/KcT+bHBddtX 4XPHrsX6dG4GhOnr/iMP8JUxi0XNtIdblZmvHcN+EYPJWVYFSBKnew6OBFzzSJmsJPe5 xbNA== 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=nkMydW90jqy7Wjaiptus6u2nLIsSiAKrExZvyRn16Vg=; b=dM//aTf80jzkLeMvq5r4YQUw3gn4gYn0cKE9fC98uymPDtOmsBTr+X38YEaWZsjXTC EZ7Y6UK8ltVkey/8PSM9ruJEUNZR/bp7xN3edrNLdUc+AUFjNqKbVK2H55+Gi1VWTovt faajAQ62GG2qLu6V83947nZzuk3DYFHI+3FtM= 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=nkMydW90jqy7Wjaiptus6u2nLIsSiAKrExZvyRn16Vg=; b=CoSLNocSOFSgmhB+GcM6/YB8JWZogyxP2oqrfxRzhGgS1nkI38U2RQHPTq7hjdJVbA ExqjCeyIh/4aNn7EP1j0WUpGZL4L3ZV71Aq2Eh+DozBqTY857MmSGr6o8wxgM2mG390S MnEtepl+I+t1Isg4bVwUeSPWs+UV1Y8pb5NsyS7BeDxkcr9fJ58yGRicDrLl2O/Ywc5g jB81X55VdeFRgikj/8g49iW/Q3HCxW9uoDwvYT9QZmiFkHGnBd4S/Yoyv3VL4T8gtzRZ oUMjn2g0Jc/ITo3c1IM8Q0djqm40IDh9vkLUrkR8ADPO13K4GDXApx9jFlNCAmFtO8kD bb3g== X-Gm-Message-State: AElRT7G0pka4+3ivCZ0YKy63SWHsYedG6VHgeQsXY2mk+E/RJQYaLy8D OnoP9Nwi6ZfowhEqlS6QPtuxehJhTOFM5QZFS+KUoA== X-Received: by 10.31.198.131 with SMTP id w125mr14542169vkf.158.1520543056243; Thu, 08 Mar 2018 13:04:16 -0800 (PST) MIME-Version: 1.0 Received: by 10.31.242.140 with HTTP; Thu, 8 Mar 2018 13:04:15 -0800 (PST) In-Reply-To: <20180308205158.5130-1-steve@sk2.org> References: <20180308205158.5130-1-steve@sk2.org> From: Kees Cook Date: Thu, 8 Mar 2018 13:04:15 -0800 X-Google-Sender-Auth: jR81QcLgZUXH7Qj0nOYQSTywHeI Message-ID: Subject: Re: [PATCH v2] 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 12:51 PM, 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. Replace the array > sizes with a pre-processor-level constant instead using ARRAY_SIZE. > > This was prompted by https://lkml.org/lkml/2018/3/7/621 > > Signed-off-by: Stephen Kitt Thanks! Reviewed-by: Kees Cook -Kees > --- > 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 | 3 +-- > 5 files changed, 11 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..fd64a950ee44 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 ARRAY_SIZE(critical_sections) > diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c > index 6612ff3b2e83..e97eceacf522 100644 > --- a/drivers/scsi/aic7xxx/aic7xxx_core.c > +++ b/drivers/scsi/aic7xxx/aic7xxx_core.c > @@ -6848,9 +6848,9 @@ ahc_dumpseq(struct ahc_softc* ahc) > static int > ahc_loadseq(struct ahc_softc *ahc) > { > - 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; > @@ -6915,7 +6915,7 @@ ahc_loadseq(struct ahc_softc *ahc) > * 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/aic7xxx_seq.h_shipped b/drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped > index 07e93fbae706..f37362bc8ece 100644 > --- a/drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped > +++ b/drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped > @@ -1304,5 +1304,4 @@ static const struct cs { > { 875, 877 } > }; > > -static const int num_critical_sections = sizeof(critical_sections) > - / sizeof(*critical_sections); > +#define NUM_CRITICAL_SECTIONS ARRAY_SIZE(critical_sections) > diff --git a/drivers/scsi/aic7xxx/aicasm/aicasm.c b/drivers/scsi/aic7xxx/aicasm/aicasm.c > index 21ac265280bf..5f474e490f3e 100644 > --- a/drivers/scsi/aic7xxx/aicasm/aicasm.c > +++ b/drivers/scsi/aic7xxx/aicasm/aicasm.c > @@ -451,8 +451,7 @@ output_code() > fprintf(ofile, "\n};\n\n"); > > fprintf(ofile, > -"static const int num_critical_sections = sizeof(critical_sections)\n" > -" / sizeof(*critical_sections);\n"); > + "#define NUM_CRITICAL_SECTIONS ARRAY_SIZE(critical_sections)\n"); > > fprintf(stderr, "%s: %d instructions used\n", appname, instrcount); > } > -- > 2.11.0 > -- Kees Cook Pixel Security