All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pragnesh Papaniya" <pragnesh.papaniya@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH RFC 04/10] PM / devfreq: Add new target_freq attribute flag for governors
Date: Fri, 24 Jul 2026 07:35:54 +0000	[thread overview]
Message-ID: <20260724073554.B307C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260724-rfc_v8_scmi_memlat-v1-4-cb732bcff1f4@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] An ABBA deadlock between kernfs active references and `devfreq_list_lock` can occur when a sysfs attribute in `gov_attr_group` is accessed concurrently with a governor switch.
- [High] Reading the `governor` sysfs attribute can cause a Use-After-Free due to a missing lock.
--

--- Patch [4]: [PATCH RFC 04/10] PM / devfreq: Add new target_freq attribute flag for governors ---
commit 270fe8b349c3594b09be3beb4f4386f10ac713aa
Author: Sibi Sankar <sibi.sankar@oss.qualcomm.com>

PM / devfreq: Add new target_freq attribute flag for governors

This commit adds a new DEVFREQ_GOV_ATTR_TARGET_FREQ flag for devfreq governors.
It gates the existing target_freq sysfs read on this flag, returning -EINVAL
if the active governor does not advertise it.

> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index f08fc6966eaee..2f27a239e34a6 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -1530,6 +1530,12 @@ static ssize_t target_freq_show(struct device *dev,
>  {
>  	struct devfreq *df = to_devfreq(dev);
>  
> +	guard(mutex)(&devfreq_list_lock);
> +

[Severity: High]
This isn't a bug introduced by this patch, but since we are modifying the
devfreq sysfs locking here, could there be an ABBA deadlock between kernfs
active references and devfreq_list_lock involving the governor attributes?

If a userspace process writes to the governor sysfs file, governor_store()
takes devfreq_list_lock and calls sysfs_update_group():

drivers/devfreq/devfreq.c:governor_store() {
    ...
    ret = sysfs_update_group(&df->dev.kobj, &gov_attr_group);
    ...
}

This causes create_files() to unconditionally remove the group's attributes
(like timer) via kernfs_remove_by_name(), which waits for all active
references to drain:

fs/sysfs/group.c:create_files() {
    ...
    kernfs_remove_by_name(parent, (*attr)->name);
    ...
}

Concurrently, if another userspace process reads the timer sysfs file:

drivers/devfreq/devfreq.c:timer_show() {
    ...
    guard(mutex)(&devfreq_list_lock);
    ...
}

The sysfs core holds the active reference to the timer node and calls
timer_show(), which blocks trying to acquire devfreq_list_lock, completing
the ABBA deadlock.

[Severity: High]
This is a pre-existing issue, but while we are adding devfreq_list_lock here
to safely access the governor, does governor_show() have a Use-After-Free
risk because it lacks this lock?

If governor_show() accesses df->governor without holding devfreq_list_lock:

drivers/devfreq/devfreq.c:governor_show() {
    ...
    return sprintf(buf, "%s\n", df->governor->name);
}

Concurrently, if a governor module is unloaded, devfreq_remove_governor()
acquires devfreq_list_lock, stops the governor, and clears df->governor.
After it returns, the module memory is freed. If governor_show() evaluates
df->governor as non-NULL before it's cleared, gets preempted, and then
resumes after the module is freed, could the dereference of
df->governor->name access freed memory?

> +	if (!df->profile || !df->governor ||
> +	    !IS_SUPPORTED_ATTR(df->governor->attrs, TARGET_FREQ))
> +		return -EINVAL;
> +
>  	return sprintf(buf, "%lu\n", df->previous_freq);
>  }

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260724-rfc_v8_scmi_memlat-v1-0-cb732bcff1f4@oss.qualcomm.com?part=4

  reply	other threads:[~2026-07-24  7:35 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24  7:18 [PATCH RFC 00/10] firmware: arm_scmi: vendors: Qualcomm Generic Vendor Extensions Pragnesh Papaniya
2026-07-24  7:18 ` [PATCH RFC 01/10] firmware: arm_scmi: Add SCMI QCOM Generic Extension Protocol documentation Pragnesh Papaniya
2026-07-24  7:27   ` sashiko-bot
2026-07-24  9:13   ` Sudeep Holla
2026-07-24  7:18 ` [PATCH RFC 02/10] dt-bindings: firmware: arm,scmi: Add Qualcomm Generic Extension Protocol Pragnesh Papaniya
2026-07-24  7:28   ` sashiko-bot
2026-07-24  7:18 ` [PATCH RFC 03/10] firmware: arm_scmi: vendors: Add QCOM SCMI Generic Extensions Pragnesh Papaniya
2026-07-24  7:30   ` sashiko-bot
2026-07-24  7:18 ` [PATCH RFC 04/10] PM / devfreq: Add new target_freq attribute flag for governors Pragnesh Papaniya
2026-07-24  7:35   ` sashiko-bot [this message]
2026-07-24  7:18 ` [PATCH RFC 05/10] PM / devfreq: Add new track_remote " Pragnesh Papaniya
2026-07-24  7:31   ` sashiko-bot
2026-07-24  7:18 ` [PATCH RFC 06/10] PM / devfreq: Add a governor for tracking remote device frequencies Pragnesh Papaniya
2026-07-24  7:33   ` sashiko-bot
2026-07-24  7:18 ` [PATCH RFC 07/10] PM / devfreq: Introduce the QCOM SCMI Memlat devfreq driver Pragnesh Papaniya
2026-07-24  7:18 ` [PATCH RFC 08/10] arm64: dts: qcom: glymur: Enable LLCC/DDR/DDR_QOS DVFS Pragnesh Papaniya
2026-07-24  7:18 ` [PATCH RFC 09/10] arm64: dts: qcom: hamoa: " Pragnesh Papaniya
2026-07-24  7:18 ` [PATCH RFC 10/10] arm64: dts: qcom: kaanapali: " Pragnesh Papaniya
2026-07-24  8:40 ` [PATCH RFC 00/10] firmware: arm_scmi: vendors: Qualcomm Generic Vendor Extensions Sudeep Holla
2026-07-24  9:02   ` Pragnesh Papaniya

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=20260724073554.B307C1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=pragnesh.papaniya@oss.qualcomm.com \
    --cc=robh@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.