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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F25E2C4332F for ; Sun, 16 Oct 2022 11:13:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229666AbiJPLNL (ORCPT ); Sun, 16 Oct 2022 07:13:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbiJPLNK (ORCPT ); Sun, 16 Oct 2022 07:13:10 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CA323A150; Sun, 16 Oct 2022 04:13:09 -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 ams.source.kernel.org (Postfix) with ESMTPS id 3A628B80C82; Sun, 16 Oct 2022 11:13:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A00BDC433D6; Sun, 16 Oct 2022 11:13:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665918786; bh=uJ8EoO01+PdQiKTY2XpaRw+EP1zyXWcYZvdwYWh7l74=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=SuDy4NBcUFwjfQntV0fTCRP0gVruzgwg2Zos96EN83fMJZfJgzSa4ZlB8qqCs1LN2 KLJ+Je9rTWhBYfM7YFa7Tcb+Lc3fKgrQZTXqLZ2l8m3/LBBFv0H+VfIIFSeO/R7SDF Uf2LIEfk4GX/cgfUeKd4IIMHL5sLUZXGcXIoZHeWYCqvCCNnKfgwVIlpBoUnLWOMoX qpufN3rKY4RxzgC1mDA4aGMackBjkgI0+TDsOBmrUwZ1qUtBO4iL9uk+pTzThoftJr s3A3KzlWjk5goUVnOA5njUXJkR/V+2cTOxSpsV8dzAMM/rnf7FG5XqSiujQ4UhX8CT pBg0ndOs78Aag== Date: Sun, 16 Oct 2022 12:13:32 +0100 From: Jonathan Cameron To: Matti Vaittinen Cc: Matti Vaittinen , Lars-Peter Clausen , Alexandru Ardelean , Miquel Raynal , Srinivas Pandruvada , Miaoqian Lin , Uwe =?UTF-8?B?S2xlaW5lLUvDtm5pZw==?= , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 03/10] iio: bmc150-accel-core: Fix unsafe buffer attributes Message-ID: <20221016121332.4240fe60@jic23-huawei> In-Reply-To: References: 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On Mon, 3 Oct 2022 11:11:12 +0300 Matti Vaittinen wrote: > 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") 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/bmc150-accel-core.c | 23 ++++++++++++++++++----- > 1 file changed, 18 insertions(+), 5 deletions(-) > > diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c > index 57e8a8350cd1..92f8b139acce 100644 > --- a/drivers/iio/accel/bmc150-accel-core.c > +++ b/drivers/iio/accel/bmc150-accel-core.c > @@ -925,17 +925,30 @@ static const struct iio_chan_spec_ext_info bmc150_accel_ext_info[] = { > { } > }; > > -static IIO_CONST_ATTR(hwfifo_watermark_min, "1"); > -static IIO_CONST_ATTR(hwfifo_watermark_max, > - __stringify(BMC150_ACCEL_FIFO_LENGTH)); > +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(BMC150_ACCEL_FIFO_LENGTH)); > +} > + > +static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0); > +static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0); > static IIO_DEVICE_ATTR(hwfifo_enabled, S_IRUGO, > bmc150_accel_get_fifo_state, NULL, 0); > static IIO_DEVICE_ATTR(hwfifo_watermark, S_IRUGO, > bmc150_accel_get_fifo_watermark, NULL, 0); > > static const struct attribute *bmc150_accel_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,