Linux Serial subsystem development
 help / color / mirror / Atom feed
From: cuigaosheng <cuigaosheng1@huawei.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: <lujialin4@huawei.com>, <gregkh@linuxfoundation.org>,
	<jirislaby@kernel.org>, <hvilleneuve@dimonoff.com>,
	<kmehltretter@gmail.com>, <john.ogness@linutronix.de>,
	<tony@atomide.com>, <linux-serial@vger.kernel.org>
Subject: Re: [PATCH -next,v3] serial: core: fix NULL/dangling port_dev on failed re-register
Date: Tue, 29 Sep 2026 10:37:38 +0800	[thread overview]
Message-ID: <aad02451-3115-66ff-95ea-c727de50d3e1@huawei.com> (raw)
In-Reply-To: <arrgcE9hdhv_-GBi@ashevche-desk.local>


On 2026/9/29 5:47, Andy Shevchenko wrote:
> On Mon, Sep 28, 2026 at 07:34:56PM +0800, Gaosheng Cui wrote:
>
>> serial8250_unregister_port() removes a port and then re-registers it
>> against the legacy serial8250 device when that device is still
>> present, ignoring the return value of uart_add_one_port(). When the
>> re-register fails, the error path of serial_core_register_port()
>> removes the port device but leaves port->port_dev dangling (or NULL
>> if the port device allocation itself failed). serial8250 matches
>> ports on ->dev, so such half-registered slots still reach
>> serial_core_unregister_port() on the next unbind:
>>
>>    Oops: general protection fault ... SMP KASAN PTI
>>    KASAN: null-ptr-deref in range [0x40-0x47]
>>    RIP: serial_core_unregister_port+0xe5/0xa00
>>      serial8250_unregister_port+0x103
>>      serial8250_remove+0x61
>>      device_release_driver_internal+0x38c
>>      unbind_store+0xd1
>>      kernfs_fop_write_iter+0x329
>>      vfs_write+0x5d0
>>      ksys_write+0xf7
>>      do_syscall_64+0xdd
>>      entry_SYSCALL_64_after_hwframe+0x77
> Submitting Patches is clear about bloated backtraces in the commit message.
>
>> Fix the error path to clear port->port_dev, and bail out of
>> serial_core_unregister_port() when port_dev is NULL. Read
>> port->port_dev under port_mutex, like all of its writers.
>> Fixes: 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
>> Assisted-by: GLM-5.3 OpenCode # fault analysis and fix rework
> Assisted-by: LLM
>
>> Signed-off-by: Cui GaoSheng <cuigaosheng1@huawei.com>

Thanks, I have submitted the V4 patch.


      reply	other threads:[~2026-09-29  2:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 11:34 [PATCH -next,v3] serial: core: fix NULL/dangling port_dev on failed re-register Gaosheng Cui
2026-09-28 11:47 ` sashiko-bot
2026-09-28 21:47 ` Andy Shevchenko
2026-09-29  2:37   ` cuigaosheng [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=aad02451-3115-66ff-95ea-c727de50d3e1@huawei.com \
    --to=cuigaosheng1@huawei.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hvilleneuve@dimonoff.com \
    --cc=jirislaby@kernel.org \
    --cc=john.ogness@linutronix.de \
    --cc=kmehltretter@gmail.com \
    --cc=linux-serial@vger.kernel.org \
    --cc=lujialin4@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox