Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3010874pxb; Mon, 18 Oct 2021 06:33:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiEIqLBuRbNx8T5wxWzb1LGLuoCmhA4tymcPsbf9YdOO0G4mjMLasKikvZljhUA0HWum3J X-Received: by 2002:a63:8742:: with SMTP id i63mr12141398pge.328.1634564019496; Mon, 18 Oct 2021 06:33:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634564019; cv=none; d=google.com; s=arc-20160816; b=cLrDgHCTUZVImeOhWf/BwqroRqoQXYc7+v8HBOWyK8g56cvsGE+t7NYw912nh7xcGg inved7oiOFSasLZvLrV8svZCjGcPCq4BFkduWQzr2Q8UdV2brXTdEN6S0PlmZzztgfHc tRZUUQfkMIQGCUcySf81YnzXBbk75EyaxZzpKWNVbrcMr9ICTAQgkXN6fG+sNJtAx9KU FmfV/GxFWGjQWM9mEgnxT4Vp1lkZA82+w2eFQNyPNKQSrznQelO1p3vENTBIdvr4gHeR LU9LaRUWD+s7BFyA7JysIJ2+VnUka6Rh2ZEbl7HNTvdOBZ9kFxpc6mcxejD2/ap0sPLQ Q0fw== 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=zCoNf6hD8yqPFoTEwSp2q2yTqHH5xuDgq7/zrOKM9bc=; b=XZPKw9leE02uJfuYWBRcSeg23SAfY2NBfZ7cHpmR2iPXMorb3UkaJECl+bRKD87Vu9 ZCZ1eFtaqiaHWq4ZYSiGzrOY51xCsQfn0p4taMSxSGuy7LYojg/ZO3MLGK74Dw0/+L9P pamQZrgSL6wMF4bDEImN71wWCD9G6LqNNIA43BP5C4CL0Tigsy59zELsjujWHVWm2mAX 9UVur4E4uI5dMqWss+teJewztK5CyETARV6wNsDp7elOsEoBbznjtMepiWx8dd+d2fyk tjxdRvVF5YbZPid1d2s6NnDP9E7WuZ08tmSRkp/t+jlMtDjFlknhxAFsCwW9FNQbGGAW WJ0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="qj86KWP/"; 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 l190si19206491pge.367.2021.10.18.06.33.26; Mon, 18 Oct 2021 06:33:39 -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="qj86KWP/"; 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 S232333AbhJRNek (ORCPT + 99 others); Mon, 18 Oct 2021 09:34:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:43310 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232055AbhJRNcq (ORCPT ); Mon, 18 Oct 2021 09:32:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5955261351; Mon, 18 Oct 2021 13:29:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634563766; bh=qg/4ckq0m7fS0L0LNkf1g03ABneXfXwvbnUI6eYM+t8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qj86KWP/saP9wXrabGQcyYgrDdBLIiHMByIiX5B9mn4HSI1pEeNN4WhCgFehqwCMH j0wUmPEav7wEX5ohb53w6iPkNzs4vrmsVUUEF8/HbkqBJN97LlGk5oc0DJkkGiAweE H/RHnIrguNxTE9Yd7I3yvouEr8L33zAQXixl3q5g= 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.19 30/50] iio: ssp_sensors: add more range checking in ssp_parse_dataframe() Date: Mon, 18 Oct 2021 15:24:37 +0200 Message-Id: <20211018132327.532435168@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132326.529486647@linuxfoundation.org> References: <20211018132326.529486647@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 @@ -283,6 +283,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, @@ -292,10 +294,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"); } @@ -303,6 +308,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,