All of lore.kernel.org
 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 3/5] tty: sc16is7xx: convert to kthread_run_worker
Date: Sat, 05 Sep 2026 09:40:35 +0000	[thread overview]
Message-ID: <20260905094036.2E7811F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <946a190a64560bbb192d03f5757b8349b97157f9.1788513591.git.brads@mainlining.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] The explicitly allocated kthread worker is destroyed before the devm-managed threaded IRQ handler is freed, causing a Use-After-Free.

Pre-existing issues:
- [High] Closing any single port cancels the shared polling timer, starving all other active ports on the same multi-port chip.
--

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

tty: sc16is7xx: convert to kthread_run_worker
    
Convert sc16is7xx 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/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
> index 7107a0fb1e7bb..2cfc1f2900091 100644
> --- a/drivers/tty/serial/sc16is7xx.c
> +++ b/drivers/tty/serial/sc16is7xx.c
> @@ -1186,7 +1185,7 @@ static void sc16is7xx_shutdown(struct uart_port *port)
>  	if (s->polling)
>  		kthread_cancel_delayed_work_sync(&s->poll_work);
>  
> -	kthread_flush_worker(&s->kworker);
> +	kthread_flush_worker(s->kworker);
>  }

[Severity: High]
This is a pre-existing issue, but does closing any single port cancel the
shared polling timer for all ports?

In polling mode, s->poll_work is shared across all ports on the chip. If
one port is closed, sc16is7xx_shutdown() unconditionally cancels s->poll_work,
which seems to starve any other active ports on the same chip.

> @@ -1705,8 +1702,8 @@ void sc16is7xx_remove(struct device *dev)
>  	if (s->polling)
>  		kthread_cancel_delayed_work_sync(&s->poll_work);
>  
> -	kthread_flush_worker(&s->kworker);
> -	kthread_stop(s->kworker_task);
> +	kthread_flush_worker(s->kworker);
> +	kthread_destroy_worker(s->kworker);
>  
>  	clk_disable_unprepare(s->clk);
>  }

[Severity: High]
Can kthread_destroy_worker() lead to a use-after-free if the threaded IRQ
handler fires concurrently?

The driver uses devm_request_threaded_irq() in sc16is7xx_probe() to manage its
interrupt, meaning the IRQ handler remains active until after
sc16is7xx_remove() returns and devres cleans it up.

If an interrupt fires or an in-flight threaded IRQ executes in parallel right
after kthread_destroy_worker() frees s->kworker, the IRQ handler could call
functions like sc16is7xx_ier_clear() which enqueue work:

drivers/tty/serial/sc16is7xx.c:sc16is7xx_ier_clear() {
    ...
    kthread_queue_work(s->kworker, &one->reg_work);
}

This would dereference the freed s->kworker pointer. Previously kworker was
embedded in the sc16is7xx_port struct, so stopping the task was safe from a
use-after-free, but now kthread_destroy_worker() frees the dynamically
allocated worker before the IRQ handler is disabled.

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

  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
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 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 3/5] tty: sc16is7xx: convert to kthread_run_worker 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 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=20260905094036.2E7811F00A3D@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 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.