From: sashiko-bot@kernel.org
To: "Pei Xiao" <xiaopei01@kylinos.cn>
Cc: cassel@kernel.org, linux-ide@vger.kernel.org, dlemoal@kernel.org
Subject: Re: [PATCH v2] ata: pata_parport: Fix use-after-free in new_device_store
Date: Thu, 30 Jul 2026 03:29:22 +0000 [thread overview]
Message-ID: <20260730032922.AA9171F000E9@smtp.kernel.org> (raw)
In-Reply-To: <77dad1184ebd0e1e7ea541d4207568f8bc5ec01f.1785381141.git.xiaopei01@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Iterating over multiple protocols without breaking after a successful probe causes a permanent deadlock on `parport_claim_or_block()`.
- [High] The `new_device` sysfs attribute does not enforce positive bounds for `mode`, `unit`, and `delay`, allowing negative values that cause out-of-bounds array accesses and CPU stalls.
--
--- Patch [1]: [PATCH v2] ata: pata_parport: Fix use-after-free in new_device_store ---
commit 0903251c06a3e624fab8c81fa244b1596978b12b
Author: Pei Xiao <xiaopei01@kylinos.cn>
ata: pata_parport: Fix use-after-free in new_device_store
The function new_device_store() calls driver_find() without protection against
concurrent driver unregistration. This commit expands the critical section
protected by pi_mutex to fix a use-after-free.
Link: https://lore.kernel.org/lkml/20260728024015.2014674-1-shuangpeng.kernel@gmail.com/
> diff --git a/drivers/ata/pata_parport/pata_parport.c b/drivers/ata/pata_parport/pata_parport.c
> --- a/drivers/ata/pata_parport/pata_parport.c
> +++ b/drivers/ata/pata_parport/pata_parport.c
[ ... ]
> @@ -646,18 +647,18 @@ static ssize_t new_device_store(const struct bus_type *bus, const char *buf, siz
> port_wanted = -1;
> }
>
[Severity: High]
This is a pre-existing issue, but does this function properly validate the
bounds of user input for mode, unit, and delay?
If negative integers are provided in the sysfs write to new_device, they are
parsed as signed integers:
if (sscanf(buf, "%11s %7s %d %d %d",
port, protocol, &mode, &unit, &delay) < 1)
These negative values can bypass upper-bound checks and be used as array
indices:
drivers/ata/pata_parport/bpck6.c:bpck6_send_cmd() {
...
switch (mode_map[pi->mode]) {
...
}
A negative delay can also be cast to a large unsigned value in udelay(),
potentially causing a permanent CPU stall:
drivers/ata/pata_parport/pata_parport.h:delay_p() {
#define delay_p (pi->delay ? udelay(pi->delay) : (void)0)
}
Could we enforce positive bounds for these parameters?
> + mutex_lock(&pi_mutex);
> drv = driver_find(protocol, &pata_parport_bus_type);
> if (!drv) {
> if (strcmp(protocol, "auto")) {
> pr_err("protocol %s not found\n", protocol);
> + mutex_unlock(&pi_mutex);
> return -EINVAL;
> }
> pr_wanted = NULL;
> } else {
> pr_wanted = container_of(drv, struct pi_protocol, driver);
> }
> -
> - mutex_lock(&pi_mutex);
> /* walk all parports */
> idr_for_each_entry(&parport_list, parport, port_num) {
> if (port_num == port_wanted || port_wanted == -1) {
[Severity: High]
This isn't a bug introduced by this patch, but does the protocol iteration
loop handle successful probes safely?
In the subsequent code in new_device_store():
/* walk all protocols */
idr_for_each_entry(&protocols, pr, pr_num) {
if (pr == pr_wanted || !pr_wanted)
if (pi_init_one(parport, pr, mode, unit,
delay))
ok = true;
}
And similarly in pata_parport_attach():
/* probe this port using all protocols */
idr_for_each_entry(&protocols, pr, pr_num)
pi_init_one(port, pr, -1, -1, -1);
If a protocol successfully initializes, it claims the parport exclusively.
However, the loop doesn't break upon success and continues trying the next
protocol.
When the next protocol calls pi_init_one() and attempts to claim the exact
same port, it will block indefinitely in parport_claim_or_block() because
the port is already locked by the first protocol.
Could this result in a permanent deadlock during sysfs-driven instantiation
or module loading?
--
Sashiko AI review · https://sashiko.dev/#/patchset/77dad1184ebd0e1e7ea541d4207568f8bc5ec01f.1785381141.git.xiaopei01@kylinos.cn?part=1
prev parent reply other threads:[~2026-07-30 3:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 3:16 [PATCH v2] ata: pata_parport: Fix use-after-free in new_device_store Pei Xiao
2026-07-30 3:29 ` sashiko-bot [this message]
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=20260730032922.AA9171F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=cassel@kernel.org \
--cc=dlemoal@kernel.org \
--cc=linux-ide@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=xiaopei01@kylinos.cn \
/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;
as well as URLs for NNTP newsgroup(s).