Skip to contentSkip to conversation

tty: n_gsm: fix race condition in status line change on dead connections

PATCH In review D. Starke 2 participants 6 messages Oct 26, 2023 TTY layer and serial drivers

lore
Share & tools
lore

D. Starke

author
#0 lore raw

PATCH 1/2 tty: n_gsm: fix race condition in status line change on dead connections

From: Daniel Starke <[email protected]>

gsm_cleanup_mux() cleans up the gsm by closing all DLCIs, stopping all timers, removing the virtual tty devices and clearing the data queues. This procedure, however, may cause subsequent changes of the virtual modem status lines of a DLCI. More data is being added the outgoing data queue and the deleted kick timer is restarted to handle this. At this point many resources have already been removed by the cleanup procedure. Thus, a kernel panic occurs.

Fix this by proving in gsm_modem_update() that the cleanup procedure has not been started and the mux is still alive.

Note that writing to a virtual tty is already protected by checks against the DLCI specific connection state.

Fixes c568f7086c6e ("tty: n_gsm: fix missing timer to handle stalled links")
---
 drivers/tty/n_gsm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/tty/n_gsm.c +2 -0
index 1f3aba607cd5..0ee7531c9201 100644
@@ -4108,6 +4108,8 @@ static int gsm_modem_upd_via_msc(struct gsm_dlci *dlci, u8 brk)
 
 static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk)
 {
+	if (dlci->gsm->dead)
+		return -EL2HLT;
 	if (dlci->adaption == 2) {
 		/* Send convergence layer type 2 empty data frame. */
 		gsm_modem_upd_via_data(dlci, brk);
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 2/2 tty: n_gsm: add partial copyright Siemens Mobility GmbH

From: Daniel Starke <[email protected]>

More than 1/3 of the n_gsm code has been contributed by us in the last 1.5 years, completing conformance with the standard and stabilizing the driver:
- added UI (unnumbered information) frame support
- added PN (parameter negotiation) message handling and function support
- added optional keep-alive control link supervision via test messages
- added TIOCM_OUT1 and TIOCM_OUT2 to allow responder to operate as modem
- added TIOCMIWAIT support on virtual ttys
- added additional ioctls and parameters to configure the new functions
- added overall locking mechanism to avoid data race conditions
- added outgoing data flow to decouple physical from virtual tty handling for better performance and to avoid dead-locks
- fixed advanced option mode implementation
- fixed convergence layer type 2 implementation
- fixed handling of CLD (multiplexer close down) messages
- fixed broken muxer close down procedure
- and many more bug fixes

With this most of our initial RFC has been implemented. It gives the driver a quality boost unseen in the decade before.

Add a partial copyright notice to the n_gsm files to highlight this contribution.

---
 drivers/tty/n_gsm.c         | 1 +
 include/uapi/linux/gsmmux.h | 1 +
 2 files changed, 2 insertions(+)
drivers/tty/n_gsm.c +1 -0
index 0ee7531c9201..fa882c7f4770 100644
@@ -2,6 +2,7 @@
 /*
  * n_gsm.c GSM 0710 tty multiplexor
  * Copyright (c) 2009/10 Intel Corporation
+ * Portions Copyright (c) 2022/23 Siemens Mobility GmbH
  *
  *	* THIS IS A DEVELOPMENT SNAPSHOT IT IS NOT A FINAL RELEASE *
  *
include/uapi/linux/gsmmux.h +1 -0
index 4c878d84dbda..101ebd15954e 100644
@@ -1,4 +1,5 @@
 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/* Portions Copyright (c) 2022/23 Siemens Mobility GmbH */
 #ifndef _LINUX_GSMMUX_H
 #define _LINUX_GSMMUX_H
 
Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH 2/2] tty: n_gsm: add partial copyright Siemens Mobility GmbH

Quoted 38 lines · D. Starke

From: Daniel Starke <[email protected]>

More than 1/3 of the n_gsm code has been contributed by us in the last 1.5 years, completing conformance with the standard and stabilizing the driver:
- added UI (unnumbered information) frame support
- added PN (parameter negotiation) message handling and function support
- added optional keep-alive control link supervision via test messages
- added TIOCM_OUT1 and TIOCM_OUT2 to allow responder to operate as modem
- added TIOCMIWAIT support on virtual ttys
- added additional ioctls and parameters to configure the new functions
- added overall locking mechanism to avoid data race conditions
- added outgoing data flow to decouple physical from virtual tty handling for better performance and to avoid dead-locks
- fixed advanced option mode implementation
- fixed convergence layer type 2 implementation
- fixed handling of CLD (multiplexer close down) messages
- fixed broken muxer close down procedure
- and many more bug fixes

With this most of our initial RFC has been implemented. It gives the driver a quality boost unseen in the decade before.

Add a partial copyright notice to the n_gsm files to highlight this contribution.

---
 drivers/tty/n_gsm.c         | 1 +
 include/uapi/linux/gsmmux.h | 1 +
 2 files changed, 2 insertions(+)
drivers/tty/n_gsm.c +0 -0
index 0ee7531c9201..fa882c7f4770 100644

drivers/tty/n_gsm.c line 5

Quoted 4 lines
drivers/tty/n_gsm.c +1 -0
@@ -2,6 +2,7 @@
 /*
  * n_gsm.c GSM 0710 tty multiplexor
  * Copyright (c) 2009/10 Intel Corporation
+ * Portions Copyright (c) 2022/23 Siemens Mobility GmbH

I have no objection to you adding your copyright, you all have done a ton of great work here and it is correct to add. But the "Portions" line is odd, and isn't something we generally use. Can you just resend this with that word removed?

include/uapi/linux/gsmmux.h line 2

Quoted 10 lines
drivers/tty/n_gsm.c +0 -0
  *
  *	* THIS IS A DEVELOPMENT SNAPSHOT IT IS NOT A FINAL RELEASE *
  *
include/uapi/linux/gsmmux.h +1 -0
index 4c878d84dbda..101ebd15954e 100644
@@ -1,4 +1,5 @@
 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/* Portions Copyright (c) 2022/23 Siemens Mobility GmbH */

Same here, just drop the "Portions"?

Odd that Intel didn't put their copyright here, but as we all know, absence of that line does not mean that someone does not have copyright on it, lines like these are lawyer cargo-cult-safety, so we play along with them :)

thanks,

greg k-h

#3 lore raw

RE: [PATCH 2/2] tty: n_gsm: add partial copyright Siemens Mobility GmbH

Quoted 7 lines
Quoted 1 line

+ * Portions Copyright (c) 2022/23 Siemens Mobility GmbH

I have no objection to you adding your copyright, you all have done a ton of great work here and it is correct to add. But the "Portions" line is odd, and isn't something we generally use. Can you just resend this with that word removed?

Quoted 12 lines

include/uapi/linux/gsmmux.h line 2

Quoted 10 lines

*
* * THIS IS A DEVELOPMENT SNAPSHOT IT IS NOT A FINAL RELEASE *
*

include/uapi/linux/gsmmux.h +1 -0
index 4c878d84dbda..101ebd15954e 100644
@@ -1,4 +1,5 @@
 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/* Portions Copyright (c) 2022/23 Siemens Mobility GmbH */

Same here, just drop the "Portions"?

This was something suggested by our IP department. But sure, I will resend this patch without the word included.

Best regards,
Daniel Starke

maintainer
#4 lore raw
In reply to D. Starke
Quoted 38 lines · D. Starke

From: Daniel Starke <[email protected]>

gsm_cleanup_mux() cleans up the gsm by closing all DLCIs, stopping all timers, removing the virtual tty devices and clearing the data queues. This procedure, however, may cause subsequent changes of the virtual modem status lines of a DLCI. More data is being added the outgoing data queue and the deleted kick timer is restarted to handle this. At this point many resources have already been removed by the cleanup procedure. Thus, a kernel panic occurs.

Fix this by proving in gsm_modem_update() that the cleanup procedure has not been started and the mux is still alive.

Note that writing to a virtual tty is already protected by checks against the DLCI specific connection state.

Fixes c568f7086c6e ("tty: n_gsm: fix missing timer to handle stalled links")
---
 drivers/tty/n_gsm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/tty/n_gsm.c +2 -0
index 1f3aba607cd5..0ee7531c9201 100644
@@ -4108,6 +4108,8 @@ static int gsm_modem_upd_via_msc(struct gsm_dlci *dlci, u8 brk)
 
 static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk)
 {
+	if (dlci->gsm->dead)
+		return -EL2HLT;
 	if (dlci->adaption == 2) {
 		/* Send convergence layer type 2 empty data frame. */
 		gsm_modem_upd_via_data(dlci, brk);
Signature · 1 line
2.34.1

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.

You are receiving this message because of the following common error(s) as indicated below:

- You have marked a patch with a "Fixes:" tag for a commit that is in an older released kernel, yet you do not have a cc: stable line in the signed-off-by area at all, which means that the patch will not be applied to any older kernel releases. To properly fix this, please follow the documented rules in the Documentation/process/stable-kernel-rules.rst file for how to resolve this.

If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.

thanks,

greg k-h's patch email bot

maintainer
#5 lore raw
Quoted 61 lines · Greg KH
Quoted 38 lines · D. Starke

From: Daniel Starke <[email protected]>

gsm_cleanup_mux() cleans up the gsm by closing all DLCIs, stopping all timers, removing the virtual tty devices and clearing the data queues. This procedure, however, may cause subsequent changes of the virtual modem status lines of a DLCI. More data is being added the outgoing data queue and the deleted kick timer is restarted to handle this. At this point many resources have already been removed by the cleanup procedure. Thus, a kernel panic occurs.

Fix this by proving in gsm_modem_update() that the cleanup procedure has not been started and the mux is still alive.

Note that writing to a virtual tty is already protected by checks against the DLCI specific connection state.

Fixes c568f7086c6e ("tty: n_gsm: fix missing timer to handle stalled links")
---
 drivers/tty/n_gsm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/tty/n_gsm.c +2 -0
index 1f3aba607cd5..0ee7531c9201 100644
@@ -4108,6 +4108,8 @@ static int gsm_modem_upd_via_msc(struct gsm_dlci *dlci, u8 brk)
 
 static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk)
 {
+	if (dlci->gsm->dead)
+		return -EL2HLT;
 	if (dlci->adaption == 2) {
 		/* Send convergence layer type 2 empty data frame. */
 		gsm_modem_upd_via_data(dlci, brk);
Signature · 1 line
2.34.1

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.

You are receiving this message because of the following common error(s) as indicated below:

- You have marked a patch with a "Fixes:" tag for a commit that is in an older released kernel, yet you do not have a cc: stable line in the signed-off-by area at all, which means that the patch will not be applied to any older kernel releases. To properly fix this, please follow the documented rules in the Documentation/process/stable-kernel-rules.rst file for how to resolve this.

Quoted 5 lines

If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.

Note, I'll take this now, and add the tag by hand, just try to remember it for the future.

thanks,

greg k-h