* [PATCH] n_tty: add null check for tty->link in packet mode
@ 2026-03-14 22:10 Osama Abdelkader
2026-03-15 6:57 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Osama Abdelkader @ 2026-03-14 22:10 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, linux-kernel, linux-serial
Cc: Osama Abdelkader
Add null check for tty->link before dereferencing in n_tty_read and
n_tty_poll. When the pty master closes, tty->link can be NULL while
the slave is still reading, causing a null pointer dereference.
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
---
drivers/tty/n_tty.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index e6a0f5b40d0a..dc04b87364f6 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -2232,7 +2232,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf,
add_wait_queue(&tty->read_wait, &wait);
while (nr) {
/* First test for status change. */
- if (packet && tty->link->ctrl.pktstatus) {
+ if (packet && tty->link && tty->link->ctrl.pktstatus) {
u8 cs;
if (kb != kbuf)
break;
@@ -2444,7 +2444,7 @@ static __poll_t n_tty_poll(struct tty_struct *tty, struct file *file,
if (input_available_p(tty, 1))
mask |= EPOLLIN | EPOLLRDNORM;
}
- if (tty->ctrl.packet && tty->link->ctrl.pktstatus)
+ if (tty->ctrl.packet && tty->link && tty->link->ctrl.pktstatus)
mask |= EPOLLPRI | EPOLLIN | EPOLLRDNORM;
if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
mask |= EPOLLHUP;
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] n_tty: add null check for tty->link in packet mode
2026-03-14 22:10 [PATCH] n_tty: add null check for tty->link in packet mode Osama Abdelkader
@ 2026-03-15 6:57 ` Greg Kroah-Hartman
2026-03-23 20:39 ` Osama Abdelkader
0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2026-03-15 6:57 UTC (permalink / raw)
To: Osama Abdelkader; +Cc: Jiri Slaby, linux-kernel, linux-serial
On Sat, Mar 14, 2026 at 11:10:44PM +0100, Osama Abdelkader wrote:
> Add null check for tty->link before dereferencing in n_tty_read and
> n_tty_poll. When the pty master closes, tty->link can be NULL while
> the slave is still reading, causing a null pointer dereference.
How can that happen?
> Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
> ---
> drivers/tty/n_tty.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
> index e6a0f5b40d0a..dc04b87364f6 100644
> --- a/drivers/tty/n_tty.c
> +++ b/drivers/tty/n_tty.c
> @@ -2232,7 +2232,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf,
> add_wait_queue(&tty->read_wait, &wait);
> while (nr) {
> /* First test for status change. */
> - if (packet && tty->link->ctrl.pktstatus) {
> + if (packet && tty->link && tty->link->ctrl.pktstatus) {
> u8 cs;
> if (kb != kbuf)
> break;
> @@ -2444,7 +2444,7 @@ static __poll_t n_tty_poll(struct tty_struct *tty, struct file *file,
> if (input_available_p(tty, 1))
> mask |= EPOLLIN | EPOLLRDNORM;
> }
> - if (tty->ctrl.packet && tty->link->ctrl.pktstatus)
> + if (tty->ctrl.packet && tty->link && tty->link->ctrl.pktstatus)
What happens if link changes right after you test it? Where is the
lock?
And what changed to cause this to show up now?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] n_tty: add null check for tty->link in packet mode
2026-03-15 6:57 ` Greg Kroah-Hartman
@ 2026-03-23 20:39 ` Osama Abdelkader
0 siblings, 0 replies; 3+ messages in thread
From: Osama Abdelkader @ 2026-03-23 20:39 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Jiri Slaby, linux-kernel, linux-serial
On Sun, Mar 15, 2026 at 07:57:53AM +0100, Greg Kroah-Hartman wrote:
> On Sat, Mar 14, 2026 at 11:10:44PM +0100, Osama Abdelkader wrote:
> > Add null check for tty->link before dereferencing in n_tty_read and
> > n_tty_poll. When the pty master closes, tty->link can be NULL while
> > the slave is still reading, causing a null pointer dereference.
>
> How can that happen?
>
> > Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
> > ---
> > drivers/tty/n_tty.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
> > index e6a0f5b40d0a..dc04b87364f6 100644
> > --- a/drivers/tty/n_tty.c
> > +++ b/drivers/tty/n_tty.c
> > @@ -2232,7 +2232,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf,
> > add_wait_queue(&tty->read_wait, &wait);
> > while (nr) {
> > /* First test for status change. */
> > - if (packet && tty->link->ctrl.pktstatus) {
> > + if (packet && tty->link && tty->link->ctrl.pktstatus) {
> > u8 cs;
> > if (kb != kbuf)
> > break;
> > @@ -2444,7 +2444,7 @@ static __poll_t n_tty_poll(struct tty_struct *tty, struct file *file,
> > if (input_available_p(tty, 1))
> > mask |= EPOLLIN | EPOLLRDNORM;
> > }
> > - if (tty->ctrl.packet && tty->link->ctrl.pktstatus)
> > + if (tty->ctrl.packet && tty->link && tty->link->ctrl.pktstatus)
>
> What happens if link changes right after you test it? Where is the
> lock?
>
> And what changed to cause this to show up now?
>
> thanks,
>
> greg k-h
Hi Greg,
I was just thinking about null dereferencing possiblity in tty->link->ctrl.pktstatus. But, you are right
It’s reasonable to drop this patch and reopen it only if I get a solid reproducer or bug report.
BR,
Osama
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-23 20:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-14 22:10 [PATCH] n_tty: add null check for tty->link in packet mode Osama Abdelkader
2026-03-15 6:57 ` Greg Kroah-Hartman
2026-03-23 20:39 ` Osama Abdelkader
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox