Linux ATA/IDE development
 help / color / mirror / Atom feed
From: Niklas Cassel <cassel@kernel.org>
To: sashiko-reviews@lists.linux.dev
Cc: Pei Xiao <xiaopei01@kylinos.cn>,
	linux-ide@vger.kernel.org, dlemoal@kernel.org,
	Ondrej Zary <linux@zary.sk>
Subject: Re: [PATCH v2 2/2] ata: pata_parport: unregister devices on protocol unregister
Date: Wed, 9 Sep 2026 12:48:07 +0200	[thread overview]
Message-ID: <aqE5Z00G5h4XmtHA@ryzen> (raw)
In-Reply-To: <20260908120855.9F34F1F00A3A@smtp.kernel.org>

On Tue, Sep 08, 2026 at 12:08:55PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> 
> Pre-existing issues:
> - [High] pata_parport_attach fails for all parports except port 0
> --
> 
> commit b043c5b13721ce815e34642853318549a000ffd3
> Author: Pei Xiao <xiaopei01@kylinos.cn>
> 
> ata: pata_parport: unregister devices on protocol unregister
> 
> When a protocol module registers multiple protocols and a later
> registration fails, the rollback path unregisters the protocol but leaves
> dynamically created devices untouched. Later removal of these dangling
> devices dereferences freed module memory, crashing the kernel. This commit
> tears down all pi_adapters using the protocol before unregistering the
> driver.
> 
> > diff --git a/drivers/ata/pata_parport/pata_parport.c b/drivers/ata/pata_parport/pata_parport.c
> > index 046ab7e3adbcf..712209882ab75 100644
> > --- a/drivers/ata/pata_parport/pata_parport.c
> > +++ b/drivers/ata/pata_parport/pata_parport.c
> [ ... ]
> 
> While reviewing this, I noticed a pre-existing issue in pata_parport_attach():
> 
> drivers/ata/pata_parport/pata_parport.c:pata_parport_attach() {
>     ...
> 	mutex_lock(&pi_mutex);
> 	id = idr_alloc(&parport_list, port, port->number, port->number,
> 		       GFP_KERNEL);
> 	if (id < 0) {
>     ...
> }

> 
> [Severity: High]
> This is a pre-existing issue, but does this idr_alloc() call fail for all
> parports except port 0?
> 
> Since the end parameter of idr_alloc() is exclusive, when port->number > 0,
> it computes max = end - 1. Because start is equal to port->number, the
> condition start > max evaluates to true, causing it to return -ENOSPC.
> 
> Would this cause attaching any parport with a number greater than 0 to
> silently fail and completely break functionality for those ports?

Looking at idr_alloc(), this looks like a legit pre-existing issue.

There is another call to idr_alloc() i pata_parport_register_driver(),
but it does:
error = idr_alloc(&protocols, pr, 0, 0, GFP_KERNEL);

0,0 is start,end

if @end is <= 0, it is treated as one larger than %INT_MAX

So this is only a problem in pata_parport_attach().



Kind regards,
Niklas

  reply	other threads:[~2026-09-09 10:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08 11:47 [PATCH v2 0/2] ata: pata_parport: fix UAF on protocol module unload Pei Xiao
2026-09-08 11:47 ` [PATCH v2 1/2] ata: pata_parport: pin the protocol module before device_register() Pei Xiao
2026-09-08 11:47 ` [PATCH v2 2/2] ata: pata_parport: unregister devices on protocol unregister Pei Xiao
2026-09-08 12:08   ` sashiko-bot
2026-09-09 10:48     ` Niklas Cassel [this message]
2026-09-09 10:52 ` [PATCH v2 0/2] ata: pata_parport: fix UAF on protocol module unload Niklas Cassel
2026-09-10 17:19   ` Niklas Cassel

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=aqE5Z00G5h4XmtHA@ryzen \
    --to=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux@zary.sk \
    --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