All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] s390/tape: cancel delayed work on device removal
@ 2026-10-19 22:56 Tristan Madani
  2026-10-19 23:07 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Tristan Madani @ 2026-10-19 22:56 UTC (permalink / raw)
  To: Heiko Carstens, Vasily Gorbik
  Cc: Stefan Bader, linux-s390, stable, Tristan Madani

From: Tristan Madani <tristan@talencesecurity.com>

tape_generic_remove() drops the device reference without cancelling
the pending delayed work tape_dnr. If tape_delayed_next_request() is
still scheduled or running when the struct is freed on the final
reference drop, the work function dereferences freed memory.

The cancel cannot go in tape_put_device() because that function is
called from atomic context (under get_ccwdev_lock with interrupts
disabled) and from within the work function itself, both of which
would deadlock or sleep in atomic context with cancel_delayed_work_sync().

Add cancel_delayed_work_sync() in tape_generic_remove() after
dev_set_drvdata() clears the device pointer and before dropping the
final reference. At this point the spinlock is not held and the device
is no longer reachable for new operations.

Fixes: 4111796d89b8c ("[PATCH] s390: channel tape fixes")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
Changes in v2:
- Moved cancel from tape_put_device() to tape_generic_remove().
  tape_put_device() is called from atomic context (under spinlock with
  IRQs disabled) and from within tape_delayed_next_request() itself,
  so cancel_delayed_work_sync() there would deadlock or sleep in atomic.
  tape_generic_remove() runs in process context with no locks held.
 drivers/s390/char/tape_core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/s390/char/tape_core.c b/drivers/s390/char/tape_core.c
index bd8e3deb11993..cb5db2cabd21a 100644
--- a/drivers/s390/char/tape_core.c
+++ b/drivers/s390/char/tape_core.c
@@ -662,6 +662,7 @@ tape_generic_remove(struct ccw_device *cdev)
 	if (device) {
 		sysfs_remove_group(&cdev->dev.kobj, &tape_attr_group);
 		dev_set_drvdata(&cdev->dev, NULL);
+		cancel_delayed_work_sync(&device->tape_dnr);
 		tape_put_device(device);
 	}
 }
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] s390/tape: cancel delayed work on device removal
  2026-10-19 22:56 [PATCH v2] s390/tape: cancel delayed work on device removal Tristan Madani
@ 2026-10-19 23:07 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-10-19 23:07 UTC (permalink / raw)
  To: Tristan Madani
  Cc: linux-s390, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger

> From: Tristan Madani <tristan@talencesecurity.com>
> 
> tape_generic_remove() drops the device reference without cancelling
> the pending delayed work tape_dnr. If tape_delayed_next_request() is
> still scheduled or running when the struct is freed on the final
> reference drop, the work function dereferences freed memory.
> 
> The cancel cannot go in tape_put_device() because that function is
> called from atomic context (under get_ccwdev_lock with interrupts
> disabled) and from within the work function itself, both of which
> would deadlock or sleep in atomic context with cancel_delayed_work_sync().
> 
> Add cancel_delayed_work_sync() in tape_generic_remove() after
> dev_set_drvdata() clears the device pointer and before dropping the
> final reference. At this point the spinlock is not held and the device
> is no longer reachable for new operations.
> 
> Fixes: 4111796d89b8c ("[PATCH] s390: channel tape fixes")
> Cc: stable@vger.kernel.org
> Signed-off-by: Tristan Madani <tristan@talencesecurity.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261019225606.1864082-1-tristmd@gmail.com?part=1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-19 23:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-19 22:56 [PATCH v2] s390/tape: cancel delayed work on device removal Tristan Madani
2026-10-19 23:07 ` sashiko-bot

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.