From: sashiko-bot@kernel.org
To: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH 3/3] tty: hvcs: replace __get_free_page() with kmalloc()
Date: Sun, 30 Aug 2026 08:05:27 +0000 [thread overview]
Message-ID: <20260830080527.E6C4E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260830-tty-v1-3-0cbe6170649b@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Error path in `hvcs_initialize()` leaves `hvcs_task` as an `ERR_PTR` and `hvcs_pi_buff` as a dangling pointer, leading to a kernel panic and double-free on module exit.
--
commit 9b8103eef858c273046b0b8e782a706cf3628f9a
Author: Mike Rapoport (Microsoft) <rppt@kernel.org>
tty: hvcs: replace __get_free_page() with kmalloc()
hvcs_initialize() allocates the buffer that receives the partner info
returned by the H_VTERM_PARTNER_INFO hypercall. This buffer can be allocated
with kmalloc() as there's nothing special about it to go directly to the
page allocator.
Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
> index d32b1e3c50bfd..b94d59fa36274 100644
> --- a/drivers/tty/hvc/hvcs.c
> +++ b/drivers/tty/hvc/hvcs.c
[ ... ]
> @@ -1486,7 +1486,7 @@ static int hvcs_initialize(void)
> return 0;
>
> kthread_fail:
> - free_page((unsigned long)hvcs_pi_buff);
> + kfree(hvcs_pi_buff);
[Severity: High]
This isn't a bug introduced by this patch, but will this error path leave
hvcs_task as an ERR_PTR and hvcs_pi_buff as a dangling pointer?
If hvcs_initialize() fails at kthread_run(), hvcs_task will hold an ERR_PTR
and hvcs_pi_buff is freed here but not nullified.
> buff_alloc_fail:
> tty_unregister_driver(hvcs_tty_driver);
> register_fail:
[ ... ]
> @@ -1528,7 +1528,7 @@ static void __exit hvcs_module_exit(void)
> kthread_stop(hvcs_task);
>
> spin_lock(&hvcs_pi_lock);
> - free_page((unsigned long)hvcs_pi_buff);
> + kfree(hvcs_pi_buff);
[Severity: High]
This isn't a bug introduced by this patch, but could module unload cause a
kernel panic and a double-free if initialization previously failed?
Since hvcs_task is left as an ERR_PTR on failure rather than being reset to
NULL, the early return check in hvcs_module_exit() fails to catch it:
drivers/tty/hvc/hvcs.c:hvcs_module_exit() {
if (!hvcs_task)
return;
...
}
This allows execution to proceed to kthread_stop(hvcs_task), which will
dereference the error pointer.
It also proceeds to double-free the dangling hvcs_pi_buff here, and
eventually passes the NULL hvcs_tty_driver to tty_unregister_driver(),
resulting in a NULL pointer dereference panic.
> hvcs_pi_buff = NULL;
> spin_unlock(&hvcs_pi_lock);
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260830-tty-v1-0-0cbe6170649b@kernel.org?part=3
prev parent reply other threads:[~2026-08-30 8:05 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-30 7:49 [PATCH 0/3] tty: replace page allocator calls with k[mz]alloc() Mike Rapoport (Microsoft)
2026-08-30 7:49 ` [PATCH 1/3] tty: port: replace get_zeroed_page() with kzalloc() Mike Rapoport (Microsoft)
2026-08-30 8:07 ` sashiko-bot
2026-08-30 7:49 ` [PATCH 2/3] serial: core: " Mike Rapoport (Microsoft)
2026-08-30 8:00 ` sashiko-bot
2026-08-30 8:44 ` Mike Rapoport
2026-08-31 3:02 ` Jiri Slaby
2026-08-31 8:28 ` Mike Rapoport
2026-08-30 7:49 ` [PATCH 3/3] tty: hvcs: replace __get_free_page() with kmalloc() Mike Rapoport (Microsoft)
2026-08-30 8:05 ` sashiko-bot [this message]
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=20260830080527.E6C4E1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=rppt@kernel.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