iio: Fix the allocation size for cros_ec_command
Subsystems (2)
PATCH 1/1 iio: Fix the allocation size for cros_ec_command
The struct cros_ec_command contains several integer fields and a trailing array. An allocation size neglecting the integer fields can lead to buffer overrun.
--- drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +2 -2
@@ -253,8 +253,8 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,platform_set_drvdata (pdev, indio_dev); state->ec = ec->ec_dev; - state->msg =devm_kzalloc (&pdev->dev, -max ((u16 )sizeof (struct ec_params_motion_sense ), + state->msg =devm_kzalloc (&pdev->dev,sizeof (*state->msg) + +max ((u16 )sizeof (struct ec_params_motion_sense ), state->ec->max_response),GFP_KERNEL );if (!state->msg)return -ENOMEM ;
Signature · 1 line
2.25.1
Quoted 5 lines · Yiyuan Guo
The struct
cros_ec_commandcontains several integer fields and a trailing array. An allocation size neglecting the integer fields can lead to buffer overrun.Signed-off-by Yiyuan Guo <[email protected]>
Better prefix the commit title with "iio: cros_ec:".
With that:
PATCH v2 1/1 iio: cros_ec: Fix the allocation size for cros_ec_command
In reply to Yiyuan GuoThe struct cros_ec_command contains several integer fields and a trailing array. An allocation size neglecting the integer fields can lead to buffer overrun.
--- drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +2 -2
@@ -253,8 +253,8 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,platform_set_drvdata (pdev, indio_dev); state->ec = ec->ec_dev; - state->msg =devm_kzalloc (&pdev->dev, -max ((u16 )sizeof (struct ec_params_motion_sense ), + state->msg =devm_kzalloc (&pdev->dev,sizeof (*state->msg) + +max ((u16 )sizeof (struct ec_params_motion_sense ), state->ec->max_response),GFP_KERNEL );if (!state->msg)return -ENOMEM ;
Signature · 1 line
2.25.1
Re: [PATCH v2] iio: cros_ec: Fix the allocation size for cros_ec_command
Quoted 5 lines · Yiyuan Guo
The struct
cros_ec_commandcontains several integer fields and a trailing array. An allocation size neglecting the integer fields can lead to buffer overrun.Signed-off-by Yiyuan Guo <[email protected]>
You could attach my R-b tag as v2 has no major changes from v1.
Quoted 1 line
---
Always a good practice to put changelog here. Search "changelog" in [1].
[1]: https://www.kernel.org/doc/html/latest/process/submitting-patches.html
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c int cros_ec_sensors_core_init(struct platform_device *pdev, · line 258
Quoted 9 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +2
-2@@ -253,8 +253,8 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,platform_set_drvdata (pdev, indio_dev); state->ec = ec->ec_dev; - state->msg =devm_kzalloc (&pdev->dev, -max ((u16 )sizeof (struct ec_params_motion_sense ), + state->msg =devm_kzalloc (&pdev->dev,sizeof (*state->msg) + +max ((u16 )sizeof (struct ec_params_motion_sense ), state->ec->max_response),GFP_KERNEL );
While looking at the patch again, I found a nit. Please align the code by adding an extra tab before "max".
PATCH v3 1/1 iio: cros_ec: Fix the allocation size for cros_ec_command
The struct cros_ec_command contains several integer fields and a trailing array. An allocation size neglecting the integer fields can lead to buffer overrun.
---v2->v3:
* Added R-b tag from Tzung-Bi Shih
* Aligned the code by adding an extra tab before "max"
* Added a patch changelogv1->v2: Prefixed the commit title with "iio: cros_ec:"
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +1 -1
@@ -253,7 +253,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,platform_set_drvdata (pdev, indio_dev); state->ec = ec->ec_dev; - state->msg =devm_kzalloc (&pdev->dev, + state->msg =devm_kzalloc (&pdev->dev,sizeof (*state->msg) +max ((u16 )sizeof (struct ec_params_motion_sense ), state->ec->max_response),GFP_KERNEL );if (!state->msg)
Signature · 1 line
2.25.1
Re: [PATCH v3] iio: cros_ec: Fix the allocation size for cros_ec_command
Quoted 7 lines · Yiyuan Guo
The struct
cros_ec_commandcontains several integer fields and a trailing array. An allocation size neglecting the integer fields can lead to buffer overrun.Reviewed-by Tzung-Bi Shih <[email protected]>Signed-off-by Yiyuan Guo <[email protected]>
Please _never_ send a patch as reply to a previous one, much less with a Re: subject.
Guenter
Quoted 26 lines
---
v2->v3:
* Added R-b tag from Tzung-Bi Shih
* Aligned the code by adding an extra tab before "max"
* Added a patch changelogv1->v2: Prefixed the commit title with "iio:cros_ec:"drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +1
-2@@ -253,7 +253,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,platform_set_drvdata (pdev, indio_dev); state->ec = ec->ec_dev; - state->msg =devm_kzalloc (&pdev->dev, + state->msg =devm_kzalloc (&pdev->dev,sizeof (*state->msg) +max ((u16 )sizeof (struct ec_params_motion_sense ), state->ec->max_response),GFP_KERNEL );if (!state->msg) --2.25.1
Re: [PATCH v3] iio: cros_ec: Fix the allocation size for cros_ec_command
Got it. I have resent the patch in a separate thread.
Thanks,
Yiyuan
Quoted 41 lines · Guenter Roeck
Quoted 7 lines · Yiyuan Guo
The struct
cros_ec_commandcontains several integer fields and a trailing array. An allocation size neglecting the integer fields can lead to buffer overrun.Reviewed-by Tzung-Bi Shih <[email protected]>Signed-off-by Yiyuan Guo <[email protected]>Please _never_ send a patch as reply to a previous one, much less with a Re: subject.
Guenter
Quoted 26 lines
---
v2->v3:
* Added R-b tag from Tzung-Bi Shih
* Aligned the code by adding an extra tab before "max"
* Added a patch changelogv1->v2: Prefixed the commit title with "iio:cros_ec:"drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +1
-2@@ -253,7 +253,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,platform_set_drvdata (pdev, indio_dev); state->ec = ec->ec_dev; - state->msg =devm_kzalloc (&pdev->dev, + state->msg =devm_kzalloc (&pdev->dev,sizeof (*state->msg) +max ((u16 )sizeof (struct ec_params_motion_sense ), state->ec->max_response),GFP_KERNEL );if (!state->msg) --2.25.1