From: sashiko-bot@kernel.org
To: "Jihong Min" <hurryman2212@gmail.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH 3/5] hwmon: Add a generic interface for userspace implementations
Date: Fri, 09 Oct 2026 15:56:25 +0000 [thread overview]
Message-ID: <sashiko-outbox-165801@kernel.org> (raw)
In-Reply-To: <27071a389536dfbc35b628a50e90636ce012c21f.1791559095.git.hurryman2212@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] hwmon: O(N^2) attribute validation loop causes CPU soft lockup
- [High] sysfs: 1-byte buffer overflow in hwmon_attr_show_string due to PAGE_SIZE limit
- [Medium] driver-core: invalid teardown order in uhwmon_exit() destroys parent before children
--
commit c2824f78f1fac4c2c5b17a97b2a2b5679a625be3
Author: Jihong Min <hurryman2212@gmail.com>
hwmon: Add a generic interface for userspace implementations
Add /dev/uhwmon so userspace drivers can expose standard hwmon
attributes. Use the shared hwmon identifiers directly and forward
numeric values or labels through read and write requests.
> diff --git a/drivers/hwmon/uhwmon.c b/drivers/hwmon/uhwmon.c
> new file mode 100644
> index 0000000000000..1855c87f06d9d
> --- /dev/null
> +++ b/drivers/hwmon/uhwmon.c
> @@ -0,0 +1,641 @@
> [ ... ]
> +static int uhwmon_create(struct file *file, void __user *arg)
> +{
> [ ... ]
> + for (i = 0; i < data->num_attrs; i++) {
> + struct uhwmon_attr *attr = &data->attrs[i];
> + u32 type;
> + bool string;
> +
> + ret = -EINVAL;
> + if (spec[i].attr >= 32 ||
> + !hwmon_is_valid_attr(spec[i].type, spec[i].attr) ||
> + !spec[i].mode || spec[i].mode & ~0644 ||
> + spec[i].flags & ~UHWMON_ATTR_CONSTANT)
> + goto out;
> + if (spec[i].type == hwmon_chip && spec[i].channel)
> + goto out;
> + /*
> + * N is a zero-based channel index: channels 0..N need at least
> + * N + 1 attribute slots, plus a NULL terminator. The core uses
> + * int counts, so N + 2 <= INT_MAX. The full count is checked below.
> + */
> + if (spec[i].channel > INT_MAX - 2) {
> + ret = -EOVERFLOW;
> + goto out;
> + }
> + string = hwmon_is_string_attr(spec[i].type, spec[i].attr);
> + if (string) {
> + if (!spec[i].size || spec[i].size > PAGE_SIZE ||
> + spec[i].mode & 0222 || spec[i].value)
> + goto out;
[Severity: High]
Does this PAGE_SIZE check leave enough room for the newline character appended
by the hwmon core?
If a daemon writes a string of length PAGE_SIZE - 1 plus a null terminator,
when read via sysfs, the hwmon core passes this string to
sprintf(buf, "%s\n", s) where buf is exactly PAGE_SIZE bytes.
This would write PAGE_SIZE - 1 characters, followed by the newline and null
terminator, totaling PAGE_SIZE + 1 bytes.
Could this cause a 1-byte overflow and memory corruption?
> + } else if (spec[i].size || spec[i].text) {
> + goto out;
> + }
> [ ... ]
> + type = spec[i].type == hwmon_energy64 ? hwmon_energy :
> + spec[i].type;
> + for (j = 0; j < i; j++) {
> + u32 other_type = spec[j].type == hwmon_energy64 ?
> + hwmon_energy :
> + spec[j].type;
> +
> + if (type == other_type &&
> + spec[i].attr == spec[j].attr &&
> + spec[i].channel == spec[j].channel)
> + goto out;
> + }
[Severity: High]
Can this nested loop cause a CPU soft lockup?
Since uhwmon_create() accepts a user-provided num_attrs bounded only by
kmalloc limits (which could exceed 100,000 attributes depending on max slab
size), this loop compares every attribute against all preceding attributes to
prevent duplicates.
For a large number of attributes, this results in billions of iterations.
As the loop lacks preemption points like cond_resched(), could it hold the
CPU exclusively for multiple seconds and trigger the soft lockup watchdog?
> + attr->spec = spec[i];
> + attr->spec.text = 0;
> + counts[spec[i].type] =
> + max(counts[spec[i].type], spec[i].channel + 1);
> + }
> [ ... ]
> +static void __exit uhwmon_exit(void)
> +{
> + struct uhwmon_device *data, *next;
> +
> + misc_deregister(&uhwmon_misc);
> + list_for_each_entry_safe(data, next, &uhwmon_devices, node) {
> + uhwmon_unregister(data);
> + list_del(&data->node);
> + uhwmon_free(data);
> + }
> +}
[Severity: Medium]
Is it safe to deregister the parent miscdevice before unregistering the child
hwmon devices?
Calling misc_deregister() destroys uhwmon_misc.this_device, which is the
parent of all registered hwmon devices. Destroying a parent device before its
children violates the driver core's topological ordering and lifecycle rules.
Could this cause sysfs warnings and potential use-after-free when the children
subsequently attempt to unregister their sysfs directories from the
already-deleted parent?
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791531025.git.hurryman2212@gmail.com?part=3
next prev parent reply other threads:[~2026-10-09 15:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 15:38 [PATCH 0/5] hwmon: Introduce uhwmon for userspace implementations Jihong Min
2026-10-09 15:38 ` [PATCH 1/5] hwmon: Export sensor and attribute definitions to userspace Jihong Min
2026-10-09 15:49 ` sashiko-bot
2026-10-09 15:38 ` [PATCH 2/5] hwmon: Expose attribute validation and string helpers Jihong Min
2026-10-09 15:47 ` sashiko-bot
2026-10-09 15:38 ` [PATCH 3/5] hwmon: Add a generic interface for userspace implementations Jihong Min
2026-10-09 15:56 ` sashiko-bot [this message]
2026-10-10 14:50 ` Markus Elfring
2026-10-09 15:38 ` [PATCH 4/5] hwmon: Reject truncated attribute names Jihong Min
2026-10-09 15:44 ` sashiko-bot
2026-10-09 15:38 ` [PATCH 5/5] docs: hwmon: Document the uhwmon userspace interface Jihong Min
2026-10-09 15:55 ` 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-165801@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=hurryman2212@gmail.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