Linux Serial subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bradley Morgan" <brads@mainlining.org>
Cc: linux-serial@vger.kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH v2 1/5] media: ivtv: convert to kthread_run_worker
Date: Sat, 05 Sep 2026 09:40:37 +0000	[thread overview]
Message-ID: <20260905094037.AF7E01F00A3F@smtp.kernel.org> (raw)
In-Reply-To: <c38e2e3575040b0a7e580e1d78d8202fe1b8cf06.1788513591.git.brads@mainlining.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] kthread_queue_work() receives a double pointer instead of a pointer to kthread_worker, leading to a build error or runtime memory corruption.
- [High] kthread_destroy_worker() is called before free_irq(), creating a Use-After-Free race condition with the interrupt handler.
--

commit a504d2685cd2f4c4e6b93a81c847d55367eae1c0
Author: Bradley Morgan <brads@mainlining.org>

media: ivtv: convert to kthread_run_worker

Convert ivtv to use kthread_run_worker() instead of the deprecated
kthread_run(kthread_worker_fn) pattern. The new API sets worker->task
before the worker starts.

> diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
> index b9ea56ec9593f..6f0e0e46deb5b 100644
> --- a/drivers/media/pci/ivtv/ivtv-driver.c
> +++ b/drivers/media/pci/ivtv/ivtv-driver.c
[ ... ]
> @@ -1372,8 +1370,8 @@ static void ivtv_remove(struct pci_dev *pdev)
>  	timer_shutdown_sync(&itv->dma_timer);
>  
>  	/* Kill irq worker */
> -	kthread_flush_worker(&itv->irq_worker);
> -	kthread_stop(itv->irq_worker_task);
> +	kthread_flush_worker(itv->irq_worker);
> +	kthread_destroy_worker(itv->irq_worker);

[Severity: High]
Does this create a use-after-free race condition with the interrupt handler?

kthread_destroy_worker() frees the dynamically allocated worker structure here,
but free_irq() is called later in ivtv_remove():

drivers/media/pci/ivtv/ivtv-driver.c:ivtv_remove() {
	...
	kthread_destroy_worker(itv->irq_worker);
	...
	free_irq(itv->pdev->irq, (void *)itv);
	...
}

Because free_irq() is the synchronization point that guarantees no interrupt
handlers are still running, an in-flight ivtv_irq_handler() on another CPU
can survive past kthread_destroy_worker().

If the handler subsequently attempts to queue work, it will dereference the
already-freed irq_worker pointer, causing a kernel panic.

>  
>  	ivtv_streams_cleanup(itv);
>  	ivtv_udma_free(itv);
> diff --git a/drivers/media/pci/ivtv/ivtv-driver.h b/drivers/media/pci/ivtv/ivtv-driver.h
> index f1f18911332e8..41789a50d1ca6 100644
> --- a/drivers/media/pci/ivtv/ivtv-driver.h
> +++ b/drivers/media/pci/ivtv/ivtv-driver.h
> @@ -668,8 +668,7 @@ struct ivtv {
>  	/* Interrupts & DMA */
>  	u32 irqmask;                    /* active interrupts */
>  	u32 irq_rr_idx;                 /* round-robin stream index */
> -	struct kthread_worker irq_worker;		/* kthread worker for PIO/YUV/VBI actions */
> -	struct task_struct *irq_worker_task;		/* task for irq_worker */
> +	struct kthread_worker *irq_worker;		/* kthread worker for PIO/YUV/VBI actions */

[Severity: High]
Does this change from a struct to a pointer cause a build error or memory
corruption in ivtv_irq_handler()?

Because irq_worker is now a pointer, the unmodified call site in
ivtv_irq_handler() now passes a double pointer:

drivers/media/pci/ivtv/ivtv-irq.c:ivtv_irq_handler() {
    ...
    kthread_queue_work(&itv->irq_worker, &itv->irq_work);
    ...
}

This violates the API contract and will cause a build failure with modern
compilers due to incompatible pointer types.

If the warning is ignored or coerced, kthread_queue_work() will treat the
offset within struct ivtv as a kthread_worker object, corrupting adjacent
fields when it acquires the spinlock, leading to a kernel crash.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1788513591.git.brads@mainlining.org?part=1

  parent reply	other threads:[~2026-09-05  9:40 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04  9:37 [PATCH v2 0/5] kthread: convert remaining users to kthread_create_worker Bradley Morgan
2026-09-04  9:37 ` [PATCH v2 1/5] media: ivtv: convert to kthread_run_worker Bradley Morgan
2026-09-04 10:44   ` Bradley Morgan
2026-09-05  9:40   ` sashiko-bot [this message]
2026-09-05  9:51     ` Bradley Morgan
2026-09-04  9:40 ` [PATCH v2 2/5] net: encx24j600: " Bradley Morgan
2026-09-05  9:40   ` sashiko-bot
2026-09-05  9:54     ` Bradley Morgan
2026-09-04  9:40 ` [PATCH v2 3/5] tty: sc16is7xx: " Bradley Morgan
2026-09-05  9:40   ` sashiko-bot
2026-09-05  9:51     ` Bradley Morgan
2026-09-04  9:40 ` [PATCH v2 4/5] cpufreq: schedutil: convert to kthread_create_worker Bradley Morgan
2026-09-05  9:40   ` sashiko-bot
2026-09-04  9:40 ` [PATCH v2 5/5] kthread: remove worker->task self assignment Bradley Morgan
2026-09-05  9:40   ` sashiko-bot
2026-09-05  9:50     ` Bradley Morgan
2026-09-05 14:37   ` kernel test robot
2026-09-05 14:50     ` Bradley Morgan
2026-09-05 15:11   ` kernel test robot
2026-09-04 15:54 ` [PATCH v2 0/5] kthread: convert remaining users to kthread_create_worker Jakub Kicinski
2026-09-04 15:56   ` Bradley Morgan
2026-09-04 21:10     ` Jakub Kicinski
2026-09-04 21:13       ` Bradley Morgan
2026-09-05 11:19         ` Greg Kroah-Hartman
2026-09-05 12:55           ` Bradley Morgan
2026-09-05 17:10             ` Greg Kroah-Hartman
2026-09-05 17:56               ` Bradley Morgan

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=20260905094037.AF7E01F00A3F@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=brads@mainlining.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=media-ci@linuxtv.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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