Received: by 10.223.185.111 with SMTP id b44csp1491170wrg; Sat, 10 Mar 2018 07:05:23 -0800 (PST) X-Google-Smtp-Source: AG47ELskivCjZNYG+PKeQVkoPhwktyXk0xWyOgVydwBgPy/mswHb7xfYGOgx+hd4vb5c5+xnif9S X-Received: by 10.99.175.8 with SMTP id w8mr1837070pge.390.1520694323825; Sat, 10 Mar 2018 07:05:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520694323; cv=none; d=google.com; s=arc-20160816; b=jprqtdtZShmOjLM1ohCc1WfSYBnA1HFajRFpHYUVC7WBcj3B1nrm56QEVKeSXMoFes b39fdmaw0ISfZ7lYoZ21wp4OfRs97BrqjL9yNv9EhXaiA7ATmT4kUQWdNdEVp3uAUGiW zmd2BjvY57KMGy8rDvaugPsaD4U0qIGnEkqCVsGRPFl4ixN3hF6gt+hGibsQjHmw1C3X h4g9mAgvSRJDanX8uq58Mh67LR91bgZFNpTCTks3DND9CBhkbyhzGGIVvWLsIHVTncWa abeRPTrQY9WMrsZ1Fnbj1r/GCIDFvjaoHqE6Tg2fPI7fVAIyteAecxEhlYunul69So3E 07zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dmarc-filter:arc-authentication-results; bh=KcP2IGK5qGn8SWJ2eVGzAK8/y+KIUEVv/zgWL0J0haE=; b=XPj8Mb4TFuOcEOfpaHJqlqRjIcMJct2M5lK1D+wUhcxG0LqibbR96Ui1XLgf4Zx0UH XJhd99oMF3dwy1JWfOfGHttt24rlRrZYG2dwSKk6e74AJ6zJGwI3XqPWyCxw5w/aSEds HMcR1zyvN/HxNYU4uVAPaLXq3FKmIeSkzwrp5BJwHFGFONxlNKKCAYaSbwlbRMI+OMOW A8DHs2AXoI64LU+qCpmlGEFpobh8PJbAfPRCB+ZJWKFXnHUHO5jy9jExMH6z7fL/y400 X4NCjwMkXUdMZV2l3VFTlV0I8y6ayk/zjuX23r9UCCVUay/SB8+WW+rrPL7LiyM8Os8o BIJA== 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 g86si2787165pfk.94.2018.03.10.07.05.09; Sat, 10 Mar 2018 07:05:23 -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; 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 S932231AbeCJPEQ (ORCPT + 99 others); Sat, 10 Mar 2018 10:04:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:56328 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750704AbeCJPEO (ORCPT ); Sat, 10 Mar 2018 10:04:14 -0500 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 92A60208FE; Sat, 10 Mar 2018 15:04:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 92A60208FE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=jic23@kernel.org Date: Sat, 10 Mar 2018 15:04:09 +0000 From: Jonathan Cameron To: Himanshu Jha Cc: Kees Cook , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, LKML , "Gustavo A. R. Silva" Subject: Re: [PATCH] iio: potentiometer: ds1803: Remove VLA usage Message-ID: <20180310150409.1060ab04@archlinux> In-Reply-To: <20180309110510.GB7786@himanshu-Vostro-3559> References: <1520534733-1743-1-git-send-email-himanshujha199640@gmail.com> <20180309110510.GB7786@himanshu-Vostro-3559> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 9 Mar 2018 16:35:10 +0530 Himanshu Jha wrote: > On Thu, Mar 08, 2018 at 11:39:15AM -0800, Kees Cook wrote: > > On Thu, Mar 8, 2018 at 10:45 AM, Himanshu Jha > > wrote: > > > In preparation to enabling -Wvla, remove VLA usage and replace it > > > with fixed a fixed length array and therefore, prevent potential > > > stack overflow attacks. > > > > > > Fixed as a part of the discussion to remove all VLAs from the kernel: > > > https://lkml.org/lkml/2018/3/7/621 > > > > > > Cc: keescook@chromium.org > > > Signed-off-by: Himanshu Jha > > > --- > > > drivers/iio/potentiometer/ds1803.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/drivers/iio/potentiometer/ds1803.c b/drivers/iio/potentiometer/ds1803.c > > > index 9b0ff4a..6bf12c9 100644 > > > --- a/drivers/iio/potentiometer/ds1803.c > > > +++ b/drivers/iio/potentiometer/ds1803.c > > > @@ -64,7 +64,7 @@ static int ds1803_read_raw(struct iio_dev *indio_dev, > > > struct ds1803_data *data = iio_priv(indio_dev); > > > int pot = chan->channel; > > > int ret; > > > - u8 result[indio_dev->num_channels]; > > > + u8 result[ARRAY_SIZE(ds1803_channels)]; > > > > It seems like num_channels is always ARRAY_SIZE(ds1803_channels). > > Could the entire field be dropped? > > If you're asking to remove num_channels then certainly it is not > possible > since it is a member of industrial I/O device struct and it is not just > a member of regular struct local to this file. > > We certainly know that there are only two channels BTW and it can be > tranformed to simply: > > u8 result[2]; > > But then I might have to add an additional comment explaining the magic > number 2. I'm happy with the exact version you proposed. num_channels isn't there for the driver use (as it can obviously know this) but for the core which uses this to know how big the channel array is when creating the sysfs interfaces etc. Applied to the togreg branch of iio.git and pushed out as testing. Thanks, Jonathan >