Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3059593rwi; Sun, 16 Oct 2022 04:40:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ZDhfF6nBiM/9NaiX1cIuvC770Kvq7KOVAGw/nF3wLFsogxV+6p2cb04DETShBsMsPejaX X-Received: by 2002:a17:906:8a68:b0:78d:9680:b03 with SMTP id hy8-20020a1709068a6800b0078d96800b03mr4851098ejc.49.1665920442306; Sun, 16 Oct 2022 04:40:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665920442; cv=none; d=google.com; s=arc-20160816; b=aOVuTzjH42s3j3lgDTtFQGz2XH35I2WCsegB6yLhRZA2n7Memnk3ZZ0KvpU6eN0peZ 0JcF3bUcANU6bqK1J9NBo3UtHgOOT723i9oirg7b7rJBB6a52lwhYE5jqyiD6Wz/9zDP 8qXSg8lRTAERKGZZwzuiHN/AkjP8PH+hZpbOG+5TN1gG4134xaJOZdwMiD6VA7aXn1wf V5gAJgZn68yEzzE3UNWr+w4aa6gWVwTfNzy7eFNrIUSKy7QJmG7L5odt9cb9JLjO/2mg +4FEP7jV05w2SnSNS7IVq+/2HIIODr6AKmpLzVjgrbNq4tPXVWqAu2lMfW12SQ1M3s15 O4Cg== 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=ASx+zSnEQiiRYQwVgM+nWaVkQPjOW+h6qMnqGlYC0Nw=; b=A9BTZW/SGqrosp6brqJ1qS1Bp/ul7R/77qES4jT+Ds24gx4paVBOosuTzzAMxSjNmZ zvg5u6U66OI7fcv7AL97RT9U3pNoYQHslwyVnBXxT9KB7ManBr/wO6ufJHf64FpDSoFR 0FnC5QEOX5ZiImUjcNECnVXiKBqfsqrG7dN121yjon9Ms05240/QeeeJWmKKwVu6yXXu xxV2UunVpunmmFHgx573EKtK6lCSxi9ZDYEKUtpZHBhNPHB6H2MJ844+C26pKw9NoDCX S0nLLRQjrqlQTnnx0///vEUhevQrni1dvlRswS98ue61Ijnl8priRRakKdOHrH0t8AuG nhkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SuDy4NBc; 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 gb6-20020a170907960600b0078d25914115si8142732ejc.570.2022.10.16.04.40.16; Sun, 16 Oct 2022 04:40:42 -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=SuDy4NBc; 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 S229722AbiJPLNL (ORCPT + 99 others); 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 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: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,