From patchwork Mon Jul 20 15:36:59 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: 237291 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp2095337ilg; Mon, 20 Jul 2020 08:47:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeLMnaDJ5PjLOBI3PtHT26+QNscDUJtkoyCTmWB8U3DChLvxiI6ycc1eE2Df892Tzk0WsH X-Received: by 2002:a17:906:b143:: with SMTP id bt3mr22493480ejb.134.1595260032497; Mon, 20 Jul 2020 08:47:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595260032; cv=none; d=google.com; s=arc-20160816; b=zBJycSzs+JnDjsIy+2wrxSlpiM03S8M3h9DG22AeQrqOHJteBx1g21aHYyHJ/yLNNG v27Jj8gkFNKH7KH5+hnI1wn2lB1XLgk1srDAO6eFab/9QSjjs9blr6eDZTzVmCxU87yO grZwMywDIa4fZvM0ceu80xa24Da5EQYeLpWLcKwckm40hgBJhpoumJK28zTikXhiR6+5 ofvsXYfsJHOg1Eh7XXbPci7XWO4m7aTjP1hZx5+3l2b//HB9G4TSJltJCWgcU7AdKicp PFsTDmsossE7LCcKhj6D+29VVatPkfXS2OQLdICd8dJULhlV2ufum89rKa2Ymrn0mgXH zIbQ== 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=hGo9GqHig13cOHFQE/I/wW8r51252vcwioXKpk9Qa4g=; b=QjRT6G4C67JaBe3h6DuJ2BKiVlHFAJAzCeVXVp3QIwJEmILFyuAaAynx+sxw8mKCDd 3OaSphd7XXjTySrI6yLoujpdfDR5ykToUR/iBFWZuAIg3hcF7sWkU7zvyy3brXJw3YBH IwXlY094JL5J71N/GrSl+W69wgI4Zj4RF2A5M5XnbPSzkFLUjPNgucOuTeSV4HehhDxw HOEB8FpT3DayABK02ug2Vdg3Gz7DYqq/6NAp/kquO4CF4toHY/Burdj1c227cDfv7s9c N823iLFTU4p4R6ptLrbIMDFQAugX33XOy5/cXbnx3ewywOS/HQzQnRPYcmfchqcKGtCf 6R5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="JrOTbe/b"; 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 r22si10811510edq.411.2020.07.20.08.47.12; Mon, 20 Jul 2020 08:47:12 -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="JrOTbe/b"; 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 S1730742AbgGTPrJ (ORCPT + 15 others); Mon, 20 Jul 2020 11:47:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:42166 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730386AbgGTPrI (ORCPT ); Mon, 20 Jul 2020 11:47:08 -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 97655206E9; Mon, 20 Jul 2020 15:47:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595260028; bh=Vk7IagyqnoRmnENC1u/iaiaXIz648HETL5Ky4FZuhwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JrOTbe/bTWtPsCwiqmhBWBtm3r6EvTq31LOF4ClAOUFI6Mx5EH5KbwYxmiLuq+zln ypAZJL1VwKFcIx3T8s0IKHp3iJe1OxkWxAAGat1duffhADxspO9u/qMMwVYxDyXqIx poPFcsASKcACrNifCIzyNeaddLNFX8hgGd09yQ3c= 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.14 080/125] iio:health:afe4404 Fix timestamp alignment and prevent data leak. Date: Mon, 20 Jul 2020 17:36:59 +0200 Message-Id: <20200720152806.883617444@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200720152802.929969555@linuxfoundation.org> References: <20200720152802.929969555@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 964f5231a831c..5e256b11ac877 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 { @@ -337,17 +339,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);