From patchwork Mon Jul 20 15:35:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 237546 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp2132021ilg; Mon, 20 Jul 2020 09:30:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5ObPJ9QMjKbHM9yLgDsNwXl4+weETa459GpgtNIb2vmlAy7E76w5YHbbFRlosMzh9fGle X-Received: by 2002:a17:906:2b9b:: with SMTP id m27mr19068661ejg.19.1595262652748; Mon, 20 Jul 2020 09:30:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595262652; cv=none; d=google.com; s=arc-20160816; b=Uu0b5lRVgMchEioHCM6N8Z8dLVKO73PbCGoY4b0H37TdLIMY0Bqy4+9dvECduWLDXa H6W8jU/iNKKVXqD6Ocdpcxol0dv0Y2I0mt2qdMUz5WCgD1rbvUAF7fVlVFKA0nWngAq0 rOQhjT/ZdzkWCNBYVG4qPL5JTVPplfFa+eSKJKBGKsw1uuCT5D4NpEi+UGEK2CMHYwYA VLPQcfA6jL0E6CUCP4divYcfrWM9I6CybWC85Ngzxc0Mu1Y/3V596fllgb4gW2k7Kaom W3Hks6rvxUBr8974OzhZYe3fy2D6ExOSE69IEyxqUA6VBL5s6kxKadcbu1YAKLf1kfbr qzGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=k6U0NZgnQQRIoQRUlqjRi7AMq0FczpcvAqO0hXo/poo=; b=HzMiju7J29/rUnbOa6YxRVkD8m0LpAr8Xr4uTWulORKOUd9yZA/OiVgId3j4k6le/F g69tpAeoJPWpBSoT8fmJ0IhqVx49T8jigPUOUB6sHRuUHQq9a8mL3BZrDz/mgwRtgOBM A/u9YZ9zdekGWg0q2dP1iR1dMC6cXr82GJkSVhyoNUfqM0mOeFjpC9SJ+Lv0qWH4mEkT X3RwFZiHZmmtFHrf7C/zxg0tCavKKNghSYhuRp6UM1SP7xfy2wuQOcRdMgLEeYTYtO5N j8iO8hVx+ITcY0ZoduCV45lAK9r8+CbQemYfWrD0eoTQs5tbwPXGzvNzSTYpR2ZRcL78 tQyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v0hZNpYh; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n7si11026106edv.74.2020.07.20.09.30.49; Mon, 20 Jul 2020 09:30:52 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v0hZNpYh; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731735AbgGTP56 (ORCPT + 15 others); Mon, 20 Jul 2020 11:57:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:58056 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731964AbgGTP55 (ORCPT ); Mon, 20 Jul 2020 11:57:57 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B0D4E2065E; Mon, 20 Jul 2020 15:57:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595260676; bh=IReQaCQ1JzU9pd3WgkQG2WkZwI3+Cf/nWKg9g+Jb9Do=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v0hZNpYhqQKbHIBnF7bS1GvVtsy8xwKWfxXRD6XFgUBO08HPhkRoVAh9O3SEvvXm3 ufeiVW4KWWEHGbAAE4HEqSkrKvmM3NNhgVUbVHXIGSssyU1EfoTg/2pyMXWv0T1aJ3 H8sufYsJwWKDvjTn3mHqvpDv/XsZlpua5vQIX9xo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lars-Peter Clausen , Jonathan Cameron , "Andrew F. Davis" , Stable@vger.kernel.org Subject: [PATCH 5.4 054/215] iio:health:afe4403 Fix timestamp alignment and prevent data leak. Date: Mon, 20 Jul 2020 17:35:36 +0200 Message-Id: <20200720152822.782068169@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200720152820.122442056@linuxfoundation.org> References: <20200720152820.122442056@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jonathan Cameron commit 3f9c6d38797e9903937b007a341dad0c251765d6 upstream. One of a class of bugs pointed out by Lars in a recent review. iio_push_to_buffers_with_timestamp assumes the buffer used is aligned to the size of the timestamp (8 bytes). This is not guaranteed in this driver which uses a 32 byte array of smaller elements on the stack. As Lars also noted this anti pattern can involve a leak of data to userspace and that indeed can happen here. We close both issues by moving to a suitable structure in the iio_priv() data with alignment explicitly requested. This data is allocated with kzalloc so no data can leak appart from previous readings. Fixes: eec96d1e2d31 ("iio: health: Add driver for the TI AFE4403 heart monitor") Reported-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron Acked-by: Andrew F. Davis Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/health/afe4403.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/drivers/iio/health/afe4403.c +++ b/drivers/iio/health/afe4403.c @@ -63,6 +63,7 @@ static const struct reg_field afe4403_re * @regulator: Pointer to the regulator for the IC * @trig: IIO trigger for this device * @irq: ADC_RDY line interrupt number + * @buffer: Used to construct data layout to push into IIO buffer. */ struct afe4403_data { struct device *dev; @@ -72,6 +73,8 @@ struct afe4403_data { struct regulator *regulator; struct iio_trigger *trig; int irq; + /* Ensure suitable alignment for timestamp */ + s32 buffer[8] __aligned(8); }; enum afe4403_chan_id { @@ -309,7 +312,6 @@ static irqreturn_t afe4403_trigger_handl struct iio_dev *indio_dev = pf->indio_dev; struct afe4403_data *afe = iio_priv(indio_dev); int ret, bit, i = 0; - s32 buffer[8]; u8 tx[4] = {AFE440X_CONTROL0, 0x0, 0x0, AFE440X_CONTROL0_READ}; u8 rx[3]; @@ -326,9 +328,9 @@ static irqreturn_t afe4403_trigger_handl if (ret) goto err; - buffer[i++] = (rx[0] << 16) | - (rx[1] << 8) | - (rx[2]); + afe->buffer[i++] = (rx[0] << 16) | + (rx[1] << 8) | + (rx[2]); } /* Disable reading from the device */ @@ -337,7 +339,8 @@ static irqreturn_t afe4403_trigger_handl if (ret) goto err; - iio_push_to_buffers_with_timestamp(indio_dev, buffer, pf->timestamp); + iio_push_to_buffers_with_timestamp(indio_dev, afe->buffer, + pf->timestamp); err: iio_trigger_notify_done(indio_dev->trig);