Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3285763pxk; Mon, 21 Sep 2020 09:42:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmGUuuqzrBfIDT4yvfOkZWAG72o+Ax5Xj+5THPGoVd7Df62M/sXIzniT9ply+0MVIQCPBr X-Received: by 2002:aa7:cc8d:: with SMTP id p13mr584220edt.136.1600706533374; Mon, 21 Sep 2020 09:42:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600706533; cv=none; d=google.com; s=arc-20160816; b=j3ThVaP/j0wNqiBuwWJ/j9bXOt1JxCD/IxBXrVQgjlr9zAtY7XKY0G/yCuBamRRzze R8pqkmKJIxBS9dezq8hj13JYkxDXTfuSXZIzs7FZAaZcp6U3qEQPz45NtokeTMWq55/V E1Dc+WGQ1pzygaYQiKsMVRjpeyWaSJHOBqGuBQlqeUz96W2pxfMRqZI8LQT8P1rSvK9c napzRFpxC17IJeBCIFelBTsYsexvPUKF6eXfeTeWqe24lCTiTp+vzT5BGEZaZaKySQCV 8/Wsax+W5cJX7/7DNQbG7areypn+Ecx7pgqjU01ifjsd9LdtwYzYxgjR/GnTgnUW/2VE JxFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gC0XO+G3p7LCGyARB24n5+jyBkIDpKsFzX4qI5O9tMg=; b=gLOWtTQbcjxQBG33olbGCZ5Kzb98iolB0435x3zq761fqPlxx4lUFdTrWpQakK/qT3 oUGXcWG8Xqza7PAwOiGNRDVmhLaEvnrIo+US0m8QObArWQvMmK3HOhKHyC9EzycNOfpQ gRW3EWxHRBg3sdDJ1Te9nwx8nwpQxxfvMtbrG+TjOE5YdufKnCw8woDQC8E3cugMFIDJ OQix+8KFoKj7tF6HNY8wl6AtXwQsfTtDiHHMjipYoFkeWLNBJkpsxm9/BetoTx9w3Pg/ sBTbqva+rEhF71TRqjPiQ0N4x7pikbIog20FAOyBnvekfChb7DUDzq8GIdyJ31xDG/uH lYyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mpzWo6Uz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd3si8835117ejb.499.2020.09.21.09.41.49; Mon, 21 Sep 2020 09:42:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=mpzWo6Uz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729109AbgIUQhv (ORCPT + 99 others); Mon, 21 Sep 2020 12:37:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:38304 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729098AbgIUQhl (ORCPT ); Mon, 21 Sep 2020 12:37:41 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 4C8C3206DC; Mon, 21 Sep 2020 16:37:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706260; bh=nLG5hz/X1zlrm0O9qtbq0AnEnLFtbPiptbdPee2Suyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mpzWo6Uz0x/3YvNAdbrdAV4ZJZGEhk0NkiDkXy2OriwQ0OmZKm29EtOXdXpqWrRbm Syi/kU33Dvit0jhRTXsT6d2JBKgRcTcZ//QLP9hK1rX32QkRB+x+qn/Tfz2FoqfQUD 3UYJEU3zcK9TtDzzSkir7GLk/kNhS7eM9yQakVLM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lars-Peter Clausen , Akinobu Mita , Jonathan Cameron , Andy Shevchenko , Stable@vger.kernel.org Subject: [PATCH 4.14 30/94] iio:adc:max1118 Fix alignment of timestamp and data leak issues Date: Mon, 21 Sep 2020 18:27:17 +0200 Message-Id: <20200921162036.941209076@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162035.541285330@linuxfoundation.org> References: <20200921162035.541285330@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jonathan Cameron commit db8f06d97ec284dc018e2e4890d2e5035fde8630 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 an 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. This data is allocated with kzalloc so no data can leak apart from previous readings. The explicit alignment of ts is necessary to ensure correct padding on architectures where s64 is only 4 bytes aligned such as x86_32. Fixes: a9e9c7153e96 ("iio: adc: add max1117/max1118/max1119 ADC driver") Reported-by: Lars-Peter Clausen Cc: Akinobu Mita Signed-off-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Cc: Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/max1118.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/drivers/iio/adc/max1118.c +++ b/drivers/iio/adc/max1118.c @@ -38,6 +38,11 @@ struct max1118 { struct spi_device *spi; struct mutex lock; struct regulator *reg; + /* Ensure natural alignment of buffer elements */ + struct { + u8 channels[2]; + s64 ts __aligned(8); + } scan; u8 data ____cacheline_aligned; }; @@ -163,7 +168,6 @@ static irqreturn_t max1118_trigger_handl struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct max1118 *adc = iio_priv(indio_dev); - u8 data[16] = { }; /* 2x 8-bit ADC data + padding + 8 bytes timestamp */ int scan_index; int i = 0; @@ -181,10 +185,10 @@ static irqreturn_t max1118_trigger_handl goto out; } - data[i] = ret; + adc->scan.channels[i] = ret; i++; } - iio_push_to_buffers_with_timestamp(indio_dev, data, + iio_push_to_buffers_with_timestamp(indio_dev, &adc->scan, iio_get_time_ns(indio_dev)); out: mutex_unlock(&adc->lock);