Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2556914rwb; Mon, 3 Oct 2022 02:30:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7aiyKm4B5IA5Ddp81EHA0rDSYMCl4wvGlUOCDBRx3Bu+ws/N5yUgfq/TztIjTC6duAFNl/ X-Received: by 2002:a17:907:5c5:b0:77d:ea1:44c with SMTP id wg5-20020a17090705c500b0077d0ea1044cmr14813816ejb.305.1664789457441; Mon, 03 Oct 2022 02:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664789457; cv=none; d=google.com; s=arc-20160816; b=nnhjeJgQ6shZIKhOjpZwTF37uYsN+0Hxb/UQYbCOJza0hh1u2u7fKZV0UdV0DqYlyw /NHlpc/xeXyfVl9jUGSumi+4ZZcgj/cK9ukZiPfr1ZKUTmx+fZ+IEsnY/q5IJfrMviQY WuF95KwheXyC4ZImTvmEpTBpvQCLhF0+5o4r2z9Rbo8vhBiY9aX5yD6vJnAeNV5/Eusb vDQgFBwcVku/46ukWkZ8Pb97RWeMdaIN/m4JbLxNdoL/KTyN/RkxiLqLIRKHXTQOYnGs 7ycyVvwCmxncl64zcnjZ9CA0qSfemNpHHOtIhWlWeoYarBZPs6bTlHqpfVrRVnuClKmb mrGQ== 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=OsCc64eJJaHmezFY3+fQiaWmA0ACCwHkFNgq4FVgBCc=; b=uaiJAYZGjvjYNO11HPtCirTKSupU9KiVapT59O0aNkAjGg+BreuJP5cBBRbxuncoye Sv2BUr49gJ/aaYpXsiXeMZHjKhf9mtEenu3u4vKqJJPO96HYZbx0zEiJwG3ORHeipB9v 8bZ1LzLecxa3a9IU0ZmYoKQemg02OHkMH+cuPZgdLbPoklsoSOTp2UmAlssuhteh53ir joURF8JFI8d4uTwlAGRfWch0FA6ZznB4k2LvVsoKnh7ZwiurU0TwRMm+XmscAbhZmdte S2PZ/DyABosFP9dj8pyq0HybpOxLvGtwRE1DQRRwnx0cmCx1O4ptdksmNCOkRF8li52s 8u0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="DAre7PP/"; 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 sh8-20020a1709076e8800b0077eb65c41e5si7049297ejc.22.2022.10.03.02.30.32; Mon, 03 Oct 2022 02:30:57 -0700 (PDT) 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="DAre7PP/"; 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 S229582AbiJCIiC (ORCPT + 99 others); Mon, 3 Oct 2022 04:38:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbiJCIhi (ORCPT ); Mon, 3 Oct 2022 04:37:38 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC6C42BB2F; Mon, 3 Oct 2022 01:10:58 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id d26so2642529ljl.2; Mon, 03 Oct 2022 01:10:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=OsCc64eJJaHmezFY3+fQiaWmA0ACCwHkFNgq4FVgBCc=; b=DAre7PP/V/+fUXyIU1cVixP9l/aP21f7MmWrs5BlDuQHOjVYs5zQNQju1G0BKejp17 3yOuaZg3eNGlqkQi5hzyrR2pNWVTcY5LCMz9t67FNlEfhU1Ntx7MEghFUjdFUCML2KZN cqei7DtadFE2fJXq8jk3A7Qcs2wqM3qIxIGs9GjUfOAQNyid660KdXHnR581z9/Q0wXi 1YFn3sS/TUqc0wBXgMCwzWQZkv3hgCmAC+XkXJtb1qD2yVrqFSOL9SVa35EamZcVaQNv z2ba6f21zKcBE3cpXB82msGQ3M5N3quKJQFZCqwye5ZCNGckwMD6efVu1q8kMe6ZcS9S B9sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=OsCc64eJJaHmezFY3+fQiaWmA0ACCwHkFNgq4FVgBCc=; b=6rn/pwXoyidO3tS38H7jd6/ha4+0nQqmfabOj5mJgDQGLzmJYEWgCRTOtwtGvNRwoN Vgewt/53ixc5I03hKw61sEVgVB5VQJCe/v79t+H7nTjTIRM8pNxXvpzI+QgemtfBQN9n 312EG0SsORZxISNw5KWo9h07Fmo6E+2fHsWjylK4BsxG0mgRKB315t6iM3RRwoVSa99q OSrzCreKljLuPvzH5d+UEAdYvRatnCBEa/+QVcAji2mMTNRjD1EOB9qFC0HoxZuMkSL2 ztt6+/+DPC9fDnsCB8HcPuOlUWDOSQdEiDHsbH4000UNwkfpc6iViP1Qzef6ah/PJX2t M56A== X-Gm-Message-State: ACrzQf3Te2kBe9PeLa9F+eT0UVVak7hDyPGLgedi2ptNafUBNa1eQtw8 Te+5NMJSmNA9P++GzrBq+Ag= X-Received: by 2002:a2e:585:0:b0:26d:d39b:19d3 with SMTP id 127-20020a2e0585000000b0026dd39b19d3mr1549181ljf.345.1664784656981; Mon, 03 Oct 2022 01:10:56 -0700 (PDT) Received: from dc75zzyyyyyyyyyyyyyyt-3.rev.dnainternet.fi (dc75zzyyyyyyyyyyyyyyt-3.rev.dnainternet.fi. [2001:14ba:16f3:4a00::1]) by smtp.gmail.com with ESMTPSA id br32-20020a056512402000b0049465afdd38sm1363358lfb.108.2022.10.03.01.10.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 01:10:56 -0700 (PDT) Date: Mon, 3 Oct 2022 11:10:51 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Alexandru Ardelean , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 02/10] iio: adxl372: Fix unsafe buffer attributes Message-ID: <19158499623cdf7f9c5efae1f13c9f1a918ff75f.1664782676.git.mazziesaccount@gmail.com> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="o7EBbn06x8oYoLLd" Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --o7EBbn06x8oYoLLd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable The iio_triggered_buffer_setup_ext() was changed by commit 15097c7a1adc ("iio: buffer: wrap all buffer attributes into iio_dev_= attr") to silently expect that all attributes given in buffer_attrs array are device-attributes. This expectation was not forced by the API - and some drivers did register attributes created by IIO_CONST_ATTR(). The added attribute "wrapping" does not copy the pointer to stored string constant and when the sysfs file is read the kernel will access to invalid location. Change the IIO_CONST_ATTRs from the driver to IIO_DEVICE_ATTR in order to prevent the invalid memory access. Signed-off-by: Matti Vaittinen Fixes: 15097c7a1adc ("iio: buffer: wrap all buffer attributes into iio_dev_= attr") --- v2 =3D> v3: Split change to own patch for simpler fix backporting. --- drivers/iio/accel/adxl372.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c index e3ecbaee61f7..bc53af809d5d 100644 --- a/drivers/iio/accel/adxl372.c +++ b/drivers/iio/accel/adxl372.c @@ -998,17 +998,30 @@ static ssize_t adxl372_get_fifo_watermark(struct devi= ce *dev, return sprintf(buf, "%d\n", st->watermark); } =20 -static IIO_CONST_ATTR(hwfifo_watermark_min, "1"); -static IIO_CONST_ATTR(hwfifo_watermark_max, - __stringify(ADXL372_FIFO_SIZE)); +static ssize_t hwfifo_watermark_min_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%s\n", "1"); +} + +static ssize_t hwfifo_watermark_max_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%s\n", __stringify(ADXL372_FIFO_SIZE)); +} + +static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0); +static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0); static IIO_DEVICE_ATTR(hwfifo_watermark, 0444, adxl372_get_fifo_watermark, NULL, 0); static IIO_DEVICE_ATTR(hwfifo_enabled, 0444, adxl372_get_fifo_enabled, NULL, 0); =20 static const struct attribute *adxl372_fifo_attributes[] =3D { - &iio_const_attr_hwfifo_watermark_min.dev_attr.attr, - &iio_const_attr_hwfifo_watermark_max.dev_attr.attr, + &iio_dev_attr_hwfifo_watermark_min.dev_attr.attr, + &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr, &iio_dev_attr_hwfifo_watermark.dev_attr.attr, &iio_dev_attr_hwfifo_enabled.dev_attr.attr, NULL, --=20 2.37.3 --=20 Matti Vaittinen, Linux device drivers ROHM Semiconductors, Finland SWDC Kiviharjunlenkki 1E 90220 OULU FINLAND ~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~ Simon says - in Latin please. ~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~ Thanks to Simon Glass for the translation =3D]=20 --o7EBbn06x8oYoLLd Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEIx+f8wZb28fLKEhTeFA3/03aocUFAmM6mQsACgkQeFA3/03a ocUJRgf/aJ6es/VTOfcqi0G8LrKzVj0qRcFmr134K5dHlmpuBQJg/0hzYz9otBWP FSwc25jJHZDmZG5KY0jnKPw6iM7zTGMq8BOjj0FVNFpWD92WFr24+Dbav9jyyOr5 1zP2Ix3GKY1M6UxpjYrehoUviXH6XPiEdvYZbDMpjksoalT1Rm++uKzuSZIZmYYS 6L82HoyJkQ9nkLAnKqRHHTrrC9ejxQPaRI+040vVaBzJfqE0H/gT2Vsij79fsbSW DC1bC62Yvn3liv2Tlxlqc+MuHSBjV5l8m30H1rggy8ZMmEk6jic/ff8tto2qdNzG YFtSgXrNUrRuJT+Hch85cVXukAS4iQ== =E+UK -----END PGP SIGNATURE----- --o7EBbn06x8oYoLLd--