From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Ruslan Valiyev <linuxoid@gmail.com>
Cc: Jiri Slaby <jirislaby@kernel.org>,
Tony Lindgren <tony@atomide.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Hugo Villeneuve <hvilleneuve@dimonoff.com>,
John Ogness <john.ogness@linutronix.de>,
Lukas Wunner <lukas@wunner.de>, Gerhard Engleder <eg@keba.com>,
linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
syzkaller-bugs@googlegroups.com,
syzbot+9f57c1b2792029198fcf@syzkaller.appspotmail.com,
stable@vger.kernel.org
Subject: Re: [PATCH] serial: core: fix NULL pointer dereference in serial_core_unregister_port()
Date: Wed, 26 Aug 2026 09:53:34 +0200 [thread overview]
Message-ID: <2026082645-stench-backpack-6e07@gregkh> (raw)
In-Reply-To: <20260826073237.1377668-1-linuxoid@gmail.com>
On Wed, Aug 26, 2026 at 09:32:36AM +0200, Ruslan Valiyev wrote:
> serial_core_unregister_port() dereferences port->port_dev before it has
> been checked:
>
> struct serial_port_device *port_dev = port->port_dev;
> struct serial_ctrl_device *ctrl_dev = serial_core_get_ctrl_dev(port_dev);
>
> serial_core_get_ctrl_dev() takes &port_dev->dev and reads dev->parent
> straight away, so a NULL port_dev faults at offset 0x40.
>
> port_dev is NULL whenever no port device is installed:
> serial_core_remove_one_port() clears it on teardown, and it is never
> set if registration failed before serial_core_port_device_add().
>
> serial8250_unregister_port() reaches that state. It calls
> uart_remove_one_port(), which clears port_dev, and then re-adds the
> port with uart_add_one_port() without checking the return value. When
> that re-add fails, port_dev stays NULL while port.dev still points at
> the ISA platform device, so unbinding that device once more calls
> serial8250_unregister_port() again and oopses:
>
> Oops: general protection fault, probably for non-canonical address
> KASAN: null-ptr-deref in range [0x0000000000000040-0x0000000000000047]
> RIP: 0010:serial_core_unregister_port+0xef/0x990
> Call Trace:
> serial8250_unregister_port+0x1e4/0x8a0
> serial8250_remove+0x8c/0xb0
> platform_remove+0x5f/0x80
> device_release_driver_internal+0x46b/0x640
> unbind_store+0xf8/0x110
> sysfs_kf_write+0xf2/0x150
> vfs_write+0x6ac/0x1050
>
> Return early when there is no port device to remove, and read
> port->port_dev under port_mutex, since every other update of that
> field is serialised by it.
>
> Also clear port->port_dev on the serial_core_register_port() error
> path. serial_base_port_device_remove() frees the port device but left
> the pointer behind, so unregistering after a failed registration read
> freed memory instead. That is the use-after-free variant of the same
> crash, and matches the title syzbot first reported this under.
It's an invalid syzbot reproducer, if root tells the kernel to unbind
from a device when it is being used, it gets to keep the pieces when
things break :(
Let me go polish off my "taint the kernel if bind/unbind runs" patch to
keep this from happening...
> Fixes: 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
> Reported-by: syzbot+9f57c1b2792029198fcf@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=9f57c1b2792029198fcf
> Cc: stable@vger.kernel.org
> Signed-off-by: Ruslan Valiyev <linuxoid@gmail.com>
Did you forget an Assisted-by: tag?
thanks,
greg k-h
next prev parent reply other threads:[~2026-08-26 7:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 7:32 [PATCH] serial: core: fix NULL pointer dereference in serial_core_unregister_port() Ruslan Valiyev
2026-08-26 7:50 ` sashiko-bot
2026-08-26 7:53 ` Greg Kroah-Hartman [this message]
2026-08-26 8:06 ` Ruslan Valiyev
2026-08-26 8:20 ` Greg Kroah-Hartman
2026-08-26 8:13 ` Andy Shevchenko
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=2026082645-stench-backpack-6e07@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=eg@keba.com \
--cc=hvilleneuve@dimonoff.com \
--cc=jirislaby@kernel.org \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linuxoid@gmail.com \
--cc=lukas@wunner.de \
--cc=stable@vger.kernel.org \
--cc=syzbot+9f57c1b2792029198fcf@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=tony@atomide.com \
/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.