Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3030918pxb; Mon, 18 Oct 2021 06:58:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiEUQBmV5pbpxm6RzdYJp++YFn3yLCM+w/C5GuxhWsaMRWDqM/V8xOV4LiynMHo/XXpGuw X-Received: by 2002:a17:902:d4d1:b0:13f:af7:9068 with SMTP id o17-20020a170902d4d100b0013f0af79068mr27314783plg.20.1634565499714; Mon, 18 Oct 2021 06:58:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634565499; cv=none; d=google.com; s=arc-20160816; b=pwRe2ZblancUm7WsMR8/tjV3HFPobR6m33eE8EDlAEecoQfiuFmWXHeKa9kXq7bLnR AAY0rRBkCFmnngDo5p252DsmzCVbP/E/Ldw/VFikK36IOF28nYto2uyKgem1UfVMrraz jtY8eWatWsTZ0iA2AW310IvairD0bCFMeKj/jg49DvV0fjoaOy4ZoLgy0k/EK2zn05Ar mCF06OLYVJJEyW4WNyaKLfzcReFmH1r1RvLB0fFQjQY1VyBJw7rpe9c8f6XLBU98KNlm OJB7h3SDZFilsL1XVIetHawZqZwgtMSMNxplZ7xBPcIXZOl7EaMkY9qPlAX+c6Dxv489 bk+w== 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=KF26tOrgXWDSJchkHkKccmbJ7E67e4DK/EXL7z8Es9MntfklPQyWT0z3YJZiBcSSxT BWCEex+ZIwbVwP2mrasBrjY8yIeGI3c8bYNSYQHwY6N6iIJx6QgHxkFFN6uF5/rjn3Zk 3okchlx2EKJRIcA+cqsEMXXyMHPAP1i5DfmYtOGQoRbYkzW7wDL0tm+V17BBaxgi3fAF Ruv8JtnEUr1sc5Q3+tRCNJiQXqYxcR26IhNCV5HwxRJS+OUAd9vW1sDYUJGZSOh+Q0iB ONZi7OzxXZvlGpvFLHBexSqi24XRXnqeWf+QJFjWHuot3etvCoDJdo+/hjXjjyDBXv09 7ifw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NgTtK0Vr; 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 e18si25447536plh.102.2021.10.18.06.58.05; Mon, 18 Oct 2021 06:58: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=NgTtK0Vr; 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 S234193AbhJRN5t (ORCPT + 99 others); Mon, 18 Oct 2021 09:57:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:58122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234336AbhJRNzu (ORCPT ); Mon, 18 Oct 2021 09:55:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8686161A04; Mon, 18 Oct 2021 13:40:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634564409; bh=sH1yKxxos5/co1fIbgisEwbOaF8zHZ/40AoBPTdz9SU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NgTtK0VrjkGEPDWadhZYcQaYAc7P5giDMzRjR+iGX8nMwjmcEjS03giuZkFmR7pf+ RKFdnCKvNwK1k2U0nZz2OoUwnbwOxzMzYk42uENHLAovnVpUiENocD8zl6qYMFmplr K8nNMTx6CiF1jvJcabQyktrFXQmcuRUwJM7P6K9U= 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.14 079/151] iio: ssp_sensors: add more range checking in ssp_parse_dataframe() Date: Mon, 18 Oct 2021 15:24:18 +0200 Message-Id: <20211018132343.257069037@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132340.682786018@linuxfoundation.org> References: <20211018132340.682786018@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,