Skip to content

Commit befd813

Browse files
committed
OPP: fix dev_pm_opp_find_bw_*() when bandwidth table not initialized
JIRA: https://issues.redhat.com/browse/RHEL-84805 CVE: CVE-2024-58068 commit b44b9bc Author: Neil Armstrong <[email protected]> Date: Tue Dec 3 09:13:00 2024 +0100 OPP: fix dev_pm_opp_find_bw_*() when bandwidth table not initialized If a driver calls dev_pm_opp_find_bw_ceil/floor() the retrieve bandwidth from the OPP table but the bandwidth table was not created because the interconnect properties were missing in the OPP consumer node, the kernel will crash with: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000004 ... pc : _read_bw+0x8/0x10 lr : _opp_table_find_key+0x9c/0x174 ... Call trace: _read_bw+0x8/0x10 (P) _opp_table_find_key+0x9c/0x174 (L) _find_key+0x98/0x168 dev_pm_opp_find_bw_ceil+0x50/0x88 ... In order to fix the crash, create an assert function to check if the bandwidth table was created before trying to get a bandwidth with _read_bw(). Fixes: add1dc0 ("OPP: Use generic key finding helpers for bandwidth key") Signed-off-by: Neil Armstrong <[email protected]> Signed-off-by: Viresh Kumar <[email protected]> Signed-off-by: Jared Kangas <[email protected]>
1 parent 17e4321 commit befd813

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

drivers/opp/core.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ static bool assert_clk_index(struct opp_table *opp_table,
116116
return opp_table->clk_count > index;
117117
}
118118

119+
/*
120+
* Returns true if bandwidth table is large enough to contain the bandwidth index.
121+
*/
122+
static bool assert_bandwidth_index(struct opp_table *opp_table,
123+
unsigned int index)
124+
{
125+
return opp_table->path_count > index;
126+
}
127+
119128
/**
120129
* dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp
121130
* @opp: opp for which voltage has to be returned for
@@ -890,7 +899,8 @@ struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev, unsigned int *bw,
890899
unsigned long temp = *bw;
891900
struct dev_pm_opp *opp;
892901

893-
opp = _find_key_ceil(dev, &temp, index, true, _read_bw, NULL);
902+
opp = _find_key_ceil(dev, &temp, index, true, _read_bw,
903+
assert_bandwidth_index);
894904
*bw = temp;
895905
return opp;
896906
}
@@ -921,7 +931,8 @@ struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
921931
unsigned long temp = *bw;
922932
struct dev_pm_opp *opp;
923933

924-
opp = _find_key_floor(dev, &temp, index, true, _read_bw, NULL);
934+
opp = _find_key_floor(dev, &temp, index, true, _read_bw,
935+
assert_bandwidth_index);
925936
*bw = temp;
926937
return opp;
927938
}

0 commit comments

Comments
 (0)