Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Benedikt Niedermayr" <benedikt.niedermayr@siemens.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v2 1/2] hwmon: simatic-ipc-ec-sensors: add BX-54A EC driver
Date: Thu, 19 Nov 2026 16:18:02 +0000	[thread overview]
Message-ID: <sashiko-outbox-223506@kernel.org> (raw)
In-Reply-To: <20261119160210.1257890-2-benedikt.niedermayr@siemens.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] hwmon: shared mutable temp config array in
  simatic_ipc_ec_hwmon_probe()
--

commit d1d68eaeccfb28c478d4c0f38bfdd8c663f3ba61
Author: Benedikt Niedermayr <benedikt.niedermayr@siemens.com>

hwmon: simatic-ipc-ec-sensors: add BX-54A EC driver

This commit adds a hardware monitoring driver for temperature sensors and
fan control on the embedded controller of Siemens SIMATIC IPC BX-54A
systems.

> diff --git a/drivers/hwmon/simatic-ipc-ec-sensors.c b/drivers/hwmon/simatic-ipc-ec-sensors.c
> new file mode 100644
> index 0000000000000..05a48faaa1b0d
> --- /dev/null
> +++ b/drivers/hwmon/simatic-ipc-ec-sensors.c

[ ... ]

> +/*
> + * The number of temperature sensor's channels comes from ACPI as it may be different for
> + * different projects. One extra zeroed entry terminates the array.
> + */
> +static u32 simatic_ipc_ec_temp_config[TEMP_MAX_CHANNELS + 1];
> +
> +static struct hwmon_channel_info simatic_ipc_ec_temp_ch_info = {
> +	.type = hwmon_temp,
> +	.config = simatic_ipc_ec_temp_config,
> +};
> +
> +static const struct hwmon_channel_info * const simatic_ipc_ec_hwmon_ch_info[] = {
> +	&simatic_ipc_ec_temp_ch_info,
> +	NULL
> +};
> +
> +static const struct hwmon_channel_info * const simatic_ipc_ec_fan_ch_info[] = {
> +	HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT | HWMON_F_LABEL),
> +	HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE),
> +	NULL
> +};
> +
> +static const struct hwmon_chip_info simatic_ipc_ec_hwmon_info = {
> +	.ops = &simatic_ipc_ec_ops,
> +	.info = simatic_ipc_ec_hwmon_ch_info,
> +};
> +
> +static const struct hwmon_chip_info simatic_ipc_ec_fan_info = {
> +	.ops = &simatic_ipc_ec_ops,
> +	.info = simatic_ipc_ec_fan_ch_info,
> +};
> +
> +static int simatic_ipc_ec_hwmon_probe(struct device *dev, struct simatic_ipc_ec_sensor *data)
> +{
> +	struct simatic_ipc_ec_temp *temp;
> +	struct device *hwmon_dev;
> +	u8 temp_count;
> +	u8 temp_base;
> +	u8 value;
> +	int ret;
> +	u8 ch;
> +
> +	ret = device_property_read_u8(dev, "TempRegOffset", &temp_base);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = device_property_read_u8(dev, "TempCount", &temp_count);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (temp_base + temp_count * SIZE_OF_TEMP_REG > 256)
> +		return -EINVAL;
> +
> +	temp = devm_kzalloc(dev, sizeof(*temp), GFP_KERNEL);
> +	if (!temp)
> +		return -ENOMEM;
> +
> +	/* Clear flags left over from a previous probe */
> +	memset(simatic_ipc_ec_temp_config, 0, sizeof(simatic_ipc_ec_temp_config));
> +
> +	temp->base = temp_base;
> +	temp->count = temp_count;
> +
> +	data->temp = temp;
> +
> +	/* Dynamically create temperature sensor channels */
> +	for (ch = 0; ch < temp_count; ch++) {
> +		ret = ec_read(temp_reg(temp_base, ch, TEMP_REG_CTR_STATUS), &value);
> +		if (ret < 0)
> +			return ret;
> +
> +		simatic_ipc_ec_temp_config[ch] |= HWMON_T_INPUT;
> +
> +		if (value & ALARM_SUPPORT)
> +			simatic_ipc_ec_temp_config[ch] |= HWMON_T_MIN | HWMON_T_MAX;
> +
> +		if (value & CRITICAL_SUPPORT)
> +			simatic_ipc_ec_temp_config[ch] |= HWMON_T_CRIT;
> +	}
> +
> +	hwmon_dev = devm_hwmon_device_register_with_info(dev, "simatic_ipc_ec_hwmon",
> +							 data, &simatic_ipc_ec_hwmon_info,
> +							 NULL);

[Severity: Medium]
Can mutating the file-scope simatic_ipc_ec_temp_config[] array in
simatic_ipc_ec_hwmon_probe() corrupt an existing device's configuration or
overflow the attribute array during concurrent probes?

Because hwdev->chip retains a pointer to simatic_ipc_ec_hwmon_info and its
config array for the lifetime of the hwmon device, probing a second
110A5004 instance zeroes and overwrites the channel config backing an
already-registered device.  Also, if two probes run concurrently while
ec_read() sleeps, mutating simatic_ipc_ec_temp_config[] between the
sizing pass (hwmon_num_channel_attrs()) and the population pass
(hwmon_genattrs()) in __hwmon_create_attrs() can write past the end of
the allocated attrs array:

CPU0                                  CPU1
simatic_ipc_ec_hwmon_probe()
  populate simatic_ipc_ec_temp_config
  ...
    __hwmon_create_attrs()
      nattrs = hwmon_num_channel_attrs()
      attrs = kzalloc_objs(..., nattrs + 1)
                                      simatic_ipc_ec_hwmon_probe()
                                        memset(simatic_ipc_ec_temp_config, 0, ...)
                                        for (ch = 0; ch < temp_count; ch++)
                                          ec_read()
                                          simatic_ipc_ec_temp_config[ch] |= ...
      hwmon_genattrs()
        attrs[aindex++] = ...  <-- heap buffer overflow

Could the channel config be allocated per device, or could a const static
config table be paired with dynamic visibility checks in
simatic_ipc_ec_temp_is_visible()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119160210.1257890-1-benedikt.niedermayr@siemens.com?part=1

  reply	other threads:[~2026-11-19 16:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 16:02 [PATCH v2 0/2] hwmon: simatic-ipc-ec-sensors: add BX-54A EC driver Benedikt Niedermayr
2026-11-19 16:02 ` [PATCH v2 1/2] " Benedikt Niedermayr
2026-11-19 16:18   ` sashiko-bot [this message]
2026-11-19 16:02 ` [PATCH v2 2/2] docs: hwmon: introduce simatic-ipc-ec-sensors Benedikt Niedermayr
2026-11-19 16:07   ` sashiko-bot

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=sashiko-outbox-223506@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=benedikt.niedermayr@siemens.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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