Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3044920rwi; Sun, 16 Oct 2022 04:25:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4D0B4CuMQaMGI/yfe7u1lFZ1OeNMayJFaPYSOLfr0cdxR+EGSYD4V9OlMGmBLkASGmjLR+ X-Received: by 2002:a17:906:ef8f:b0:78d:fa64:275b with SMTP id ze15-20020a170906ef8f00b0078dfa64275bmr4706999ejb.663.1665919508195; Sun, 16 Oct 2022 04:25:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665919508; cv=none; d=google.com; s=arc-20160816; b=qRCSp7ddmPwyghNLEBTAdC5ymZJBR7Tr7C+V5c81p3uT2BpjdNpRs/2uZ2Qqjte+7F sJCPnCj+KeENzS09/IYMOTyjw8v4b0W6RA0SVo+1PGCFbiX/g8yHlTUNDST08pyK+Tu+ hwFG8uU+QxlS0fHR3fQ6HJBkZSgrdyIUI+Ki0h5kKntTWiAzdlu+wPqSsMOEBQqK5v3L LyQ+h/Y80ZREgTJgY5gmDVEQIjvKWqohYuim404ePY/vdP1W/IfIP2EZIpmt+SJ/NfM1 EIREOrSzrVT0Vm4QPBUfa9866DyJIM+7RPYTvT2urZw3IjK6W1lz/61Yu2Uy0214mjiI hqoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=fX7EUi/GvEhyk2q0fTh+Tbz0mlnxUdONgd+bxivzcsI=; b=QscHEOY7JwMAPYs2tQehjbXnWBlsSXzgvKJ0MYUz9FP6+8SxYThcLc9IMJEOYjukVY aYjOpKmXnHC5NL4K6bGZ7u6eAOz8dztT1JzS+W9r2j7FaSLNlxdOWplUTbSJlu96Nv0N ByBTw6LkgWyLX2kYrvOw/e4jbMjF23PyFcvbN26KkJGcz+Y0dqHXvaGql8gRLdTz0dwx NRW0vi4vcLMtiLbD6el+NhqMUYNQtvtrlOWsrCiC9Wtn94U5X2nXdSySu+4ek+ivomfE 6+Ysx2FE1Gy9sWUcZjeAS5CL5FbptwCHOoY0CyiqrhpIXHEJIWuxLO3vYngl/ugdqFPk 36rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hTTrCsVz; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds1-20020a170907724100b00774d0f10566si7022828ejc.821.2022.10.16.04.24.35; Sun, 16 Oct 2022 04:25:08 -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=@kernel.org header.s=k20201202 header.b=hTTrCsVz; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229661AbiJPLL6 (ORCPT + 99 others); Sun, 16 Oct 2022 07:11:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229594AbiJPLL4 (ORCPT ); Sun, 16 Oct 2022 07:11:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DBD233E23; Sun, 16 Oct 2022 04:11:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 39956609AE; Sun, 16 Oct 2022 11:11:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD39EC433C1; Sun, 16 Oct 2022 11:11:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665918714; bh=haZgvxjEjKaGrnWpf/XakHvzA6ss1pVHMfzXnUyCxsg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=hTTrCsVzPfcijf8ZTSNizDVkrYqa2C04Rbi6ATJbieqribKliILfqN3RMucOdOhaO ydM5U+vtAO8kSwaOP4uZdAYdZ3+N+ml9Uld0MgmFMYAHLqNZacyfhz3MpfmE23Xvdn k1dX6HA2TfTIrlHIXi2C7VCfJ3moYpHL4z4UKTmeuu3Y5m1B8rW9vjVaRuIn6yh4ZY Q/bGS0x7ySRQmptShyADHQmMny0YH1YKCpZOSwweA2pyzoO/22ED5crdb+tFwUy1a4 Pvp0gqUDebq2gZukUU2zh6s8bR7/9jequUSLyERrWrWvzEkqHlUg2wUpwoNjPkKUdg JjsMKCwRPSxNw== Date: Sun, 16 Oct 2022 12:12:19 +0100 From: Jonathan Cameron To: Matti Vaittinen Cc: Matti Vaittinen , Lars-Peter Clausen , Michael Hennerich , Cosmin Tanislav , Alexandru Ardelean , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 01/10] iio: adxl367: Fix unsafe buffer attributes Message-ID: <20221016121219.4114cab2@jic23-huawei> In-Reply-To: <2e2d9ec34fb1df8ab8e2749199822db8cc91d302.1664782676.git.mazziesaccount@gmail.com> References: <2e2d9ec34fb1df8ab8e2749199822db8cc91d302.1664782676.git.mazziesaccount@gmail.com> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 On Mon, 3 Oct 2022 11:10:29 +0300 Matti Vaittinen wrote: > The devm_iio_kfifo_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") Seems like a safe enough change to take without additional review. Hence applied to the fixes-togreg branch of iio.git and marked for stable. Thanks, Jonathan > > --- > > v2 => v3: > Split change to own patch for simpler fix backporting. > --- > drivers/iio/accel/adxl367.c | 23 ++++++++++++++++++----- > 1 file changed, 18 insertions(+), 5 deletions(-) > > diff --git a/drivers/iio/accel/adxl367.c b/drivers/iio/accel/adxl367.c > index 47feb375b70b..7c7d78040793 100644 > --- a/drivers/iio/accel/adxl367.c > +++ b/drivers/iio/accel/adxl367.c > @@ -1185,17 +1185,30 @@ static ssize_t adxl367_get_fifo_watermark(struct device *dev, > return sysfs_emit(buf, "%d\n", fifo_watermark); > } > > -static IIO_CONST_ATTR(hwfifo_watermark_min, "1"); > -static IIO_CONST_ATTR(hwfifo_watermark_max, > - __stringify(ADXL367_FIFO_MAX_WATERMARK)); > +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(ADXL367_FIFO_MAX_WATERMARK)); > +} > + > +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, > adxl367_get_fifo_watermark, NULL, 0); > static IIO_DEVICE_ATTR(hwfifo_enabled, 0444, > adxl367_get_fifo_enabled, NULL, 0); > > static const struct attribute *adxl367_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,