From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Karl Mehltretter <kmehltretter@gmail.com>
Cc: Jiri Slaby <jirislaby@kernel.org>,
linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2 2/4] serial: core: clear freed pointers on uart_register_driver() failure
Date: Thu, 30 Jul 2026 16:28:45 +0200 [thread overview]
Message-ID: <2026073030-smother-rundown-c4b3@gregkh> (raw)
In-Reply-To: <20260719221014.44354-3-kmehltretter@gmail.com>
On Mon, Jul 20, 2026 at 12:10:12AM +0200, Karl Mehltretter wrote:
> uart_register_driver() leaves freed pointers behind on failure. If
> tty_alloc_driver() fails, it frees drv->state without clearing it. If
> tty_register_driver() fails, it also drops the tty driver reference
> without clearing drv->tty_driver.
>
> Several drivers register the uart_driver lazily and use drv->state as
> an "already registered" sentinel. After a failed registration, the
> next probe sees the stale pointer, skips re-registration and calls
> uart_add_one_port() with freed state.
>
> The resulting unwind can call uart_unregister_driver() with a NULL or
> dangling drv->tty_driver and oops in tty_unregister_driver():
>
> Unhandled fault: page domain fault (0x01b) at 0x00000018
> PC is at tty_unregister_driver+0x10/0x68
> LR is at uart_unregister_driver+0x1c/0x60
>
> Reproduced with failslab fail-nth injection on qemu's raspi1ap board:
> fail the tty_alloc_driver() allocation during a sysfs bind of the
> PL011 port, then bind again in the same boot.
>
> Clear drv->state after freeing the state array and clear
> drv->tty_driver after dropping the tty driver reference, as
> uart_unregister_driver() already does.
>
> The tty_register_driver() failure case predates Git history. The
> tty_alloc_driver() failure case was introduced by commit 9e845abfc8a8
> ("serial: fix NULL pointer dereference"), which made that error path
> return cleanly instead of crashing in put_tty_driver(NULL).
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Fixes: 9e845abfc8a8 ("serial: fix NULL pointer dereference")
> Cc: stable@vger.kernel.org
Same comment here, this can't ever be hit by a "normal" user, right?
thanks,
greg k-h
next prev parent reply other threads:[~2026-07-30 16:19 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-19 22:10 [PATCH v2 0/4] serial: fix console lifetime bugs on failed bind and removal Karl Mehltretter
2026-07-19 22:10 ` [PATCH v2 1/4] serial: core: do fallible allocations before the console can be registered Karl Mehltretter
2026-07-30 14:28 ` Greg Kroah-Hartman
2026-07-31 12:37 ` Karl Mehltretter
2026-07-19 22:10 ` [PATCH v2 2/4] serial: core: clear freed pointers on uart_register_driver() failure Karl Mehltretter
2026-07-30 14:28 ` Greg Kroah-Hartman [this message]
2026-07-19 22:10 ` [PATCH v2 3/4] tty: don't oops in tty_unregister_device() when no cdev is registered Karl Mehltretter
2026-07-30 14:29 ` Greg Kroah-Hartman
2026-07-31 13:15 ` Karl Mehltretter
2026-07-19 22:10 ` [PATCH v2 4/4] serial: imx: serialize imx_uart_ports[] lifetime Karl Mehltretter
2026-07-30 14:31 ` Greg Kroah-Hartman
2026-07-31 13:54 ` Karl Mehltretter
2026-07-30 19:02 ` Frank Li
2026-07-31 14:40 ` Karl Mehltretter
2026-07-31 15:28 ` Frank Li
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=2026073030-smother-rundown-c4b3@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=kmehltretter@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=stable@vger.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®