mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: duoming@zju.edu.cn
To: "Greg KH" <gregkh@linuxfoundation.org>
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	jikos@kernel.org, dsterba@suse.com, jirislaby@kernel.org,
	kuba@kernel.org, alexander.deucher@amd.com,
	akpm@linux-foundation.org, pkshih@realtek.com, tglx@kernel.org,
	mingo@kernel.org
Subject: Re: [PATCH] tty: ipwireless: Fix use-after-free in tasklet during device removal
Date: Sun, 8 Feb 2026 22:53:26 +0800 (GMT+08:00)	[thread overview]
Message-ID: <7ece79f6.6d747.19c3dbe4a1f.Coremail.duoming@zju.edu.cn> (raw)
In-Reply-To: <2026020814-aorta-reptilian-e91a@gregkh>

On Sun, 8 Feb 2026 15:34:49 +0100 Greg KH wrote:
> > > > > > When IPWireless PCMCIA card is being detached, the ipw_hardware is
> > > > > > deallocated in ipwireless_hardware_free(). However, the hw->tasklet may
> > > > > > still be running or pending, leading to use-after-free bugs when the
> > > > > > already freed ipw_hardware is accessed again in ipwireless_do_tasklet().
> > > > > 
> > > > > Nice, do you have this hardware to test this with?
> > > > 
> > > > I don't have the real hardware. In order to reproduce the bug, I simulate 
> > > > the IPWireless PCMCIA card in the qemu by allocating and configuring the 
> > > > necessary resources(I/O ports, memory regions, interrupts and so on) to
> > > > correspond with the hardware expected by the driver in the initialization 
> > > > code of the virtual device.
> > > 
> > > I wonder if this device even is still around, given that pcmcia is all
> > > but dead for a very long time.
> > > 
> > > > > > One race condition scenario is as follows:
> > > > > > 
> > > > > > CPU 0 (cleanup)               | CPU 1 (interrupt)
> > > > > > ipwireless_hardware_free()    | ipwireless_interrupt()
> > > > > >   ipwireless_stop_interrupts()|   ipwireless_handle_v1_interrupt()
> > > > > >     do_close_hardware()       |     tasklet_schedule()
> > > > > >       synchronize_irq()       |
> > > > > >   kfree(hw) //FREE            | ipwireless_do_tasklet() //handler
> > > > > >                               |   hw = from_tasklet() //USE
> > > > > >                               |   hw-> //USE
> > > > > > 
> > > > > > Fix this by ensuring hw->tasklet is properly canceled before ipw_hardware
> > > > > > is released. Add tasklet_kill() in ipwireless_stop_interrupts() to
> > > > > > synchronize with any pending or running tasklet. Since do_close_hardware()
> > > > > > could prevent further interrupts, place tasklet_kill() after it to avoid
> > > > > > the tasklet being rescheduled by ipwireless_interrupt().
> > > > > 
> > > > > How was this issue found and tested?
> > > > 
> > > > The issue was found by static analysis. I test it through the following steps:
> > > > 1. Simulating the IPWireless PCMCIA device in the qemu and enable it to trigger interrupts.
> > > > 2. Controlling the removal and attachment of device via sysfs.
> > > 
> > > So this is with the bind/unbind logic, or some other way?  If you are
> > > unloading the driver, that is something that only root can do, and this
> > > is a debugging facility, not a "real" way to control drivers and devices
> > > (yes, the virt drivers abuse this to no end, every time I see this I
> > > laugh...)
> > 
> > When the PCMCIA device is attached, we can operate the file
> > /sys/bus/pcmcia/devices/.../remove to detach the device.
> 
> 'remove' should be removing the driver from the device, something that
> is only allowed by root and is not a normal operation at all.  race
> conditions there are "at your own risk" for all drivers as it's pretty
> much the same as unloading the module, it is there for developer ease
> only.

I did this only to verify the existence of the bug. In real word scenarios,
the device removal code can be triggered by removing the real pcmcia hardware.

> > > > 3. Triggering interrupts by writing data to device registers via /dev/mem memory mapping
> > > >    in userspace.
> > > 
> > > Interrupts would not happen if the device is removed.  Or is this only
> > > if the driver is unbound?
> > 
> > The interrupts should be triggered before the deivce is removed.
> 
> But when the device is physically removed from the system, no more
> interrupts will happen.

I think the tasklet is a deferred mechanism. Although interrupts cannot
happen after device is removed, the tasklet handler may still be executing
or pending. This is why tasklet_kill() needs to be added.

Best regards,
Duoming Zhou

  reply	other threads:[~2026-02-08 14:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-08  6:25 Duoming Zhou
2026-02-08  6:38 ` Greg KH
2026-02-08 10:28   ` duoming
2026-02-08 11:00     ` Greg KH
2026-02-08 13:57       ` duoming
2026-02-08 14:34         ` Greg KH
2026-02-08 14:53           ` duoming [this message]
2026-02-08 14:58             ` Greg KH
2026-02-08 17:25       ` Jiri Kosina
2026-02-09 10:21         ` David Sterba
2026-02-17  8:03           ` Jiri Slaby
2026-02-18 15:23             ` David Sterba
2026-03-09 11:18               ` Qingfang Deng
2026-03-09 11:25                 ` Greg KH

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=7ece79f6.6d747.19c3dbe4a1f.Coremail.duoming@zju.edu.cn \
    --to=duoming@zju.edu.cn \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.deucher@amd.com \
    --cc=dsterba@suse.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jikos@kernel.org \
    --cc=jirislaby@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=pkshih@realtek.com \
    --cc=tglx@kernel.org \
    /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

all inboxes | Powered by JetHome®