Message ID | 20240223172936.it.875-kees@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-78864-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp736142dyb; Fri, 23 Feb 2024 09:35:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXqeSNdiyhgCxZV/wU9BgO/j+AzmEJsFy5LuB+BKmqkXkH3fbjBJ4NkmDjH6Crpa17ED6LpxZl7h6BeTWkzheYxwvMZKA== X-Google-Smtp-Source: AGHT+IGulw2C/yDzkGWGwdeWtK9LDJmcu+mZWLQdWgYm8xTQt3aITQHTEQn1Xshw5S51yBNHePv8 X-Received: by 2002:a17:903:1111:b0:1dc:7b6:867a with SMTP id n17-20020a170903111100b001dc07b6867amr335570plh.21.1708709754143; Fri, 23 Feb 2024 09:35:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708709754; cv=pass; d=google.com; s=arc-20160816; b=MPMOyLj3M17HXCyS8ChEb01Eu9QJFUyAQr2RoMB7HNys/RA+DsJQoSI6h1FblEf0ek fXwyi5VnD8xVsDWtM7gltbe7SmXWCnI5cohfxBJg4EzHdsJygmu2gSd3g4w20x9SAeeo kKPJJgt7JvJwftQQyEumadKmFYpRQNujUWqrTScbLPtAp6LYu6dhS+1mizaJ8I+1NSlE 31VtQa5KGWkKvUymIKXkQtvqTTgZ8zgSf3zWSw170Ooxiz7xF2ipFe3Y99NngqDyP9qJ QkjK3o9BdcMqG4qo1JAy7z/1BZGEVyHcMXhQjSJ25oYoUvXKCNip0eb1zQJBpswU0epR /lxQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=bM3MPkF58+jFMGrw4OrogBOTmRr+QWSJaSYzjCyKYu4=; fh=U+ZsbfvBbLndEkmZyKCjMWSyHIzzC+DKTuWy6U4Bw/k=; b=T8Vwn7jRcrwZEVAUmPQ1n8LnEgxs1QRYu8wA4faU0MUyFgXY/Eky3Y2dCPmzz4iHM5 iK5+UUGtNIGVu+pVx7DbrZ46aXFU7CeE0mVJ0y5ynI6RSITKflitm4USjSZhgIE/LLcW 47U0qeRyTYg9jHUG5rN4ZFGbu8WNI4S7xb56i89dZCG+eiXPldlow21F5lJIxcuEiuDt XqJzXifhN+BgFzObu/Es6zKpNwan6L7EskbYp10m/kh9VM3wzPVZSNJoZOy+DrKO5Ap9 wti0cVfqDG2pBmcGV2FsobfBVNpXg9zWz+aIID1DD8VNu3k114px7/0MSG8SquQqoEyP XeQA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HxlLyd3w; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-78864-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78864-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b15-20020a170902650f00b001db6043dd97si9262679plk.246.2024.02.23.09.35.54 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 09:35:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78864-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HxlLyd3w; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-78864-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78864-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5356D282706 for <ouuuleilei@gmail.com>; Fri, 23 Feb 2024 17:35:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 73E2E142639; Fri, 23 Feb 2024 17:29:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="HxlLyd3w" Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F5B41420D5 for <linux-kernel@vger.kernel.org>; Fri, 23 Feb 2024 17:29:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708709384; cv=none; b=Tya8PYxpDk2XoWTW9d4ZqivsACsnhjMU1lXhvW+6jd5fzvVqB3D/XKIvw+mjNNQ5fIGQxjAkeQ/sNwlrW4RkFtD/qBDQRcvkt+UO+xQgqWzMxxV30Xg5Bw28IjhjU3kA7JPC2DAD0D5NfzgJGzkOOJCvlU5j8WpdD5YFAU4DtPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708709384; c=relaxed/simple; bh=ZSQMrFcXK67EoYJFvWEtAVXpJz5HlNabiFfB2+DnMz4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=DriPGSi2Otzj/VDsMFlmgs4i88AhNM6J+yez7sUBP4h94GYSH1W+7iD+5aEtuNypuqhg4ohlPVc3CTO2mrxhdIMh9yKPcN7JaZzi+sSphJLydB+Hd4tkoBRKWbzzj1jmFBv99SPxVmpYLqY5dCRquFzpBXqTcj3kxAVUk8JyWrk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=HxlLyd3w; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1dc5d0162bcso9136195ad.0 for <linux-kernel@vger.kernel.org>; Fri, 23 Feb 2024 09:29:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1708709382; x=1709314182; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=bM3MPkF58+jFMGrw4OrogBOTmRr+QWSJaSYzjCyKYu4=; b=HxlLyd3wWp/ZtJmDGIhSVJrTQECsFgCM/77iCE2CRWD2fY2+jeyERBZOXlM8GtInHD deAVVscCHDZSs18oOHyqJVBYOflGvccJf+Zu2PfhXdm9MTT+JSBUU/jAchGUqDqy32rT /MMF1V59vC9RgcIEGFS4LUTz+RPKL+l+nsY+0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708709382; x=1709314182; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bM3MPkF58+jFMGrw4OrogBOTmRr+QWSJaSYzjCyKYu4=; b=pagTSQo8On44jq3udYHCc4D6t8GPoOa1yZ3wurPC93FFXS7SN33FMy/8ZE93FnFnbJ D4IHeRehpPFXoTWRnJeLOyEKoqJc65slZfuTDeL/kg9CQUub8K4sCth9VJ/szrzibKAi SqFSoTGJTpCoFpTRUVZaxnOfWjHQZ2Oftb7hAhRjNXZ2ZYCuYPfzea59iDUG+oQ5kYoL uk8mV1x+Sge0lVe/M1jzlXNzdQjioQ9k4N1ThYrEB8FAEI07d6GEJSl9/DZxKOa0lpNI /kiniMSuTWwz70ItmVMZ425bWZcM2t9OMZENwIniG+P73mVGSazN6Ep5ywVLlrlhS0JX JkWw== X-Forwarded-Encrypted: i=1; AJvYcCU2KnLJptudHv34BuzduatWhWyhR+vm8lIqNJN9hyfBdFKfKiWynTwVK5FkjhvvcX0KEqQ1XbHIB1/B09BfTa9TNXDhI1jQwQEEEMYP X-Gm-Message-State: AOJu0YxhFoo7zz4qLkzRTUsVVCbHY2ZiOdDVWXdphoUGCMTDe1sNBh9B 9lML5XvnoEvMXiNNjC2hAYqAO9UDdzHt58BTrFJ4aJYvlolGmoamHi98lJbP6w== X-Received: by 2002:a17:902:c102:b0:1db:c536:803c with SMTP id 2-20020a170902c10200b001dbc536803cmr435891pli.33.1708709382389; Fri, 23 Feb 2024 09:29:42 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id b2-20020a170902b60200b001db604f41dcsm1778891pls.103.2024.02.23.09.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 09:29:42 -0800 (PST) From: Kees Cook <keescook@chromium.org> To: Jonathan Cameron <jic23@kernel.org> Cc: Kees Cook <keescook@chromium.org>, "Lars-Peter Clausen" <lars@metafoo.de>, =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= <u.kleine-koenig@pengutronix.de>, "Andy Shevchenko" <andriy.shevchenko@linux.intel.com>, =?utf-8?q?Nuno_S?= =?utf-8?q?=C3=A1?= <nuno.sa@analog.com>, linux-iio@vger.kernel.org, "Nathan Chancellor" <nathan@kernel.org>, "Nick Desaulniers" <ndesaulniers@google.com>, "Bill Wendling" <morbo@google.com>, "Justin Stitt" <justinstitt@google.com>, llvm@lists.linux.dev, Tomislav Denis <tomislav.denis@avl.com>, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v2] iio: pressure: dlhl60d: Initialize empty DLH bytes Date: Fri, 23 Feb 2024 09:29:39 -0800 Message-Id: <20240223172936.it.875-kees@kernel.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Developer-Signature: v=1; a=openpgp-sha256; l=1937; i=keescook@chromium.org; h=from:subject:message-id; bh=ZSQMrFcXK67EoYJFvWEtAVXpJz5HlNabiFfB2+DnMz4=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBl2NYDdis920sydQS6ipBI49BtcHYYpvp5bOl50 hx40NdinzyJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZdjWAwAKCRCJcvTf3G3A JnTxD/wM4aMItMA1GlvtME+XbzHXS9RwkeN0sJ2am73tn22dB2vdV/htY/rmnPgBgjy46iuc62k Q3m4V2vmIRR7oin7Dp6MHFYVWNysZUrOrwO8uoINALTCyF30N3JPEUAlk4XA7j+U6DxerZ2IdL2 jERDFaW6E+LGdZ3aQ6NsWuJxVvv1CRf2vcdwt8LL852yhg04L+MVtjejOhyu5dpy2wwFWU1qRGD cclqSl/4dB639iKcUgL3C9V9HKkPNtCYNINpITFMjIQFQzsNWTGonSvc/j3a5qgjb0gOMjlZ3+w cgF0DtlubTNlGX3Cpcq1K1B7qACqsit98xxDp561xm8fxD5LzuBoUfAlUZ3FhMj03iGsyMibDs8 sk2GVwIANvPLWEriBJoqA83QqASX0TUC2BoszwezFgAriD0yMUS1O+j9zvO1SL8sNENlY7hzfIF Uo8fIy0Ey61dvD4BLNIY/5gQINuPOcGnpiw6PUIuUw1YywkubRbxs/Kajkeh2JjzESkcGpHXVO2 zWqeB9B8/TO83C5O/BVx13LUq4OabuCRcOQA3anJYepO7RV5Nm2pUlZkx7gznkJtH68AMU9pmiu F3zxSeRPQ96CxmN+/baatYUN4AR1631D1oJIWyIM9SKfmCwzVUENT+QYOHbx0I0DhV0/52n0wAY wgn4Woo Gjwzea2g== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791712039164180675 X-GMAIL-MSGID: 1791712039164180675 |
Series |
[v2] iio: pressure: dlhl60d: Initialize empty DLH bytes
|
|
Commit Message
Kees Cook
Feb. 23, 2024, 5:29 p.m. UTC
3 bytes were being read but 4 were being written. Explicitly initialize
the unused bytes to 0 and refactor the loop to use direct array
indexing, which appears to silence a Clang false positive warning[1].
Link: https://github.com/ClangBuiltLinux/linux/issues/2000 [1]
Fixes: ac78c6aa4a5d ("iio: pressure: Add driver for DLH pressure sensors")
Signed-off-by: Kees Cook <keescook@chromium.org>
---
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: "Andy Shevchenko" <andriy.shevchenko@linux.intel.com>
Cc: "Nuno Sá" <nuno.sa@analog.com>
Cc: linux-iio@vger.kernel.org
Cc: "Nathan Chancellor" <nathan@kernel.org>
Cc: "Nick Desaulniers" <ndesaulniers@google.com>
Cc: "Bill Wendling" <morbo@google.com>
Cc: "Justin Stitt" <justinstitt@google.com>
Cc: llvm@lists.linux.dev
v2: drop comments, array expansion, and WARN. refactor loop.
v1: https://lore.kernel.org/linux-hardening/20240222222335.work.759-kees@kernel.org/
---
drivers/iio/pressure/dlhl60d.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
Comments
On Fri, Feb 23, 2024 at 09:29:39AM -0800, Kees Cook wrote: > 3 bytes were being read but 4 were being written. Explicitly initialize > the unused bytes to 0 and refactor the loop to use direct array > indexing, which appears to silence a Clang false positive warning[1]. .. > for_each_set_bit(chn, indio_dev->active_scan_mask, > - indio_dev->masklength) { > - memcpy(tmp_buf + i, > + indio_dev->masklength) { > + memcpy(&tmp_buf[i++], > &st->rx_buf[1] + chn * DLH_NUM_DATA_BYTES, > DLH_NUM_DATA_BYTES); > - i++; > } Not that I'm against the changes, but they (in accordance with the commit message) are irrelevant to this fix. I prefer fixes to be more focused on the real issues.
On Fri, Feb 23, 2024 at 07:47:36PM +0200, Andy Shevchenko wrote: > On Fri, Feb 23, 2024 at 09:29:39AM -0800, Kees Cook wrote: > > 3 bytes were being read but 4 were being written. Explicitly initialize > > the unused bytes to 0 and refactor the loop to use direct array > > indexing, which appears to silence a Clang false positive warning[1]. .. > > for_each_set_bit(chn, indio_dev->active_scan_mask, > > - indio_dev->masklength) { > > - memcpy(tmp_buf + i, > > + indio_dev->masklength) { > > + memcpy(&tmp_buf[i++], > > &st->rx_buf[1] + chn * DLH_NUM_DATA_BYTES, > > DLH_NUM_DATA_BYTES); > > - i++; > > } > > Not that I'm against the changes, but they (in accordance with the commit > message) are irrelevant to this fix. I prefer fixes to be more focused on > the real issues. Ah, sorry, there are two changes here: - indentation (which is indeed irrelevant) - and indexing, which seems the needed one. Whatever, Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
On Fri, Feb 23, 2024 at 07:47:36PM +0200, Andy Shevchenko wrote: > On Fri, Feb 23, 2024 at 09:29:39AM -0800, Kees Cook wrote: > > 3 bytes were being read but 4 were being written. Explicitly initialize > > the unused bytes to 0 and refactor the loop to use direct array > > indexing, which appears to silence a Clang false positive warning[1]. > > ... > > > for_each_set_bit(chn, indio_dev->active_scan_mask, > > - indio_dev->masklength) { > > - memcpy(tmp_buf + i, > > + indio_dev->masklength) { > > + memcpy(&tmp_buf[i++], > > &st->rx_buf[1] + chn * DLH_NUM_DATA_BYTES, > > DLH_NUM_DATA_BYTES); > > - i++; > > } > > Not that I'm against the changes, but they (in accordance with the commit > message) are irrelevant to this fix. I prefer fixes to be more focused on > the real issues. Jonathan, let me know if you'd prefer I split this patch...
On Fri, 23 Feb 2024 09:50:10 -0800 Kees Cook <keescook@chromium.org> wrote: > On Fri, Feb 23, 2024 at 07:47:36PM +0200, Andy Shevchenko wrote: > > On Fri, Feb 23, 2024 at 09:29:39AM -0800, Kees Cook wrote: > > > 3 bytes were being read but 4 were being written. Explicitly initialize > > > the unused bytes to 0 and refactor the loop to use direct array > > > indexing, which appears to silence a Clang false positive warning[1]. > > > > ... > > > > > for_each_set_bit(chn, indio_dev->active_scan_mask, > > > - indio_dev->masklength) { > > > - memcpy(tmp_buf + i, > > > + indio_dev->masklength) { > > > + memcpy(&tmp_buf[i++], > > > &st->rx_buf[1] + chn * DLH_NUM_DATA_BYTES, > > > DLH_NUM_DATA_BYTES); > > > - i++; > > > } > > > > Not that I'm against the changes, but they (in accordance with the commit > > message) are irrelevant to this fix. I prefer fixes to be more focused on > > the real issues. > > Jonathan, let me know if you'd prefer I split this patch... > Andy is strictly speaking correct that the indent should be separate patch but meh - not worth the time to split that out + the change makes the fixed code itself easier to read. I added a tiny comment to say it the indent tidying up was incorporated so the fixed code was more readable. Applied to the fixes-togreg branch of iio.git and marked for stable. Given timing this may well go in during the merge window rather than before. Jonathan
diff --git a/drivers/iio/pressure/dlhl60d.c b/drivers/iio/pressure/dlhl60d.c index 28c8269ba65d..0bba4c5a8d40 100644 --- a/drivers/iio/pressure/dlhl60d.c +++ b/drivers/iio/pressure/dlhl60d.c @@ -250,18 +250,17 @@ static irqreturn_t dlh_trigger_handler(int irq, void *private) struct dlh_state *st = iio_priv(indio_dev); int ret; unsigned int chn, i = 0; - __be32 tmp_buf[2]; + __be32 tmp_buf[2] = { }; ret = dlh_start_capture_and_read(st); if (ret) goto out; for_each_set_bit(chn, indio_dev->active_scan_mask, - indio_dev->masklength) { - memcpy(tmp_buf + i, + indio_dev->masklength) { + memcpy(&tmp_buf[i++], &st->rx_buf[1] + chn * DLH_NUM_DATA_BYTES, DLH_NUM_DATA_BYTES); - i++; } iio_push_to_buffers(indio_dev, tmp_buf);