]> git.baikalelectronics.ru Git - kernel.git/commitdiff
regmap-irq: Fix offset/index mismatch in read_sub_irq_data()
authorAidan MacDonald <aidanmacdonald.0x0@gmail.com>
Mon, 20 Jun 2022 20:05:57 +0000 (21:05 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Jun 2022 07:03:25 +0000 (09:03 +0200)
[ Upstream commit 6aba4b5d3813d485a181e7f73bbf8bc2b58b6c05 ]

We need to divide the sub-irq status register offset by register
stride to get an index for the status buffer to avoid an out of
bounds write when the register stride is greater than 1.

Fixes: 9d73ad8e526e ("regmap: regmap-irq: Add main status register support")
Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
Link: https://lore.kernel.org/r/20220620200644.1961936-3-aidanmacdonald.0x0@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/base/regmap/regmap-irq.c

index cd12078ed51b1f9c261609ac23a3a22a88a3a13f..3aac960ae30abcaa006b2ca6dd1bbbd1625453bc 100644 (file)
@@ -387,6 +387,7 @@ static inline int read_sub_irq_data(struct regmap_irq_chip_data *data,
                subreg = &chip->sub_reg_offsets[b];
                for (i = 0; i < subreg->num_regs; i++) {
                        unsigned int offset = subreg->offset[i];
+                       unsigned int index = offset / map->reg_stride;
 
                        if (chip->not_fixed_stride)
                                ret = regmap_read(map,
@@ -395,7 +396,7 @@ static inline int read_sub_irq_data(struct regmap_irq_chip_data *data,
                        else
                                ret = regmap_read(map,
                                                chip->status_base + offset,
-                                               &data->status_buf[offset]);
+                                               &data->status_buf[index]);
 
                        if (ret)
                                break;