Skip to contentSkip to conversation

iio: cros_ec: Fix the allocation size for cros_ec_command

PATCH Applied Yiyuan Guo 5 participants 8 messages Jun 30, 2023 – Sep 11, 2023

Subsystems (2)
lore
Share & tools
lore

Yiyuan Guo

author
#0 lore raw

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 changelog
v1->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
index 943e9e14d1e9..b72d39fc2434 100644
@@ -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
maintainer
#1 lore raw
Quoted 6 lines · On Fri, 30 Jun 2023 22:37:19 +0800 Yiyuan Guo <[email protected]> wrote:

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.

Hi. I'm sitting on this one for a couple of reasons.
1) No fixes tag (replying to this thread with one is fine)
2) Various people commented on earlier versions, and I'm waiting for them to confirm they are fine with this version.

If I hear nothing in a few more weeks I'll try and figure out the fixes tag + whether all the reviewer comments have been addressed.

Jonathan

Quoted 23 lines

---
v2->v3:
* Added R-b tag from Tzung-Bi Shih
* Aligned the code by adding an extra tab before "max"
* Added a patch changelog
v1->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
index 943e9e14d1e9..b72d39fc2434 100644
@@ -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)
author
#2 lore raw
Fixes 974e6f02e27e1b46 ("iio: cros_ec_sensors_core: Add common

functions for the ChromeOS EC S…")

Quoted 45 lines · Jonathan Cameron
Quoted 6 lines · On Fri, 30 Jun 2023 22:37:19 +0800 Yiyuan Guo <[email protected]> wrote:

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.

Hi. I'm sitting on this one for a couple of reasons.
1) No fixes tag (replying to this thread with one is fine)
2) Various people commented on earlier versions, and I'm waiting for them to confirm they are fine with this version.

If I hear nothing in a few more weeks I'll try and figure out the fixes tag + whether all the reviewer comments have been addressed.

Jonathan

Quoted 23 lines

---
v2->v3:
* Added R-b tag from Tzung-Bi Shih
* Aligned the code by adding an extra tab before "max"
* Added a patch changelog
v1->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
index 943e9e14d1e9..b72d39fc2434 100644
@@ -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)
#3 lore raw
In reply to Jonathan Cameron

On Sun, Jul 16, 2023 at 02:10:28PM +0100, Jonathan Cameron wrote:
[...]

Quoted 2 lines

2) Various people commented on earlier versions, and I'm waiting for them to confirm they are fine with this version.

The version addressed all my comments and LGTM.

#4 lore raw
Quoted 6 lines · On Mon, 17 Jul 2023 11:09:08 +0800 Tzung-Bi Shih <[email protected]> wrote:

On Sun, Jul 16, 2023 at 02:10:28PM +0100, Jonathan Cameron wrote:
[...]

Quoted 2 lines

2) Various people commented on earlier versions, and I'm waiting for them to confirm they are fine with this version.

The version addressed all my comments and LGTM.

Tag? I can pick up without, but it's nice to record this
formally. Reviewed-by seems appropriate here.

maintainer Applied
#5 lore raw
Quoted 5 lines · On Tue, 18 Jul 2023 10:37:02 +0100 Jonathan Cameron…
Quoted 2 lines · On Mon, 17 Jul 2023 11:09:08 +0800 Tzung-Bi Shih <[email protected]> wrote:

On Sun, Jul 16, 2023 at 02:10:28PM +0100, Jonathan Cameron wrote:
[...]

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

2) Various people commented on earlier versions, and I'm waiting for them to confirm they are fine with this version.

The version addressed all my comments and LGTM.

Tag? I can pick up without, but it's nice to record this
formally. Reviewed-by seems appropriate here.

Applied to the fixes-togreg branch of iio.git.

Note the fixes tag had to be replaced with the full version. No shortening allowed.

Jonathan

#6 lore raw
In reply to Yiyuan Guo
This patch was applied to chrome-platform/linux.git (for-kernelci) by Jonathan Cameron <[email protected]>:

Hello:

This patch was applied to chrome-platform/linux.git (for-kernelci) by Jonathan Cameron <[email protected]>:

Quoted 8 lines · On Fri, 30 Jun 2023 22:37:19 +0800 you wrote:

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.

[...]

Here is the summary with links:
- [v3] iio: cros_ec: Fix the allocation size for cros_ec_command

    https://git.kernel.org/chrome-platform/c/8a4629055ef5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#7 lore raw
In reply to Yiyuan Guo
This patch was applied to chrome-platform/linux.git (for-next) by Jonathan Cameron <[email protected]>:

Hello:

This patch was applied to chrome-platform/linux.git (for-next) by Jonathan Cameron <[email protected]>:

Quoted 8 lines · On Fri, 30 Jun 2023 22:37:19 +0800 you wrote:

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.

[...]

Here is the summary with links:
- [v3] iio: cros_ec: Fix the allocation size for cros_ec_command

    https://git.kernel.org/chrome-platform/c/8a4629055ef5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html