Linux ATA/IDE development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pei Xiao" <xiaopei01@kylinos.cn>
Cc: cassel@kernel.org, dlemoal@kernel.org, linux-ide@vger.kernel.org
Subject: Re: [PATCH] ata: pata_parport: Fix missing module refcount for pata_parport itself
Date: Thu, 30 Jul 2026 08:25:54 +0000	[thread overview]
Message-ID: <20260730082554.B2C161F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <a8d9807618ab786313654099c904d613075e1b63.1785398816.git.xiaopei01@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Circular dependency permanently preventing module unloading.
- [High] Race condition leading to Use-After-Free during device release.
--

--- Patch [1]: [PATCH] ata: pata_parport: Fix missing module refcount for pata_parport itself ---
commit 35d67ec0c667d20f10f4b6d490918bd71ccafa32
Author: Pei Xiao <xiaopei01@kylinos.cn>

ata: pata_parport: Fix missing module refcount for pata_parport itself

This commit adds a module reference count for the pata_parport core module
during device initialization and drops it during device release. This is
intended to prevent the module from being unloaded while devices are still
attached.

> diff --git a/drivers/ata/pata_parport/pata_parport.c b/drivers/ata/pata_parport/pata_parport.c
> index 40baeac594a9f..6de237602a13e 100644
> --- a/drivers/ata/pata_parport/pata_parport.c
> +++ b/drivers/ata/pata_parport/pata_parport.c
> @@ -455,6 +455,12 @@ static void pata_parport_dev_release(struct device *dev)
>  {
>  	struct pi_adapter *pi = container_of(dev, struct pi_adapter, dev);
>  
> +	/*
> +	 * pi->proto is NULL when device_register() fails early,
> +	 * before __module_get() was called -- skip module_put().
> +	 */
> +	if (pi->proto)
> +		module_put(THIS_MODULE);

[Severity: High]
Does this create a race condition where the module could be unloaded while
pata_parport_dev_release() is still executing?

If module_put() drops the final reference to the module, a concurrent module
unload could unmap the module's memory. The remaining instructions in this
function, including the call to ida_free() which accesses the static
pata_parport_bus_dev_ids structure, would then be executing in freed memory.

>  	ida_free(&pata_parport_bus_dev_ids, dev->id);
>  	kfree(pi);
>  }

[ ... ]

> @@ -524,6 +530,8 @@ static struct pi_adapter *pi_init_one(struct parport *parport,
>  
>  	pi->proto = pr;
>  
> +	__module_get(THIS_MODULE);
> +

[Severity: High]
Will this prevent the module from ever being unloaded?

Normally, the driver's exit function (pata_parport_exit) would unregister the
driver, which in turn detaches devices and drops their references. By taking a
module reference for every attached device, the module reference count will
never reach zero while devices exist, making pata_parport_exit() unreachable
via standard unload operations.

>  	if (!try_module_get(pi->proto->owner))
>  		goto out_unreg_dev;
>  	if (pi->proto->init_proto && pi->proto->init_proto(pi) < 0)

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/a8d9807618ab786313654099c904d613075e1b63.1785398816.git.xiaopei01@kylinos.cn?part=1

      reply	other threads:[~2026-07-30  8:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30  8:13 [PATCH] ata: pata_parport: Fix missing module refcount for pata_parport itself Pei Xiao
2026-07-30  8:25 ` 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=20260730082554.B2C161F00A3A@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