Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1623485 > unrolled thread
| Started by | Axel Lin <axel.lin@ingics.com> |
|---|---|
| First post | 2017-04-14 05:00 +0200 |
| Last post | 2017-04-14 19:20 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] regulator: vctrl: Fix out of bounds array access for vctrl->vtable Axel Lin <axel.lin@ingics.com> - 2017-04-14 05:00 +0200
Re: [PATCH] regulator: vctrl: Fix out of bounds array access for vctrl->vtable Matthias Kaehlcke <mka@chromium.org> - 2017-04-14 19:20 +0200
Re: [PATCH] regulator: vctrl: Fix out of bounds array access for vctrl->vtable Matthias Kaehlcke <mka@chromium.org> - 2017-04-14 21:10 +0200
Applied "regulator: vctrl: Fix out of bounds array access for vctrl->vtable" to the regulator tree Mark Brown <broonie@kernel.org> - 2017-04-14 19:20 +0200
| From | Axel Lin <axel.lin@ingics.com> |
|---|---|
| Date | 2017-04-14 05:00 +0200 |
| Subject | [PATCH] regulator: vctrl: Fix out of bounds array access for vctrl->vtable |
| Message-ID | <tvZCO-3NY-9@gated-at.bofh.it> |
Current code only allocates rdesc->n_voltages entries for vctrl->vtable.
Thus use rdesc->n_voltages instead of n_voltages in the for loop.
While at it, also switch to use devm_kcalloc instead of devm_kmalloc_array
+ __GFP_ZERO flag and fix the argument order.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
drivers/regulator/vctrl-regulator.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/regulator/vctrl-regulator.c b/drivers/regulator/vctrl-regulator.c
index 6baadef..78de002 100644
--- a/drivers/regulator/vctrl-regulator.c
+++ b/drivers/regulator/vctrl-regulator.c
@@ -345,9 +345,9 @@ static int vctrl_init_vtable(struct platform_device *pdev)
return -EINVAL;
}
- vctrl->vtable = devm_kmalloc_array(
- &pdev->dev, sizeof(struct vctrl_voltage_table),
- rdesc->n_voltages, GFP_KERNEL | __GFP_ZERO);
+ vctrl->vtable = devm_kcalloc(&pdev->dev, rdesc->n_voltages,
+ sizeof(struct vctrl_voltage_table),
+ GFP_KERNEL);
if (!vctrl->vtable)
return -ENOMEM;
@@ -371,7 +371,7 @@ static int vctrl_init_vtable(struct platform_device *pdev)
NULL);
/* pre-calculate OVP-safe downward transitions */
- for (i = n_voltages - 1; i > 0; i--) {
+ for (i = rdesc->n_voltages - 1; i > 0; i--) {
int j;
int ovp_min_uV = (vctrl->vtable[i].out *
(100 - vctrl->ovp_threshold)) / 100;
--
2.9.3
[toc] | [next] | [standalone]
| From | Matthias Kaehlcke <mka@chromium.org> |
|---|---|
| Date | 2017-04-14 19:20 +0200 |
| Subject | Re: [PATCH] regulator: vctrl: Fix out of bounds array access for vctrl->vtable |
| Message-ID | <twd33-3Pv-1@gated-at.bofh.it> |
| In reply to | #1623485 |
Hi Axel,
El Fri, Apr 14, 2017 at 10:50:43AM +0800 Axel Lin ha dit:
> Current code only allocates rdesc->n_voltages entries for vctrl->vtable.
> Thus use rdesc->n_voltages instead of n_voltages in the for loop.
This is intended. n_voltages is the number of voltages of the control
regulator. In the first loop of the function we determine how many of
these voltages are usable by the vctrl regulator (=> rdesc->n_voltages).
The loop that populates vctrl->vtable iterates over n_voltages,
however it skips those that are outside of the voltage range for the
control regulator.
> While at it, also switch to use devm_kcalloc instead of devm_kmalloc_array
> + __GFP_ZERO flag and fix the argument order.
This looks good to me.
Thanks
Matthias
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
> drivers/regulator/vctrl-regulator.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/regulator/vctrl-regulator.c b/drivers/regulator/vctrl-regulator.c
> index 6baadef..78de002 100644
> --- a/drivers/regulator/vctrl-regulator.c
> +++ b/drivers/regulator/vctrl-regulator.c
> @@ -345,9 +345,9 @@ static int vctrl_init_vtable(struct platform_device *pdev)
> return -EINVAL;
> }
>
> - vctrl->vtable = devm_kmalloc_array(
> - &pdev->dev, sizeof(struct vctrl_voltage_table),
> - rdesc->n_voltages, GFP_KERNEL | __GFP_ZERO);
> + vctrl->vtable = devm_kcalloc(&pdev->dev, rdesc->n_voltages,
> + sizeof(struct vctrl_voltage_table),
> + GFP_KERNEL);
> if (!vctrl->vtable)
> return -ENOMEM;
>
> @@ -371,7 +371,7 @@ static int vctrl_init_vtable(struct platform_device *pdev)
> NULL);
>
> /* pre-calculate OVP-safe downward transitions */
> - for (i = n_voltages - 1; i > 0; i--) {
> + for (i = rdesc->n_voltages - 1; i > 0; i--) {
> int j;
> int ovp_min_uV = (vctrl->vtable[i].out *
> (100 - vctrl->ovp_threshold)) / 100;
[toc] | [prev] | [next] | [standalone]
| From | Matthias Kaehlcke <mka@chromium.org> |
|---|---|
| Date | 2017-04-14 21:10 +0200 |
| Subject | Re: [PATCH] regulator: vctrl: Fix out of bounds array access for vctrl->vtable |
| Message-ID | <tweLv-4WH-5@gated-at.bofh.it> |
| In reply to | #1623789 |
El Fri, Apr 14, 2017 at 10:11:37AM -0700 Matthias Kaehlcke ha dit:
> Hi Axel,
>
> El Fri, Apr 14, 2017 at 10:50:43AM +0800 Axel Lin ha dit:
>
> > Current code only allocates rdesc->n_voltages entries for vctrl->vtable.
> > Thus use rdesc->n_voltages instead of n_voltages in the for loop.
>
> This is intended. n_voltages is the number of voltages of the control
> regulator. In the first loop of the function we determine how many of
> these voltages are usable by the vctrl regulator (=> rdesc->n_voltages).
> The loop that populates vctrl->vtable iterates over n_voltages,
> however it skips those that are outside of the voltage range for the
> control regulator.
Sorry, I should have gotten coffee first. Your patch changes the
pre-calc and not the population loop, the use of n_voltages there
is indeed incorrect. Thanks for catching this!
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
> > While at it, also switch to use devm_kcalloc instead of devm_kmalloc_array
> > + __GFP_ZERO flag and fix the argument order.
>
> This looks good to me.
>
> Thanks
>
> Matthias
>
> > Signed-off-by: Axel Lin <axel.lin@ingics.com>
> > ---
> > drivers/regulator/vctrl-regulator.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/regulator/vctrl-regulator.c b/drivers/regulator/vctrl-regulator.c
> > index 6baadef..78de002 100644
> > --- a/drivers/regulator/vctrl-regulator.c
> > +++ b/drivers/regulator/vctrl-regulator.c
> > @@ -345,9 +345,9 @@ static int vctrl_init_vtable(struct platform_device *pdev)
> > return -EINVAL;
> > }
> >
> > - vctrl->vtable = devm_kmalloc_array(
> > - &pdev->dev, sizeof(struct vctrl_voltage_table),
> > - rdesc->n_voltages, GFP_KERNEL | __GFP_ZERO);
> > + vctrl->vtable = devm_kcalloc(&pdev->dev, rdesc->n_voltages,
> > + sizeof(struct vctrl_voltage_table),
> > + GFP_KERNEL);
> > if (!vctrl->vtable)
> > return -ENOMEM;
> >
> > @@ -371,7 +371,7 @@ static int vctrl_init_vtable(struct platform_device *pdev)
> > NULL);
> >
> > /* pre-calculate OVP-safe downward transitions */
> > - for (i = n_voltages - 1; i > 0; i--) {
> > + for (i = rdesc->n_voltages - 1; i > 0; i--) {
> > int j;
> > int ovp_min_uV = (vctrl->vtable[i].out *
> > (100 - vctrl->ovp_threshold)) / 100;
[toc] | [prev] | [next] | [standalone]
| From | Mark Brown <broonie@kernel.org> |
|---|---|
| Date | 2017-04-14 19:20 +0200 |
| Subject | Applied "regulator: vctrl: Fix out of bounds array access for vctrl->vtable" to the regulator tree |
| Message-ID | <twd34-3Pv-19@gated-at.bofh.it> |
| In reply to | #1623485 |
The patch
regulator: vctrl: Fix out of bounds array access for vctrl->vtable
has been applied to the regulator tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
From a9bbb453b50c91295ab362e4832eb37fd4e6785d Mon Sep 17 00:00:00 2001
From: Axel Lin <axel.lin@ingics.com>
Date: Fri, 14 Apr 2017 10:50:43 +0800
Subject: [PATCH] regulator: vctrl: Fix out of bounds array access for
vctrl->vtable
Current code only allocates rdesc->n_voltages entries for vctrl->vtable.
Thus use rdesc->n_voltages instead of n_voltages in the for loop.
While at it, also switch to use devm_kcalloc instead of devm_kmalloc_array
+ __GFP_ZERO flag and fix the argument order.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
drivers/regulator/vctrl-regulator.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/regulator/vctrl-regulator.c b/drivers/regulator/vctrl-regulator.c
index 6baadef0ed74..78de002037c7 100644
--- a/drivers/regulator/vctrl-regulator.c
+++ b/drivers/regulator/vctrl-regulator.c
@@ -345,9 +345,9 @@ static int vctrl_init_vtable(struct platform_device *pdev)
return -EINVAL;
}
- vctrl->vtable = devm_kmalloc_array(
- &pdev->dev, sizeof(struct vctrl_voltage_table),
- rdesc->n_voltages, GFP_KERNEL | __GFP_ZERO);
+ vctrl->vtable = devm_kcalloc(&pdev->dev, rdesc->n_voltages,
+ sizeof(struct vctrl_voltage_table),
+ GFP_KERNEL);
if (!vctrl->vtable)
return -ENOMEM;
@@ -371,7 +371,7 @@ static int vctrl_init_vtable(struct platform_device *pdev)
NULL);
/* pre-calculate OVP-safe downward transitions */
- for (i = n_voltages - 1; i > 0; i--) {
+ for (i = rdesc->n_voltages - 1; i > 0; i--) {
int j;
int ovp_min_uV = (vctrl->vtable[i].out *
(100 - vctrl->ovp_threshold)) / 100;
--
2.11.0
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web