Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp608395pxb; Mon, 25 Oct 2021 14:53:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynFvJzxAjun/wKsZ4JtKTVHXAOt1CbMuPWQSlCP9XEBBx0i4EzFO5dolwGoXrXARiUFTVr X-Received: by 2002:a17:902:784c:b0:138:f4e5:9df8 with SMTP id e12-20020a170902784c00b00138f4e59df8mr18555781pln.14.1635198799796; Mon, 25 Oct 2021 14:53:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635198799; cv=none; d=google.com; s=arc-20160816; b=tq51YFBPddjK4ZUALMlVdVKtN1PfOJQPs0ghXQagL6aSD5UIQX6V+Hc8PzCbMDrL1n an4vkeRNF9sRyeWBOjz5X+LVdnhzVCgnV1rdu5wUWYI0HTaCOSZEUUbdNCwoR1+j4GaR KhTRlngDDYD0Si0hc7ZiHM8dgNIZE3rHS/MlpQ6aSx+QcqEMqw1AAr60twqsEI5qO436 DSIA9AN0Y2NTzYhkZ2jaTk+L7aXDZuufuqRXjcGl8u5+CAOgIhD7MGGatGGen3rwxVns hLqaUR+qF3VIEAzmVMSWB5lc7F3a3mY1NnWSFRnnoBxbQtsSH/dCwMdpgw05qtjV2urL G43g== 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=1v3ml49RjrUsHIhSMCUO5uQTEdWHtzkA7pqXWm2hcfs=; b=G9I8cPBJr+p3biJNq6dMNazjtF/EgZQh/0MUOT95SukowWLfozNz1cwMQ+1BApx9P4 jJ7l4NgATbubpBTeuESgvGSsxAszhE+WoS65YIwiWsCF4glWdSmoaBphzUuggTFps3wF P/09zIH0B248/ZrXZjO7E8tV7L9EawS/NKaZpPZQUi4PFiZLy8QsWm2nB6i2mxJT6hLc TbCi34G+d05JXm4copEGZt7ibzUx9cdwBG+Iz/4MqHu0NHC26hnk9IwULjwK7lbLQR1q JvS2mYzrIYd5Ax3BJr6vclIBgMB9xbrHoSOq36Eb6ozQthz5ohh+A8fny3fw3zNNiJ54 VLWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QuSsKuEU; 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=pass (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 x1si13637476pgu.532.2021.10.25.14.53.06; Mon, 25 Oct 2021 14:53:19 -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=@linuxfoundation.org header.s=korg header.b=QuSsKuEU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234162AbhJYTSP (ORCPT + 99 others); Mon, 25 Oct 2021 15:18:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:35724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234123AbhJYTSE (ORCPT ); Mon, 25 Oct 2021 15:18:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9D9FD60FE8; Mon, 25 Oct 2021 19:15:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635189342; bh=gNRHkcxNAhkS63JpCBusgv0NtAF1h969xehizz1tV6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QuSsKuEUBVqv+7v72/CaRxcDMPlceRUnPwT5zneRidGy0HJs3xwItHuTcg2YUVc8/ 2ysIt8oJY37XQr5FaoQIoi+N3B419Wu4UEdnOQhnFCenobriwlU61pfuw1bOAhpY3S zCzX0o9oWK4yuca6caBqKIZCVv+OsSk16hdQfbZo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 4.4 11/44] iio: ssp_sensors: add more range checking in ssp_parse_dataframe() Date: Mon, 25 Oct 2021 21:13:52 +0200 Message-Id: <20211025190930.935892826@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211025190928.054676643@linuxfoundation.org> References: <20211025190928.054676643@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: Dan Carpenter commit 8167c9a375ccceed19048ad9d68cb2d02ed276e0 upstream. The "idx" is validated at the start of the loop but it gets incremented during the iteration so it needs to be checked again. Fixes: 50dd64d57eee ("iio: common: ssp_sensors: Add sensorhub driver") Signed-off-by: Dan Carpenter Link: https://lore.kernel.org/r/20210909091336.GA26312@kili Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/common/ssp_sensors/ssp_spi.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/drivers/iio/common/ssp_sensors/ssp_spi.c +++ b/drivers/iio/common/ssp_sensors/ssp_spi.c @@ -286,6 +286,8 @@ static int ssp_parse_dataframe(struct ss for (idx = 0; idx < len;) { switch (dataframe[idx++]) { case SSP_MSG2AP_INST_BYPASS_DATA: + if (idx >= len) + return -EPROTO; sd = dataframe[idx++]; if (sd < 0 || sd >= SSP_SENSOR_MAX) { dev_err(SSP_DEV, @@ -295,10 +297,13 @@ static int ssp_parse_dataframe(struct ss if (indio_devs[sd]) { spd = iio_priv(indio_devs[sd]); - if (spd->process_data) + if (spd->process_data) { + if (idx >= len) + return -EPROTO; spd->process_data(indio_devs[sd], &dataframe[idx], data->timestamp); + } } else { dev_err(SSP_DEV, "no client for frame\n"); } @@ -306,6 +311,8 @@ static int ssp_parse_dataframe(struct ss idx += ssp_offset_map[sd]; break; case SSP_MSG2AP_INST_DEBUG_DATA: + if (idx >= len) + return -EPROTO; sd = ssp_print_mcu_debug(dataframe, &idx, len); if (sd) { dev_err(SSP_DEV,