From patchwork Mon Jul 20 15:36:15 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: 237545 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp2129315ilg; Mon, 20 Jul 2020 09:27:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxo9Z2MuGXoquq7626aAKbCPMGP3AZETzLHeMaOjimeIPEtKcP5vhSrprCq07B07EOHYOO6 X-Received: by 2002:a17:906:7d86:: with SMTP id v6mr20993551ejo.542.1595262445321; Mon, 20 Jul 2020 09:27:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595262445; cv=none; d=google.com; s=arc-20160816; b=Rifz7pVXuYvb+DTO0wfbHXYkEK3fan5HgIjWNCLBBguI0McpGXWN7NuanooOihf9ux ZrjgktSi32TIHJzuK5OHZ04sblw5q2Z7GXav7WzbcUKT6dOwP4P59fy86J+FlowbWmBY hIxuJMDPVUU6WGvvH7zK3Cdo2Ho2Z9v9CxyvBFq4foYsCdLuuISZMm5ELqC5gjUPIc7d wRevH4cQqtQNfCtfx6imjuf/bdkmE5QfYQ3TCP9B2Ya+NzMM7zZjYwbs80UY8doHTN7N yVg64VDUFrsecLieQy4qpZEevvy7oadjrJ29VFsPX+gfK8rWKA0xxEhv7jZFbItrTadt YC+g== 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=bg1QsSJ+1PnVYtnO+4KbjyPf/NMpr4oRz1r6haFyT7M=; b=KvJjO5paC1VrHC4mfr6SbbKz0dCXlz7/d6wUboCtQPsP4rlWrA2A/DTAVxHPlgRfeC gzJdXen2tYG9WGN5Ui0Px2+zqtPewlRWfAEjHmzyr1VnM+H5ND9LF/KnWD0cYHxBYIWZ eSNXhoJ8+v8wgett4bcHNxnZeE9y48DbYBfTE/SAXDjWPtBzwrDTCAbRf79Of30Oo/Cy Rw56e3VZChTSe8yGPlcIHt6etZrA1c558jc5hwaiAqWMl8L6i4h14mNMGIBMiw87OmH5 caSeQYI/7jPhcFHJLcPJnD5fI4B6m0Y4NKK44gdrSvfNurJB/uDHWL6oKKtwMSV15UQ5 BexQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0L3YDBpt; 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 z1si10758738eju.231.2020.07.20.09.27.25; Mon, 20 Jul 2020 09:27:25 -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=0L3YDBpt; 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 S2387994AbgGTQ1M (ORCPT + 15 others); Mon, 20 Jul 2020 12:27:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:60628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732287AbgGTP7n (ORCPT ); Mon, 20 Jul 2020 11:59:43 -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 7D5F822BEF; Mon, 20 Jul 2020 15:59:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595260783; bh=OrUqV8JJjkoxK8FuCM07uleGXeKVco3gz7e0rfHRBo0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0L3YDBptN8h1RGID9SxAOYrhicAsc9OUFIlqETxLVyvkR/QI+vMYnDl0HpahfxlPW MxmgckBE/Y5jFXVcHJpoQB6HpQS5cofl/MyTIdl5S5qwCxJPKQCwO2uqHAnboP0TRa jwTaIasCMYaZEaybs7CppkGB1xSlSIytXVqIFqbg= 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 5.4 093/215] iio:health:afe4404 Fix timestamp alignment and prevent data leak. Date: Mon, 20 Jul 2020 17:36:15 +0200 Message-Id: <20200720152824.632533390@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 [ 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 e728bbb21ca88..cebb1fd4d0b15 100644 --- a/drivers/iio/health/afe4404.c +++ b/drivers/iio/health/afe4404.c @@ -83,6 +83,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; @@ -91,6 +92,7 @@ struct afe4404_data { struct regulator *regulator; struct iio_trigger *trig; int irq; + s32 buffer[10] __aligned(8); }; enum afe4404_chan_id { @@ -328,17 +330,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);