Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp385798rwb; Sat, 1 Oct 2022 01:10:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6bPZyrlaeaayLVcEOK6mhRe+OJfYu3evC+2OBdPV0u+0Xh3Z3RbsWriwfixIqR3VDoRVlY X-Received: by 2002:aa7:c78e:0:b0:456:c524:90ec with SMTP id n14-20020aa7c78e000000b00456c52490ecmr10715624eds.192.1664611803831; Sat, 01 Oct 2022 01:10:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664611803; cv=none; d=google.com; s=arc-20160816; b=L2ZgjlZErqrb5DA/4+HVVjURX3uPjyNY5by/Ce2h/m+0gg2w4TuvAZfSErJ3LhTdbP 0EbtU88E7dxTBGsb6RjEM/86h3UHLewKyuVOGv4vw7CBcDprCwr9bIJUMJ76Y580Anh4 8bN2yu5p0I7FCsOLzZ3ru0wvp5NI/13gRzpJ1EFGMZpRlk7uRnjf62L5d3kb2x70wuPp KLMSs8g51ObSsHsJoKkOhzRQJFlYdeDhauJ2aotVubhT8Rj6WuVRUOP3Mm+LHeiNd4i5 tqghOKzcKo+R84qI6K5Sx52PZw5VgzHVdtywvwC23YW1tipYauidBXx4rc6Vebi/zzU/ Hl3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=b0K8YxHzOLYyHo4VvKo91+kAJ3r6DDnk5+tjHXHmZ/8=; b=NcKPKzTcdwvxe/hwyUIPmWNByevbnIc0Xt28dlbEgWvq0p2te6VUWiI+8DbUpsBYYP +69x+j04xkJ1IAU0838JtZvwnI9MQmt5K/iBq6nv8WCl/JBlS+mM6xbDnaSocWs3BSc5 YzCcxlBLf2iq2slWTC4IFCGJWJ9OkeLeawPU/7Me4sh6aJyR4gLfY5w+N1SF48dK9lRU UrKqxz+84NFoiF89yXxakuXNei/nfu9Yf2a0X5H60MrOLldgUE2axSl+6Ce2OS9XpG5K hwJE39hLHOLZFajErO3qHmebFIq8nsXn796nIO7Agy3I4BaVBim299Dxg0vRImgKvoUf Deeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=NVhTLj2C; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l14-20020a170906794e00b00741a16e8562si3551027ejo.826.2022.10.01.01.09.24; Sat, 01 Oct 2022 01:10:03 -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=@gmail.com header.s=20210112 header.b=NVhTLj2C; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229586AbiJAHnn (ORCPT + 99 others); Sat, 1 Oct 2022 03:43:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiJAHnl (ORCPT ); Sat, 1 Oct 2022 03:43:41 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4531515515F; Sat, 1 Oct 2022 00:43:39 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id z4so10006660lft.2; Sat, 01 Oct 2022 00:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date; bh=b0K8YxHzOLYyHo4VvKo91+kAJ3r6DDnk5+tjHXHmZ/8=; b=NVhTLj2CYnWllRTa3+jXekeih3wEZs7pTk+FVo4Chn9pNtfsLiUwlS/qpr+ZclpvGb NNpaPXGQNeK5eIpWnL+j/SGwDbmtzRGOwYIBfA0RAXZn7Kydz3H/AH0bS5PKgRajjCJf mKvtqzuQIQ1y1aWApYz9TDMUOLY3HcWz1a2FJgaQBTj/ZPqpA85WKsSi40ph0WBJ3+EY fpx1b76cZvoJLIH1hMcj3FK32k/wt5OcwQkAYoKePZEsRdNxUPyE/Cu3xrx6K3Z1rTYq Oiw2jcIhsAZ+CYPXTHew2JFZ6Edj7V9ipof7D8XnCWJqXtY5UmzjsvrwWTA1x4S0/k52 nZhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=b0K8YxHzOLYyHo4VvKo91+kAJ3r6DDnk5+tjHXHmZ/8=; b=UoGVANUE8JkyatFo8lhrWK4Q7E6fKTWaw0TUBXsAzk9wUM8JLAohDNyNO1h65yw/jf 8UOe9CTr3Grc1VYDLiBOXkk5BhkzApD9r0Bh8YQoTwVT1JBU72JwibucLi5PL4Ivcofa TmU9MlefOT2wbwcI25xkqWTMSP1zamMp/T9gAfajAIkj3n6rbRDomcfLf/F3djIrLxvh Xz0XqU7Qbr136+Y3aSqAVLzzrsM6FO0G8LZzcHGCiQ+OIvzp4anB6n+eIrNKuf8CfC4l /3XPxWlzy2ciWtbLiusB/gwgwABftCiqI9bIdrW0b1vakkXJXJ4F06XMIkYOcRwWnpzU CUyw== X-Gm-Message-State: ACrzQf0cebY9hkrrxn3mBumkg4PSrtyR4C8bso9E/K7TE69NzudeBUfM Q2JmmBrvaLqWZwSsmyX0OQo= X-Received: by 2002:a05:6512:2392:b0:4a0:3180:5c40 with SMTP id c18-20020a056512239200b004a031805c40mr4228494lfv.681.1664610217445; Sat, 01 Oct 2022 00:43:37 -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 f1-20020a05651232c100b00497ad9ae486sm668561lfg.62.2022.10.01.00.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 00:43:36 -0700 (PDT) Date: Sat, 1 Oct 2022 10:43:18 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Cosmin Tanislav , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Eugen Hristev , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Benson Leung , Guenter Roeck , Alexandru Ardelean , Srinivas Pandruvada , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Nathan Chancellor , Miquel Raynal , Matti Vaittinen , Miaoqian Lin , Paul Cercueil , Mihail Chindris , Gwendal Grignou , Douglas Anderson , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, chrome-platform@lists.linux.dev Subject: [RFT PATCH v2 0/2] iio: Fix unsafe buffer attributes Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="p/1ifXIpa00LMeD9" Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 --p/1ifXIpa00LMeD9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable IIO The iio_triggered_buffer_setup_ext() has been changed to expect that all attributes given in buffer_attrs array are device-attributes. This expectation has not been forced by the API and not all existing users were checked. Some drivers do 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 address. This series aims to address both the drivers using IIO_CONST_ATTR() and the API. Use of IIO_CONST_ATTR() has been dropped from drivers for the triggered buffers and the iio_triggered_buffer_setup_ext() is changed to take an array of pointers to struct iio_dev_attr instead of an array of pointers to struct attribute. This should fix the existing users and also prevent similar problem to occur in the future. I am not super happy about the new macro IIO_STATIC_CONST_DEVICE_ATTR() which unconditionally creates a static function and a static struct iio_dev_attr. OTOH, I do believe static function + static struct iio_dev_attr should be the right thing to do for majority of use cases. I did also change the struct iio_buffer to have array of pointers to iio_dev_attr in order to avoid yet another copying in side the iio_triggered_buffer_setup_ext(). This change appeared to be somewhat intrusive - and as I lack the hardware to do thorough testing I added the request for testing tag here. Especially testing of adi-axi-adc would be highly appreciated as it is using the industrialio-buffer-dmaengine. Changelog v2: - fix also the cros_ec_sensors_core.c - fix also the industrialio-buffer-dmaengine.c - add RFT + this cover-letter. -- Matti Vaittinen (2): iio: Add IIO_STATIC_CONST_DEVICE_ATTR iio: Fix unsafe buffer attributes drivers/iio/accel/adxl367.c | 16 ++++++++-------- drivers/iio/accel/adxl372.c | 16 ++++++++-------- drivers/iio/accel/bmc150-accel-core.c | 18 +++++++++--------- drivers/iio/adc/at91-sama5d2_adc.c | 16 ++++++++-------- .../iio/buffer/industrialio-buffer-dmaengine.c | 4 ++-- .../iio/buffer/industrialio-triggered-buffer.c | 4 ++-- drivers/iio/buffer/kfifo_buf.c | 2 +- .../cros_ec_sensors/cros_ec_sensors_core.c | 6 +++--- .../common/hid-sensors/hid-sensor-trigger.c | 8 ++++---- drivers/iio/industrialio-buffer.c | 11 +++++++---- include/linux/iio/buffer_impl.h | 2 +- include/linux/iio/kfifo_buf.h | 3 ++- include/linux/iio/sysfs.h | 11 +++++++++++ include/linux/iio/triggered_buffer.h | 6 +++--- 14 files changed, 69 insertions(+), 54 deletions(-) base-commit: f76349cf41451c5c42a99f18a9163377e4b364ff --=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 --p/1ifXIpa00LMeD9 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEIx+f8wZb28fLKEhTeFA3/03aocUFAmM374kACgkQeFA3/03a ocVTHQgAzUVSblClKdgM1OzHi45hngdIJh1Zg2mq6PgBWQn/XWc+6s5e3OYK3yS0 XliPnOk0vcf/vuyTiUdN/vhfJpnVab3jLRkPFSGfg9KwOGz8PPWvi8OafRSIRhgA prid6wavAeZV9Zpg4F6jvYWW56fkK/2vF5wyQI1bfYf13XJD7qJG73WKv/Xj/L4p D+LleNNcd0ntDjigScC61IoZMvQ7g/jTYsXd7LR0MudKc4eUM9ia6coznNDXumuh CuJGjVewJbb2Wu6Aybv+gW8WPrZG0c/ctaX5F5e0mISlZ1FnRiKBlYv/dVEONdOT xD6KakdrOYTf2Vors49vmIhO/+RIow== =qM0L -----END PGP SIGNATURE----- --p/1ifXIpa00LMeD9--