From: Xin Chen <quic_cxin@quicinc.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Rob Herring <robh@kernel.org>, Jiri Slaby <jirislaby@kernel.org>,
<linux-serial@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<liulzhao@qti.qualcomm.com>, <quic_chejiang@quicinc.com>,
<zaiyongc@qti.qualcomm.com>, <quic_zijuhu@quicinc.com>,
<quic_mohamull@quicinc.com>,
Panicker Harish <quic_pharish@quicinc.com>
Subject: Re: [PATCH v1] tty: serdev: serdev-ttyport: Fix use-after-free in ttyport_close() due to uninitialized serport->tty
Date: Thu, 8 May 2025 17:29:18 +0800 [thread overview]
Message-ID: <d388b471-482b-48ba-a504-694529535362@quicinc.com> (raw)
In-Reply-To: <2025043022-rumbling-guy-26fb@gregkh>
On 4/30/2025 7:40 PM, Greg Kroah-Hartman wrote:
> On Wed, Apr 30, 2025 at 07:16:17PM +0800, Xin Chen wrote:
>> When ttyport_open() fails to initialize a tty device, serport->tty is not
>> --- a/drivers/tty/serdev/serdev-ttyport.c
>> +++ b/drivers/tty/serdev/serdev-ttyport.c
>> @@ -88,6 +88,10 @@ static void ttyport_write_flush(struct serdev_controller *ctrl)
>> {
>> struct serport *serport = serdev_controller_get_drvdata(ctrl);
>> struct tty_struct *tty = serport->tty;
>> + if (!tty) {
>> + dev_err(&ctrl->dev, "tty is null\n");
>> + return;
>> + }
>
> What prevents tty from going NULL right after you just checked this?
First sorry for reply so late for I have a long statutory holidays.
Maybe I don't get your point. From my side, there is nothing to prevent it.
Check here is to avoid code go on if tty is NULL.
>
> And why print out that message, what can userspace do with it?
>
I add the print just ref to code in other place. This can't be used by
userspace, but it can be used in DMesg log when system crashes.
>>
>> tty_driver_flush_buffer(tty);
>> }
>> @@ -108,8 +112,10 @@ static int ttyport_open(struct serdev_controller *ctrl)
>> int ret;
>>
>> tty = tty_init_dev(serport->tty_drv, serport->tty_idx);
>> - if (IS_ERR(tty))
>> + if (IS_ERR(tty)) {
>> + serport->tty = NULL;
>> return PTR_ERR(tty);
>> + }
>> serport->tty = tty;
>>
>> if (!tty->ops->open || !tty->ops->close) {
>> @@ -156,6 +162,11 @@ static void ttyport_close(struct serdev_controller *ctrl)
>>
>> clear_bit(SERPORT_ACTIVE, &serport->flags);
>>
>> + if (!tty) {
>> + dev_err(&ctrl->dev, "tty is null\n");
>> + return;
>> + }
>
> Again, what prevents it from changing right after you just checked it?
Same with above, there is nothing prevent it. Check here is to avoid code go on
if tty is NULL.
The check is for changes in ttyport_open(). In my project, it's possible that
ttyport_close() and ttyport_write_flush() get called after ttyport_open()
failed, at which time tty is invalid.
thanks,
Xin
next prev parent reply other threads:[~2025-05-08 9:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-30 11:16 Xin Chen
2025-04-30 11:40 ` Greg Kroah-Hartman
2025-05-08 9:29 ` Xin Chen [this message]
2025-05-08 9:41 ` Greg Kroah-Hartman
2025-05-14 9:14 ` Xin Chen
2025-05-23 2:52 ` Xin Chen
2025-05-29 9:07 ` Greg Kroah-Hartman
2025-05-29 9:41 ` Greg Kroah-Hartman
2025-05-30 8:34 ` Xin Chen
2025-05-31 7:20 ` Greg Kroah-Hartman
2025-06-05 8:13 ` Xin Chen
2025-05-30 8:11 ` Xin Chen
2025-05-31 7:16 ` Greg Kroah-Hartman
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=d388b471-482b-48ba-a504-694529535362@quicinc.com \
--to=quic_cxin@quicinc.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=liulzhao@qti.qualcomm.com \
--cc=quic_chejiang@quicinc.com \
--cc=quic_mohamull@quicinc.com \
--cc=quic_pharish@quicinc.com \
--cc=quic_zijuhu@quicinc.com \
--cc=robh@kernel.org \
--cc=zaiyongc@qti.qualcomm.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
all inboxes | Powered by JetHome®