]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
powercap: intel_rapl: Fix off by one in get_rpi()
authorDan Carpenter <dan.carpenter@linaro.org>
Tue, 20 Aug 2024 08:41:34 +0000 (11:41 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 4 Oct 2024 14:28:51 +0000 (16:28 +0200)
[ Upstream commit 95f6580352a7225e619551febb83595bcb77ab17 ]

The rp->priv->rpi array is either rpi_msr or rpi_tpmi which have
NR_RAPL_PRIMITIVES number of elements.  Thus the > needs to be >=
to prevent an off by one access.

Fixes: 98ff639a7289 ("powercap: intel_rapl: Support per Interface primitive information")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Acked-by: Zhang Rui <rui.zhang@intel.com>
Link: https://patch.msgid.link/86e3a059-504d-4795-a5ea-4a653f3b41f8@stanley.mountain
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/powercap/intel_rapl_common.c

index 3dfe45ac300aa96777d273887e14197a6dc89b36..f1de4111e98d9d2224147625e9d2742c7fe818ce 100644 (file)
@@ -738,7 +738,7 @@ static struct rapl_primitive_info *get_rpi(struct rapl_package *rp, int prim)
 {
        struct rapl_primitive_info *rpi = rp->priv->rpi;
 
-       if (prim < 0 || prim > NR_RAPL_PRIMITIVES || !rpi)
+       if (prim < 0 || prim >= NR_RAPL_PRIMITIVES || !rpi)
                return NULL;
 
        return &rpi[prim];