Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5409857pxb; Mon, 7 Feb 2022 01:05:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjkwlhuyObK2JzSF0LhHqbh/tpdAar6jHaVREDGAWHXsFOIcOm8dg35fEHNOhHc4PVUGv4 X-Received: by 2002:a17:903:18c:: with SMTP id z12mr15257410plg.119.1644224703100; Mon, 07 Feb 2022 01:05:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644224703; cv=none; d=google.com; s=arc-20160816; b=xRQY5T5Fmc2Q3Y3sTyhRcfOTAX5+LBXI2dbIUTRWu64BJghF03jO7wPT86ppLLoIOS 66pGnj2vDnGLOH2ysJcet+hLcBAHSwNwxAhYMMnbNLO0T9LGS+ZVBWpOmwqTlR7YO3xU myOBFTO8GzWNXtj0FqxMTEmJkyiWboFKhT6B6Aue3xQb0gUxlB9xXPNot5Q5Soo+O6dC DYf5C1Z2k+Ly4x8rwCNL1K9GZcyQ6cLyFlYqzFOS838UlZzgVWx4ARrqerY+uYz6rij7 uahR/SwB0tNNC7PlEotoiTVaYU/sfZ+s8TPfOTmn4uvqt+tGAaOBK6f/1PAm+pnGfBCK 76Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wNFwjW4PYcifd9RezG6AJwf0bLCg9aSqyt07d3zX9jU=; b=NKzDVMekASPpgi+EkaGKo7/1VAX7Mzy5gvrxwhEpFMhxWI7OiakCpD/uOeoauwm4IR Eg0+P4nCNsYZNKRCSf74EDvnrP3IU6wePRUwcwYibrTjFsyKcKVnXUeZuFSnabAJAdkU VvS0rQfmsYhTFyF1auhWgSMP4QDjoO5JgqoUvP10753uizkgKlL/pFYY5d3WzKEVSo8g BFTcblsyC0Tg7PKbyAkEfjEeMDG0eCCFt9jpVg1GQHMwvoq8avXRhEy3DFCSaR0IA9t7 ZPjHKtIMDW3XFvI3oTBPHjSKG7Xxq2/9PHStyqmapfXZNfQRGabL8jPe1eOnIPrkAR9F X3mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=A1bh1iNc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kb1si10434880pjb.60.2022.02.07.01.04.51; Mon, 07 Feb 2022 01:05:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=A1bh1iNc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356935AbiBDE3n (ORCPT + 99 others); Thu, 3 Feb 2022 23:29:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233571AbiBDE3m (ORCPT ); Thu, 3 Feb 2022 23:29:42 -0500 Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42B16C061714; Thu, 3 Feb 2022 20:29:42 -0800 (PST) Received: by mail-il1-x136.google.com with SMTP id z7so3881193ilb.6; Thu, 03 Feb 2022 20:29:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=wNFwjW4PYcifd9RezG6AJwf0bLCg9aSqyt07d3zX9jU=; b=A1bh1iNcaCgez+6i8g3ApzO/lcs1iqFtK+bb28hHm1PubPk8Xff+pshB7YqMSSQ07V kzE1uGH6FPhjXt0UhfWmLyOl+LW03GQ2jFA+JEGZI+WxDopjc0PPJ1rm1XYgtyr9iNbE U17xDXckyZcyme4qKTLCUrI/c9Ptu5W9dHegB2oM6VUH8WS5Yx2sBrSKLiHCEeVUJWW6 FRQWrE1w+wqGtY9cKCH0r6qo/9YE4FXO9xgWG58jsMg89vIbLa5+Oik+WG+Gk4hVwmL1 ePjpm9zU3D8nnAbfRB1B6SnGnNNOSi43iat3hLxNoGDh7QgsLxhemT1ILFYLCwDG1OyB Yeaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=wNFwjW4PYcifd9RezG6AJwf0bLCg9aSqyt07d3zX9jU=; b=noe8uyqwxTnea8iB3b8tbSrjqLIIEdzrU3l8Cax8RNRM4xHzuNCy2piHcwn//6wLvO gH8OMegGl96/zGdFYZiHx27/umfmYRmtr3ylaq1xirtXcCuS7wiV5MnYpeCnl6XeZfaM L9zxCN1tOVAshSX3KBPkPbuno4VXftmKqHGdB7ZxjwmlH1s1wgKNWvxd9KbcqLrqraqA MfP1l9yhGQnmgDHRzM/d9IjEcaSkP+QZoFYo0T0EJ2HLgXFC9v8yiWVXN0LQKi4E6aMM TxUCKRL54b4bI88CkSaQOLzcvcBsdBP9gMLqd/Ve6SZ75h6J8PNXyivi+F/eHLX3EMAD sWUg== X-Gm-Message-State: AOAM53186loxz1jSHm43Q/qN7CDmIxQny7s9vGdMdLXkDWBGoMGdpsy3 3XE+gBGFdM5peMRBKdmPHSamnMMzrR0= X-Received: by 2002:a92:680b:: with SMTP id d11mr588761ilc.74.1643948981266; Thu, 03 Feb 2022 20:29:41 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id m1sm459683ilu.87.2022.02.03.20.29.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 20:29:40 -0800 (PST) Date: Thu, 3 Feb 2022 20:29:38 -0800 From: Yury Norov To: Kees Cook Cc: Jonathan Cameron , Lars-Peter Clausen , Maxime Coquelin , Alexandre Torgue , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] iio: stmpe-adc: Use correctly sized arguments for bit field Message-ID: References: <20211215232513.2070158-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211215232513.2070158-1-keescook@chromium.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 15, 2021 at 03:25:13PM -0800, Kees Cook wrote: > The find.h APIs are designed to be used only on unsigned long arguments. > This can technically result in a over-read, but it is harmless in this > case. Regardless, fix it to avoid the warning seen under -Warray-bounds, > which we'd like to enable globally: > > In file included from ./include/linux/bitmap.h:9, > from ./include/linux/cpumask.h:12, > from ./arch/x86/include/asm/cpumask.h:5, > from ./arch/x86/include/asm/msr.h:11, > from ./arch/x86/include/asm/processor.h:22, > from ./arch/x86/include/asm/cpufeature.h:5, > from ./arch/x86/include/asm/thread_info.h:53, > from ./include/linux/thread_info.h:60, > from ./arch/x86/include/asm/preempt.h:7, > from ./include/linux/preempt.h:78, > from ./include/linux/spinlock.h:55, > from ./include/linux/swait.h:7, > from ./include/linux/completion.h:12, > from drivers/iio/adc/stmpe-adc.c:10: > drivers/iio/adc/stmpe-adc.c: In function 'stmpe_adc_probe': > ./include/linux/find.h:98:23: warning: array subscript 'long unsigned int[0]' is partly outside array bounds of 'u32[1]' {aka 'unsigned int[1]'} [-Warray-bounds] > 98 | val = *addr | ~GENMASK(size - 1, offset); > | ^~~~~ > drivers/iio/adc/stmpe-adc.c:258:13: note: while referencing 'norequest_mask' > 258 | u32 norequest_mask = 0; > | ^~~~~~~~~~~~~~ > > Signed-off-by: Kees Cook > --- > drivers/iio/adc/stmpe-adc.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/iio/adc/stmpe-adc.c b/drivers/iio/adc/stmpe-adc.c > index fba659bfdb40..d2d405388499 100644 > --- a/drivers/iio/adc/stmpe-adc.c > +++ b/drivers/iio/adc/stmpe-adc.c > @@ -256,6 +256,7 @@ static int stmpe_adc_probe(struct platform_device *pdev) > struct stmpe_adc *info; > struct device_node *np; > u32 norequest_mask = 0; > + unsigned long bits; > int irq_temp, irq_adc; > int num_chan = 0; > int i = 0; > @@ -309,8 +310,8 @@ static int stmpe_adc_probe(struct platform_device *pdev) > > of_property_read_u32(np, "st,norequest-mask", &norequest_mask); > > - for_each_clear_bit(i, (unsigned long *) &norequest_mask, > - (STMPE_ADC_LAST_NR + 1)) { > + bits = norequest_mask; This would not work on 64-bit BE architecture. It should use bitmap_from_arr32() > + for_each_clear_bit(i, &bits, (STMPE_ADC_LAST_NR + 1)) { > stmpe_adc_voltage_chan(&info->stmpe_adc_iio_channels[num_chan], i); > num_chan++; > } > -- > 2.30.2