Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3014628pxb; Mon, 18 Oct 2021 06:38:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoFVAdGH0cRO1c5zkXal/H7gcvl+a/k5MtFAtAiIncCC6O6zgFfGumUclNt7DyvdUmoVJf X-Received: by 2002:a17:90a:a586:: with SMTP id b6mr33155000pjq.244.1634564289216; Mon, 18 Oct 2021 06:38:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634564289; cv=none; d=google.com; s=arc-20160816; b=LbLEsMZdaqq5mFYutmLhhm2aHhaCHK8SPUezXCooVB/cB2c6u/HpGpNdOtyvviGx+3 a7RR3g/HPAHFXOuxEmU+Uj5/TsRLzwU0NA8wujKpSFbM4UgE7QjonrLwUAxPNIgbANd5 oUWFr3tOAdkGbvTtpMCPqV+Z/BlTELp+7j/+9s0H4D+ArECDdEk6PD46B08pxil5wYtp 30nQgc5zuNhHT4aS7c4oPEOAWzBrGvcVPy2A/zOcHUhkvzMnvV+Wkimd3Q6XGGfpP/a4 TEL5hc+yBW1oCuHlnkxQ5NR9jz/GMdv3yu39x537DZGMv7C/EfTyXqXXaPKEUiFt5+Cu L8KA== 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=7ZdddfuNb2bAHtzrQXnTJUQj/ZZXrQCEZh9+3eDLwZE=; b=B2zqtXQC0F8kIid+5zmw4X+6eXbusCjhErasAlbU4cM1cPhXh/r52+TvCaOEz1a40S PcJFV4LT9eHvpZ6hjZamJ6TLorem5cim3SZYcTPdHcK4sgamhWnMdjEXCXKA4teDlKC3 718Ss0Uffk9D+uFGD4YqOI9EqiOx851GOIUBqQmhFLheHx5XpOtt1mJEXSDzrfjJgFaf B1Ai3HTWxgPE16Hy4FYhgngIX4KaLOVf7lJZofavIfZ9NnogATNRmCwMqiwLFyyifRZs Tru2lBnmLv4eTDKb0cTCPH6gJ1DPbFsrB7SBl/nuTZsOxbWEfoPGIQTAHVrr/SWf6yJY hovw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="aU/zOXD5"; 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 b16si3698120pfb.117.2021.10.18.06.37.56; Mon, 18 Oct 2021 06:38:09 -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="aU/zOXD5"; 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 S232783AbhJRNjI (ORCPT + 99 others); Mon, 18 Oct 2021 09:39:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:55128 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232628AbhJRNgO (ORCPT ); Mon, 18 Oct 2021 09:36:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 727F0613CF; Mon, 18 Oct 2021 13:30:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634563859; bh=sH1yKxxos5/co1fIbgisEwbOaF8zHZ/40AoBPTdz9SU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aU/zOXD5vHe8GJEyuLKXxfM6qlyXA6wEU7Rkq0xxXSShKBCF54RZphZ9tbEV93h5d jjyYwT5eG04HN85aNHGBf4aWKw0I0DoUUc8Xsvn3rac95ZQPIZ99zF/yMJAQxk7dFj NM5RsFJKtK/4o6YRu7ddX6o8k4sNxkncktL0PQ4E= 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 5.4 42/69] iio: ssp_sensors: add more range checking in ssp_parse_dataframe() Date: Mon, 18 Oct 2021 15:24:40 +0200 Message-Id: <20211018132330.871950576@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132329.453964125@linuxfoundation.org> References: <20211018132329.453964125@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 @@ -273,6 +273,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, @@ -282,10 +284,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"); } @@ -293,6 +298,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,