From patchwork Mon Jul 20 15:36:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 237314 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp2099167ilg; Mon, 20 Jul 2020 08:51:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3knw438xu8D9bUMZc5XEl00HFB1kGkAkEqwXptMv2rD6MBCC+zAVfhMot8tzrBW/KNOmy X-Received: by 2002:a17:906:cc13:: with SMTP id ml19mr21003786ejb.288.1595260319183; Mon, 20 Jul 2020 08:51:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595260319; cv=none; d=google.com; s=arc-20160816; b=UoNEXkGhB0ttRzGOeyHpcwACOj+ti/yLaTGEd8Z/7hcKV4UVp/1vjuHlZD4my1tcHE Ggc6INbsjMC7VMennsdxI/FImUN9pY0W+P4BniluDcdtxeA6WoQ451xW8Qm30Ie/Ullt XgiR+lQJI09q4FL2em65+rbZwhXzQ6mtNkdxQ/prE5lIGUdMJyF1BTpHSvTUjgDwomWu F81aPBVWN7dXSmd6e0HRseO3QmH3gm90fBmYCv/PTHXDsKWzJ9hxN+hOnwRvwvxM7Act RBVBBw2mg8tht7X9S9R4WlxOnYZwnYNHHFEwG9YVi1CWnxaLp2+HDXFXzSPFqqzqkcSc IXOQ== 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=flTiEZMqUeJ/sZ1LVgPAWXgYm0ABDekDzA3PMVsTgbc=; b=zjuUxHCzKcndzHRpkIIpm+8y7NVla/JGy4voA32aTqOzuoFONu6H2mH0DHA+wZjsV0 2uAZiHDQ03/Ey4jIyksHLifVIkc25FMF02Kb1vXSe1MwWh1VA0LVSJIuB5XFrhqsHphO yMZ54SB4c5Hzu6nrPGkvGLhBS6N/5ZBjuBHsJYWuN5ePBvTCxx8npxiWm1efgRGv61xc oTw0WkQ2KNbPGwRBj0FfD6bVYJ8/Y0mR81KBMlJMKnfP++jP5JYpLY3bchvu+KtDGN+H 3QrPV/MqNykGd450o1yYrwLW+3CRlRBaAKRS5h+4nk5uAZRtbAKKvR2IEEVVH2zDwb1/ JlZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lmX8lAGV; 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 f12si10234025ejq.334.2020.07.20.08.51.58; Mon, 20 Jul 2020 08:51:59 -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=lmX8lAGV; 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 S1731285AbgGTPv6 (ORCPT + 15 others); Mon, 20 Jul 2020 11:51:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:49130 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730999AbgGTPv5 (ORCPT ); Mon, 20 Jul 2020 11:51: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 EF0EF2065E; Mon, 20 Jul 2020 15:51:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595260316; bh=4hKcacuzSJxqP6yYZUginvZpXGohejSQrLJwU190vW4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lmX8lAGVUttjKBJhxfbr78/aW3eGFuBCYh1JndhQvDRtSGNVxwLFVPw1xoCXUpgDH O7ucC0g3/bEB2kPh24zjXiDdyarWN4bgbUL0lo22vJMA8g2DdZSg3aWGb929rMN92d iuiVAvIW21Td5S8hUj4/GPCzrn4HTbhkl1tp/+Sg= 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" , Sasha Levin Subject: [PATCH 4.19 058/133] iio:health:afe4404 Fix timestamp alignment and prevent data leak. Date: Mon, 20 Jul 2020 17:36:45 +0200 Message-Id: <20200720152806.530074469@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200720152803.732195882@linuxfoundation.org> References: <20200720152803.732195882@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 [ Upstream commit f88ecccac4be348bbcc6d056bdbc622a8955c04d ] 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 40 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: 87aec56e27ef ("iio: health: Add driver for the TI AFE4404 heart monitor") Reported-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron Acked-by: Andrew F. Davis Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- drivers/iio/health/afe4404.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) -- 2.25.1 diff --git a/drivers/iio/health/afe4404.c b/drivers/iio/health/afe4404.c index 11910922e6556..23e1ac6501a1a 100644 --- a/drivers/iio/health/afe4404.c +++ b/drivers/iio/health/afe4404.c @@ -91,6 +91,7 @@ static const struct reg_field afe4404_reg_fields[] = { * @regulator: Pointer to the regulator for the IC * @trig: IIO trigger for this device * @irq: ADC_RDY line interrupt number + * @buffer: Used to construct a scan to push to the iio buffer. */ struct afe4404_data { struct device *dev; @@ -99,6 +100,7 @@ struct afe4404_data { struct regulator *regulator; struct iio_trigger *trig; int irq; + s32 buffer[10] __aligned(8); }; enum afe4404_chan_id { @@ -336,17 +338,17 @@ static irqreturn_t afe4404_trigger_handler(int irq, void *private) struct iio_dev *indio_dev = pf->indio_dev; struct afe4404_data *afe = iio_priv(indio_dev); int ret, bit, i = 0; - s32 buffer[10]; for_each_set_bit(bit, indio_dev->active_scan_mask, indio_dev->masklength) { ret = regmap_read(afe->regmap, afe4404_channel_values[bit], - &buffer[i++]); + &afe->buffer[i++]); 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);