Patch "regulator: s5m8767: Bounds check id indexing into arrays" has been added to the 5.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    regulator: s5m8767: Bounds check id indexing into arrays

to the 5.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     regulator-s5m8767-bounds-check-id-indexing-into-arra.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 866c1679a8c200a9f2759be736123935b7a31b83
Author: Kees Cook <keescook@xxxxxxxxxxxx>
Date:   Fri Jan 27 16:53:58 2023 -0800

    regulator: s5m8767: Bounds check id indexing into arrays
    
    [ Upstream commit e314e15a0b58f9d051c00b25951073bcdae61953 ]
    
    The compiler has no way to know if "id" is within the array bounds of
    the regulators array. Add a check for this and a build-time check that
    the regulators and reg_voltage_map arrays are sized the same. Seen with
    GCC 13:
    
    ../drivers/regulator/s5m8767.c: In function 's5m8767_pmic_probe':
    ../drivers/regulator/s5m8767.c:936:35: warning: array subscript [0, 36] is outside array bounds of 'struct regulator_desc[37]' [-Warray-bounds=]
      936 |                         regulators[id].vsel_reg =
          |                         ~~~~~~~~~~^~~~
    
    Cc: Krzysztof Kozlowski <krzysztof.kozlowski@xxxxxxxxxx>
    Cc: Liam Girdwood <lgirdwood@xxxxxxxxx>
    Cc: Mark Brown <broonie@xxxxxxxxxx>
    Cc: linux-samsung-soc@xxxxxxxxxxxxxxx
    Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>
    Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20230128005358.never.313-kees@xxxxxxxxxx
    Signed-off-by: Mark Brown <broonie@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index 1e9f03a2ea1cc..7ff480810cfa2 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -924,10 +924,14 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
 
 	for (i = 0; i < pdata->num_regulators; i++) {
 		const struct sec_voltage_desc *desc;
-		int id = pdata->regulators[i].id;
+		unsigned int id = pdata->regulators[i].id;
 		int enable_reg, enable_val;
 		struct regulator_dev *rdev;
 
+		BUILD_BUG_ON(ARRAY_SIZE(regulators) != ARRAY_SIZE(reg_voltage_map));
+		if (WARN_ON_ONCE(id >= ARRAY_SIZE(regulators)))
+			continue;
+
 		desc = reg_voltage_map[id];
 		if (desc) {
 			regulators[id].n_voltages =



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux