From patchwork Sat Oct 1 07:43:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 12996428 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 B2179C433F5 for ; Sat, 1 Oct 2022 07:45:14 +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: MIME-Version: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:In-Reply-To: References:List-Owner; bh=Vdpq/nFuqaAa3aND/S5KucDKsrq59Kv0SolSSGe+Jmk=; b=3UW 24tbnCX68DYLVVm47Qtjgvoi72VDvbPwy4j4Q8NFZ3ezTyBjvdOq2MqVy9cHR3q0+rT0G6wzlI7Q5 Q8l2Ee8NV8Q8JtueNMwwTqrRD+WiZqElNH4INVxB9IsADpQkU3i3yd4eGAzBpSLELls4VkjhN8tB/ yQXd7M5OBESEnNt3zoiZmfe6pjZOOAVdPcxP5dH3GlBDk6cf+Lp8V2L3CJcV/uJ7KQ4do96aWwIyK /SokRjmmncLHC/gOqJqqrfwclklXQYhCTJ6HWuiDXxPwyE2jXukkMw3eBkBhZR07Nsue0dKQ1ccLd 0GpsTS8LdmaX2wSlLwHnblXx5tplr6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oeXA0-00Db0l-Ev; Sat, 01 Oct 2022 07:43:44 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oeX9x-00Db06-FG for linux-arm-kernel@lists.infradead.org; Sat, 01 Oct 2022 07:43:42 +0000 Received: by mail-lf1-x12d.google.com with SMTP id z4so10006661lft.2 for ; Sat, 01 Oct 2022 00:43:40 -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=PVIR7v5CNF7swHfa6L+FTkGQK+p+jdFUKLk8O26x5fjEN2PvnuzF49GUiW9tfG1GdO d4/6hkL3snZsNEq51gHuKq9gPcUZ+5gcNl7L8mb3WybdBDi20l72V4gl33s/tObPeGxW 9Tc291fqq/mvl578w+62dl8q9xD4L7pkHfKYYsxdzmE0+JKy1+ZFmqDNIoQ1P9RSmTL8 kokGvY9uUGxa52g6oZgxU53G/GgTyaxyU+EXu+o7nkoAI1o8FT4VPUPx2qjapJQSXN68 5ruahsnHA4H3coIGUkNMkxXyibDsuSew2Ootce3fW7vxzd++HIQeZ3hh9T2hoIxHvvVo SWgQ== X-Gm-Message-State: ACrzQf2CgOKQoSe8+8CNmVafcjMZBy1GONjuy4wHrGEla8NwGYLBwzcP tHOlYMBJR2iAwpOFje5fbSo= X-Google-Smtp-Source: AMsMyM7LLnwhLHuoSKBKosxxQsVKk214LgqJsDBFfNo+oUVQfsZJjUzDwnN/iDcW8jfQiEbWnOC7Dg== 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 Subject: [RFT PATCH v2 0/2] iio: Fix unsafe buffer attributes Message-ID: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221001_004341_535702_43CD2BC0 X-CRM114-Status: GOOD ( 20.45 ) 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 , linux-iio@vger.kernel.org, Srinivas Pandruvada , Gwendal Grignou , Paul Cercueil , Miquel Raynal , Guenter Roeck , chrome-platform@lists.linux.dev, Lars-Peter Clausen , Miaoqian Lin , Uwe =?iso-8859-1?q?Kleine-K=F6nig?= , Alexandru Ardelean , Mihail Chindris , Michael Hennerich , Matti Vaittinen , Cosmin Tanislav , Nathan Chancellor , Benson Leung , linux-arm-kernel@lists.infradead.org, Douglas Anderson , linux-kernel@vger.kernel.org, Eugen Hristev , Claudiu Beznea , Jonathan Cameron Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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