Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp48228pxk; Tue, 15 Sep 2020 17:24:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxo/l1bDzlMcsetp8xeJlnL19YDfNWmqk5Z5Tq0AqvJvw5aS/3HUIq6mS/e5IHTaio8PK3s X-Received: by 2002:a05:6402:346:: with SMTP id r6mr25645660edw.301.1600215892542; Tue, 15 Sep 2020 17:24:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600215892; cv=none; d=google.com; s=arc-20160816; b=BdJAJg5AMHPHXwj/q1YuTZpuqUVApH02Y5FUgCvl4yuSTVhDCSbIP63gRP7hpoB21e HFBl/g9OFLz4rf8JTE5O4mCYa7+4hMmIzPTQmGAcjbBFSsBGZLN1+cZHN8e+YVB1UJnA wNjr4Gg/z4QPIXDKwjhjSqs9PpNvyD1wZr8KlqIinyZxdaYKVJC52cReRwkhLi9r+H+E DcKGCOTiB0t8LrvC7ollQQ7+NzE2Q7mKCpNe8ykzNYqCQ3VlbHAKNzc7E2mSY4K0VR94 iAT+dLux5Wh24OgR0yGxRZrKkOTKAa0Cpgy8BNRMk/a9Tm0M6JXxhSzwvkdiot9P1VLr XA6Q== 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=829ifijyVPjs8lBKpT522nT03nlP45PU5rs4cADI2L4=; b=HGRFdxq2KYR6o5jUqEaDchwRKdEgMMvJE4ilIobBpM8wTQ5ETa4Xgj9rXPMVV00dvo fj60Cc+syMgYqquOMVbcIyHLFK3sEagVMyoGnYyo+ekN6qsEAK/bLePtAxPgL0oLa0/D plm5kUDxy60hLNAtN+aHCpNPGtczrvgC7uOPrgPfp90MGm5pcg2ixsnqm7y4cEpKAQo3 7tdvcYxvMx+VHzQ/y2tjUn4EHrghS4BdUoQhWiQoo4DJr9Vq+bXr/gMbf9zLsSMbiGuP DocSoK+i1R4hBBBi19sl33p2BftNE1XJnCRUGc5PGtCLThIEtyS813Ld3kYvshFhXotC 97jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CLnqK2sG; 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 r10si10786717ejr.168.2020.09.15.17.24.30; Tue, 15 Sep 2020 17:24:52 -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=CLnqK2sG; 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 S1727239AbgIPAX4 (ORCPT + 99 others); Tue, 15 Sep 2020 20:23:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:60686 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726463AbgIOOU6 (ORCPT ); Tue, 15 Sep 2020 10:20:58 -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 BF27722242; Tue, 15 Sep 2020 14:16:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600179405; bh=zlO04cuBhV3PjPDzXpp2mShiEaTudJ8etpwglLcOXLo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CLnqK2sGoXSidqXWbc+JF90wZLWokOyo1K7q7OhNf5mzSULrlAP8Hn79mlLZW/YBw SeHaF0xGQ/XGgRCTDAiZXifF81TC4ZtR4EXzQSOg80CG29pngsJzyWmo+aCRE7Smu8 lIvx0w5IEOZsNgEOjc1jn9wZduxQhUPVLqG0epuI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lars-Peter Clausen , Jonathan Cameron , Andy Shevchenko , Stable@vger.kernel.org Subject: [PATCH 4.19 47/78] iio:adc:ti-adc081c Fix alignment and data leak issues Date: Tue, 15 Sep 2020 16:13:12 +0200 Message-Id: <20200915140635.936272631@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200915140633.552502750@linuxfoundation.org> References: <20200915140633.552502750@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jonathan Cameron commit 54f82df2ba86e2a8e9cbf4036d192366e3905c89 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(). This data is allocated with kzalloc so no data can leak apart from previous readings. The eplicit alignment of ts is necessary to ensure correct padding on x86_32 where s64 is only aligned to 4 bytes. Fixes: 08e05d1fce5c ("ti-adc081c: Initial triggered buffer support") Reported-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Cc: Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/ti-adc081c.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/drivers/iio/adc/ti-adc081c.c +++ b/drivers/iio/adc/ti-adc081c.c @@ -36,6 +36,12 @@ struct adc081c { /* 8, 10 or 12 */ int bits; + + /* Ensure natural alignment of buffer elements */ + struct { + u16 channel; + s64 ts __aligned(8); + } scan; }; #define REG_CONV_RES 0x00 @@ -131,14 +137,13 @@ static irqreturn_t adc081c_trigger_handl struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct adc081c *data = iio_priv(indio_dev); - u16 buf[8]; /* 2 bytes data + 6 bytes padding + 8 bytes timestamp */ int ret; ret = i2c_smbus_read_word_swapped(data->i2c, REG_CONV_RES); if (ret < 0) goto out; - buf[0] = ret; - iio_push_to_buffers_with_timestamp(indio_dev, buf, + data->scan.channel = ret; + iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, iio_get_time_ns(indio_dev)); out: iio_trigger_notify_done(indio_dev->trig);