From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA5D4C433FE for ; Mon, 3 Oct 2022 08:12:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=PkxziH6S3eMdjtqH5Oh/eEcw85Qf0a3OFBnGsqjomn8=; b=VtT3GToSWt3niHlUR1FQfMu7I5 P3Sp5Vy/YiH+iKqwmeTxezH6XuM7ZWNGS7g821N4iQRCmySsShsJUEPwP5Za5IrTBhSGPiStw4R4e 0eTfG+uWIDmGv66CzzX1GYk5Kq/4H8DSq8vq2mBr+OKI5Yg4TpY2BCMIaX8UOM6DMCNEVmup1oWi+ b1b6uHfTYA15K34jt8PYkR07rKFVaTeAniWqcedj/ynWeq5MeXaXhRSsnQgDtqZRxrKbUcdwO731y fS9uMJP9K20Dt4KUb353YlJbMLePa+ENyLlHtScIahlwvjqWjBQYO6qWm1RWEfA/TZvHm9fcaAS9t qob/xRAA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ofGYG-004chs-9o; Mon, 03 Oct 2022 08:11:48 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ofGYD-004cg6-5p for linux-arm-kernel@lists.infradead.org; Mon, 03 Oct 2022 08:11:46 +0000 Received: by mail-lf1-x133.google.com with SMTP id u26so6835203lfk.8 for ; Mon, 03 Oct 2022 01:11:45 -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=n8GMBnHxJxPaGcOLs5PFtLhf/pfq+CS8nFHzOIUU5Qc=; b=jIkamS1RHFlH2SL/8e3NYvEsKWvfGXLkJz78rFGNdC8hRYUVKhxx8dD8+4xPeaXrQF XI8itBO/7GZfhjIEyxV31JX7JnSgykL5xJJepQrw0rzwacAPDBsdPRgiumAf51k2ljpP ce3rP+vUa9U4dxeifNcUMfgkXfisnAaT3M1pnOo33nbv97pYezhCZ35CmEl+enBRrZpD 6V/g+eWIEwpreV1PtkzZ0w9xj3TVOgN9K3fEakbdkvP+LDWXstcFPM44Mb2ZNplHgti1 YB5yq2x92cWT1BHBfS9td/idQnJs3v3vwG2VsCD1W0Epu8SxQMOHir7A+BopGq7dnH2C hAqA== 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=n8GMBnHxJxPaGcOLs5PFtLhf/pfq+CS8nFHzOIUU5Qc=; b=QMb5X4PIzvaSFrAlrJnh8cXmocP4v6SoXc3wYy7W1UFM700fUa1AgwpjFEITFyXRZU HVaenb5sNcCRiOCk3vtNeXsf+XX5bpqVFBRSdNVql8h5rBCLSs4Pli6E93V+7b/e0rxb s2CNNYyVAVHeebDkkZ1/sVhbiFKJ1OKDJSOTbkj0aoFQiqFBfe9teE9wX5ys58iDqs10 RGbXnPddegV/iD7nLuT4ruupGe+iJ5COfd1G3mcKPN9Av3VHm4pbVjOsb1r9MK8ZPZQk qrZzo+jRjEYzSLSK31LcK3WTwZ19uQMkaZUCRVhlGUl+fmBGFe2qdM/JDzc+dEIuYaNc iqcQ== X-Gm-Message-State: ACrzQf010H0YhYP7P3LZbxwlYorgFvIOFH4RduPbnNDcsR6qR4uaBBjz obY4a1oHSLKJhxGUKr9UyYk= X-Google-Smtp-Source: AMsMyM5QgYlSP3Kogs4t3JONKnm6ALa2mDNjMs+sbXfnGYB/A9raY9ov5c0lh2CH1pUt6O2Bmke8Gg== X-Received: by 2002:a05:6512:1392:b0:4a1:e5b8:f9b with SMTP id p18-20020a056512139200b004a1e5b80f9bmr7250781lfa.474.1664784703798; Mon, 03 Oct 2022 01:11:43 -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 b15-20020a056512304f00b00492b494c4e8sm1351128lfb.298.2022.10.03.01.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 01:11:42 -0700 (PDT) Date: Mon, 3 Oct 2022 11:11:33 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Subject: [PATCH v3 04/10] iio: at91-sama5d2_adc: Fix unsafe buffer attributes Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221003_011145_267794_AB65C0F1 X-CRM114-Status: GOOD ( 16.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Lars-Peter Clausen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Eugen Hristev , Alexandru Ardelean , Claudiu Beznea , Jonathan Cameron Content-Type: multipart/mixed; boundary="===============8391670431060266161==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============8391670431060266161== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="bCYLTgg4To/0KZJq" Content-Disposition: inline --bCYLTgg4To/0KZJq 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/adc/at91-sama5d2_adc.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama= 5d2_adc.c index 279430c1d88c..6e3f9fa93cee 100644 --- a/drivers/iio/adc/at91-sama5d2_adc.c +++ b/drivers/iio/adc/at91-sama5d2_adc.c @@ -1841,13 +1841,26 @@ static ssize_t at91_adc_get_watermark(struct device= *dev, return scnprintf(buf, PAGE_SIZE, "%d\n", st->dma_st.watermark); } =20 +static ssize_t hwfifo_watermark_min_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%s\n", "2"); +} + +static ssize_t hwfifo_watermark_max_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%s\n", AT91_HWFIFO_MAX_SIZE_STR); +} + static IIO_DEVICE_ATTR(hwfifo_enabled, 0444, at91_adc_get_fifo_state, NULL, 0); static IIO_DEVICE_ATTR(hwfifo_watermark, 0444, at91_adc_get_watermark, NULL, 0); - -static IIO_CONST_ATTR(hwfifo_watermark_min, "2"); -static IIO_CONST_ATTR(hwfifo_watermark_max, AT91_HWFIFO_MAX_SIZE_STR); +static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0); +static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0); =20 static IIO_CONST_ATTR(oversampling_ratio_available, __stringify(AT91_OSR_1SAMPLES) " " @@ -1864,8 +1877,8 @@ static const struct attribute_group at91_adc_attribut= e_group =3D { }; =20 static const struct attribute *at91_adc_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 --bCYLTgg4To/0KZJq Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEIx+f8wZb28fLKEhTeFA3/03aocUFAmM6mTUACgkQeFA3/03a ocV55Qf/cPENFqybBAKcTd4RDKH/h/Oe427StBd+bRAVNhKC5hGigSl4DXZPJpb4 7asjsDj4TgWKd0u9j3tlkhEVy5UZwWP/FKpAVdZwqdfnbB85xBfjMue8pue6zuRW gwDrup7GMFrAlQYnFKt+znz8JvJeeSx+2rOlYpajr/PwspyglJs40A6/daB9ljB2 ASchwOJ8h6bDtk/H5nqV63oSMPT0uoTJGQNnKos3LFqpyxZDMIlXVcBh9BiQ1gE2 Loj5wJDM1hxAMtx4GX3EJYHWDtMmZ5+aT84QhRXn/Lt1GKuoxECWV4hytSMOaldH 7Kd7h0tfgpFGYs6tzNDNL/WI4TESjg== =rETr -----END PGP SIGNATURE----- --bCYLTgg4To/0KZJq-- --===============8391670431060266161== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============8391670431060266161==--