From patchwork Mon Jul 20 15:35:35 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: 237547 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp2132044ilg; Mon, 20 Jul 2020 09:30:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKeUkAmYkl3hfw30lZKJr8AgOmLhOtEa9wy2I4KYGMF25f6sFI0tULEoF5cdPK7QiWpcbL X-Received: by 2002:aa7:d44f:: with SMTP id q15mr21275343edr.340.1595262653842; Mon, 20 Jul 2020 09:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595262653; cv=none; d=google.com; s=arc-20160816; b=e3MrrMUkzxQGMgnEOOqg2xLinTbSFobARODwqjcT12vZSuaX+2zsRR+3Lt2Cs2676z /6jTzN/U86lfygsiYHS1QGXnxWFYwJv74dbQSDhAPS+Qalm7jWd9A+Ghldts+ISPnHkW Wb7uiotWDW/ND0C8cxlO7oRk4np3sSmJrVg3h0Rer0HwpWkhU2mUj3lPY0fHb27NA0vh RCVD7YKtBaHGU1TxkL9DNM7Fjj2DEW6lzGnh2oa3POe4SF3Cp/XwPc6w+/7O6TXvTLaU o9nlRqsvVGgjTuDE3Ee0N1U8wmiBgcR9yhXJmmvYdXA0mH8j62GEUKGIvCey9dwK3bKi JazA== 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=MQukpceyA3tWf1bkLRu/MatGBpYJxWayJXaiWUTaRdA=; b=QIxhgMLMUvu5tiK2MvOdBodJ8N1UsKhDefjquhbWlKNNW2lqRG5jhlGiWDJAnpnscU 9jkVk9z2jK5XBcaqSqBXNpmR9CHb/qTpVPDfvalasBBYbSQwvcCBS7vdx6IGUnA40fFI 0Rk7aWfkrpiYGaB0OU4XPOyDJH9C3PseQRX6frbGkw3x/VlCuNHVngfroDrSxrCySQwI /hQmBiGjcu2T3ZVkG/RQbFRQbT9xEkkft2QZVczFLCUQdxJ4e5EtERe7cbudDPqZZ4/9 E80D/ObfwvuIEirjtc3kfuQHA4ruv8q0QQJj1E3rNuhLhRJaqwlzcaM0fHagaPmbt1BY QfxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="jEQ/lHdi"; 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 n7si11026106edv.74.2020.07.20.09.30.53; Mon, 20 Jul 2020 09:30:53 -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="jEQ/lHdi"; 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 S1732684AbgGTQat (ORCPT + 15 others); Mon, 20 Jul 2020 12:30:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:58008 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730562AbgGTP5y (ORCPT ); Mon, 20 Jul 2020 11:57:54 -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 1D60622CAF; Mon, 20 Jul 2020 15:57:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595260673; bh=1H5+7kJO9eaqpbN5JgnI5mNMkNUZHr0WnC6h16aXQEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jEQ/lHdiIhVJCF/1YQjwx9oG0JIBMjpzzjat7V9/pYukZjj4/bc3M3FBi9/CA8Crc H9HlKvmWHes1dqob8Xna+mmey2EIknBXQDQ7vx/fYAFjhgaHEtREaLQCJDMbGSrSRd ze5oyXQcA6YZjmL3fc1bpAL8+0MrOgVd83whKNK4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lars-Peter Clausen , Jonathan Cameron , Tomasz Duszynski , Stable@vger.kernel.org Subject: [PATCH 5.4 053/215] iio:pressure:ms5611 Fix buffer element alignment Date: Mon, 20 Jul 2020 17:35:35 +0200 Message-Id: <20200720152822.732782291@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 commit 8db4afe163bbdd93dca6fcefbb831ef12ecc6b4d 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. Here there is no data leak possibility so use an explicit structure on the stack to ensure alignment and nice readable fashion. The forced alignment of ts isn't strictly necessary in this driver as the padding will be correct anyway (there isn't any). However it is probably less fragile to have it there and it acts as documentation of the requirement. Fixes: 713bbb4efb9dc ("iio: pressure: ms5611: Add triggered buffer support") Reported-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron Acked-by: Tomasz Duszynski Cc: Signed-off-by: Greg Kroah-Hartman --- drivers/iio/pressure/ms5611_core.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/drivers/iio/pressure/ms5611_core.c +++ b/drivers/iio/pressure/ms5611_core.c @@ -212,16 +212,21 @@ static irqreturn_t ms5611_trigger_handle struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct ms5611_state *st = iio_priv(indio_dev); - s32 buf[4]; /* s32 (pressure) + s32 (temp) + 2 * s32 (timestamp) */ + /* Ensure buffer elements are naturally aligned */ + struct { + s32 channels[2]; + s64 ts __aligned(8); + } scan; int ret; mutex_lock(&st->lock); - ret = ms5611_read_temp_and_pressure(indio_dev, &buf[1], &buf[0]); + ret = ms5611_read_temp_and_pressure(indio_dev, &scan.channels[1], + &scan.channels[0]); mutex_unlock(&st->lock); if (ret < 0) goto err; - iio_push_to_buffers_with_timestamp(indio_dev, buf, + iio_push_to_buffers_with_timestamp(indio_dev, &scan, iio_get_time_ns(indio_dev)); err: