From patchwork Mon Oct 3 08:11:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 12997130 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 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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") Tested-by: Claudiu Beznea --- v2 => 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-sama5d2_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); } +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); static IIO_CONST_ATTR(oversampling_ratio_available, __stringify(AT91_OSR_1SAMPLES) " " @@ -1864,8 +1877,8 @@ static const struct attribute_group at91_adc_attribute_group = { }; static const struct attribute *at91_adc_fifo_attributes[] = { - &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,