public inbox for chrome-platform@lists.linux.dev
 help / color / mirror / Atom feed
From: Yiyuan Guo <yguoaz@gmail.com>
To: jic23@kernel.org, lars@metafoo.de, bleung@chromium.org,
	groeck@chromium.org
Cc: dianders@chromium.org, mazziesaccount@gmail.com,
	gwendal@chromium.org, linux-iio@vger.kernel.org,
	chrome-platform@lists.linux.dev, yguoaz@gmail.com
Subject: [PATCH] iio: Fix the allocation size for cros_ec_command
Date: Thu, 29 Jun 2023 21:24:05 +0800	[thread overview]
Message-ID: <20230629132405.1237292-1-yguoaz@gmail.com> (raw)

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.

Signed-off-by: Yiyuan Guo <yguoaz@gmail.com>
---
 drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index 943e9e14d1e9..e4c01f1072bd 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -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;
-- 
2.25.1


             reply	other threads:[~2023-06-29 13:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-29 13:24 Yiyuan Guo [this message]
2023-06-30  5:13 ` [PATCH] iio: Fix the allocation size for cros_ec_command Tzung-Bi Shih
2023-06-30  6:31 ` [PATCH v2] iio: cros_ec: " Yiyuan Guo
2023-06-30  7:36   ` Tzung-Bi Shih
2023-06-30  8:31     ` [PATCH v3] " Yiyuan Guo
2023-06-30 14:06       ` Guenter Roeck
2023-06-30 14:42         ` yguoaz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230629132405.1237292-1-yguoaz@gmail.com \
    --to=yguoaz@gmail.com \
    --cc=bleung@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=dianders@chromium.org \
    --cc=groeck@chromium.org \
    --cc=gwendal@chromium.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=mazziesaccount@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox