From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63A1D7C6DB; Wed, 21 Feb 2024 13:49:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708523385; cv=none; b=qM6FehNbrUPW/MUvUVimWbT5JPybf3JwVteaqDIuH4mT2hHXeNUf0oPGDjMH9VVzHc+I1feYD3LXE66kyNFiN0evQuE6NU1k2mpkfvycmAsHMwKx5ADKvwdOFQI07hwMtMZKnY5ObxTGYcu4FGH3QaYPYhbtCyJBq8k6+8uNZIE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708523385; c=relaxed/simple; bh=KhtfPzQctWiQfPrQxz0qzAyGcI70DaNqSjVJGF2kPYY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iMAdhLwctBQ8I31bVVMlQOBVKHj43j2MfmHXEplNMSLlvgzPqY1EFaazU3LJz2jMHvNLvE25NOpUNOqymgPLVDNKMbh8R5bm5oZdr6ZX/VblWZMM409/7fWfV7+E46FNBUf8rlLLpwRAsZUmLNquDFcyvcF7xyYM0/h0DwpjMX0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jHFIRcVJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="jHFIRcVJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB60CC43390; Wed, 21 Feb 2024 13:49:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708523385; bh=KhtfPzQctWiQfPrQxz0qzAyGcI70DaNqSjVJGF2kPYY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jHFIRcVJKsriRNWF7sStw4Rp2LVXYvZNxm/OfrF3S5rwKIKCadXHCUdAMo8qboWOw OVLrJUIY2nje9FTZwLdLH80AnjYW6brHTPcdmiJ2Lg6dtVzROwr9m0fJ0DXqyxAjYN zK4VOA5QdrTiInmO8rAIPmjE5xCx94wN/9zqZfMo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhouyi Zhou , "zhili.liu" , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 5.15 392/476] iio: magnetometer: rm3100: add boundary check for the value read from RM3100_REG_TMRC Date: Wed, 21 Feb 2024 14:07:23 +0100 Message-ID: <20240221130022.511609727@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221130007.738356493@linuxfoundation.org> References: <20240221130007.738356493@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: zhili.liu commit 792595bab4925aa06532a14dd256db523eb4fa5e upstream. Recently, we encounter kernel crash in function rm3100_common_probe caused by out of bound access of array rm3100_samp_rates (because of underlying hardware failures). Add boundary check to prevent out of bound access. Fixes: 121354b2eceb ("iio: magnetometer: Add driver support for PNI RM3100") Suggested-by: Zhouyi Zhou Signed-off-by: zhili.liu Link: https://lore.kernel.org/r/1704157631-3814-1-git-send-email-zhouzhouyi@gmail.com Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/magnetometer/rm3100-core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/drivers/iio/magnetometer/rm3100-core.c +++ b/drivers/iio/magnetometer/rm3100-core.c @@ -538,6 +538,7 @@ int rm3100_common_probe(struct device *d struct rm3100_data *data; unsigned int tmp; int ret; + int samp_rate_index; indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); if (!indio_dev) @@ -595,9 +596,14 @@ int rm3100_common_probe(struct device *d ret = regmap_read(regmap, RM3100_REG_TMRC, &tmp); if (ret < 0) return ret; + + samp_rate_index = tmp - RM3100_TMRC_OFFSET; + if (samp_rate_index < 0 || samp_rate_index >= RM3100_SAMP_NUM) { + dev_err(dev, "The value read from RM3100_REG_TMRC is invalid!\n"); + return -EINVAL; + } /* Initializing max wait time, which is double conversion time. */ - data->conversion_time = rm3100_samp_rates[tmp - RM3100_TMRC_OFFSET][2] - * 2; + data->conversion_time = rm3100_samp_rates[samp_rate_index][2] * 2; /* Cycle count values may not be what we want. */ if ((tmp - RM3100_TMRC_OFFSET) == 0)