Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3284515pxk; Mon, 21 Sep 2020 09:40:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7ggazztKyqptv9nNkXsoxqXsr9iqtPYM5o5R9AkX4nzY+mR+HPsQJDaenHTC0Gfxnu2sb X-Received: by 2002:aa7:c987:: with SMTP id c7mr484727edt.385.1600706414748; Mon, 21 Sep 2020 09:40:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600706414; cv=none; d=google.com; s=arc-20160816; b=lTqlCXyEUFkl66aQJVhdrOhbjfSL4t6CNE0loLbFDu/TrSbTwZtXCE5RfMw2WVckDE fhiA3W1hJkNi1QceVUmIMOw35GrZv1o3jr0wvmaoUGXeghJ+AvF/+YWRV+C7wBbl+/bO ccGspvoF45pJWya+Noi5YmZ/G7wuJAESaWpvWSU2KswAnEgvh5JnmXiT7a34cgbUTnYN di3lbvSHf9VSSQD26pzwRzzGkDWUkwQJW+g5YWd8QAKZEfjGI2/fJkF3XS3DQHhJbxVU ysIlBSXcR1/Dn0HngnqNNptYhF88Kb58kdDzH4DEIIRiJF0Is0FSu+P9yRVQN+AabHQZ kD5Q== 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=noh/Vnh2WwSYIn1sxHmj2c/BvdKQnBrMtRDA0Rmlot8=; b=04PUzrLRRT7KAdyNAzcvgsPDcSXVeUNnu373A4sZSGGenKTwucy+qznZTha8sUDlpD us4dro0S3Sp3N/pRnP8Ejkoou0IyzQox9AJo8//atg2JEHHIIZuWQYOLoNv0BfAQnMdG lYl2SQTGvVntHau0y4i+lpQULSMzwv+Z7sjapTh7e957D66cJAjWsKGsNIl01Dvh9Q9A nzn8HShRDN4y+NCciBaptE1dQYM2tUR0bPc4CMEfo6zDArQ3YE+6acVFgmEoBNlJ20dv Lfz4pVszH6GLtKpW3Uh53bqRv2yOtEuJrzfIfJTdGWEXR+C+CcT9tV1NWaaxdlbRjmwl y2yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UglwgWwM; 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 bs4si8673982edb.261.2020.09.21.09.39.51; Mon, 21 Sep 2020 09:40:14 -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=UglwgWwM; 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 S1728543AbgIUQhx (ORCPT + 99 others); Mon, 21 Sep 2020 12:37:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:38392 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728789AbgIUQho (ORCPT ); Mon, 21 Sep 2020 12:37:44 -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 04ACD238EE; Mon, 21 Sep 2020 16:37:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706263; bh=p7jydHRi2UcpgGqpxPC294TEpk0O700BEyFJFD72Stg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UglwgWwMvQ3lyyYZVv4XHDQR+meiWFN38/9BGxvOkRVnO9hqm0bXqm1DDQDXvCUF6 VXYByUVa2QMq9CWGulUUPQVSN2JrHokH7lr/Uv7ZG0CzbPYvDsACbbaSVOfyiXJT/h FcccKqjkNba5dATbNSjuwXIPXOi7kyr2vkWyX4jw= 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.14 31/94] iio:adc:ti-adc081c Fix alignment and data leak issues Date: Mon, 21 Sep 2020 18:27:18 +0200 Message-Id: <20200921162036.981421718@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 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 @@ -132,14 +138,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);