All of lore.kernel.org
 help / color / mirror / Atom feed
* RE: [PATCH 2/3] tty: n_gsm: fix mux activation issues in gsm_config()
@ 2022-05-09 11:03 Starke, Daniel
  2022-05-09 11:13 ` Jiri Slaby
  0 siblings, 1 reply; 4+ messages in thread
From: Starke, Daniel @ 2022-05-09 11:03 UTC (permalink / raw)
  To: Jiri Slaby, linux-serial, gregkh; +Cc: linux-kernel

> >   static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c)
> >   {
> > +	int ret = 0;
> 
> Why is the initialization needed? You can as well declare the variable only inside the if below.

You are right, this was unneeded. But this patch was already included in
the tty-linus branch. Shall I resubmit it nevertheless?

Best regards,
Daniel Starke

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/3] tty: n_gsm: fix mux activation issues in gsm_config()
  2022-05-09 11:03 [PATCH 2/3] tty: n_gsm: fix mux activation issues in gsm_config() Starke, Daniel
@ 2022-05-09 11:13 ` Jiri Slaby
  0 siblings, 0 replies; 4+ messages in thread
From: Jiri Slaby @ 2022-05-09 11:13 UTC (permalink / raw)
  To: Starke, Daniel, linux-serial, gregkh; +Cc: linux-kernel

On 09. 05. 22, 13:03, Starke, Daniel wrote:
>>>    static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c)
>>>    {
>>> +	int ret = 0;
>>
>> Why is the initialization needed? You can as well declare the variable only inside the if below.
> 
> You are right, this was unneeded. But this patch was already included in
> the tty-linus branch. Shall I resubmit it nevertheless?

In that case, you can only send a fixup patch...

thanks,
-- 
js
suse labs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/3] tty: n_gsm: fix mux activation issues in gsm_config()
  2022-05-04  8:17 ` [PATCH 2/3] tty: n_gsm: fix mux activation issues in gsm_config() D. Starke
@ 2022-05-09 10:28   ` Jiri Slaby
  0 siblings, 0 replies; 4+ messages in thread
From: Jiri Slaby @ 2022-05-09 10:28 UTC (permalink / raw)
  To: D. Starke, linux-serial, gregkh; +Cc: linux-kernel

On 04. 05. 22, 10:17, D. Starke wrote:
> From: Daniel Starke <daniel.starke@siemens.com>
> 
> The current implementation activates the mux if it was restarted and opens
> the control channel if the mux was previously closed and we are now acting
> as initiator instead of responder, which is the default setting.
> This has two issues.
> 1) No mux is activated if we keep all default values and only switch to
> initiator. The control channel is not allocated but will be opened next
> which results in a NULL pointer dereference.
> 2) Switching the configuration after it was once configured while keeping
> the initiator value the same will not reopen the control channel if it was
> closed due to parameter incompatibilities. The mux remains dead.
> 
> Fix 1) by always activating the mux if it is dead after configuration.
> Fix 2) by always opening the control channel after mux activation.
> 
> Fixes: e1eaea46bb40 ("tty: n_gsm line discipline")
> Cc: stable@vger.kernel.org
> Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
> ---
>   drivers/tty/n_gsm.c | 12 ++++++++----
>   1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
> index 9b0b435cf26e..bcb714031d69 100644
> --- a/drivers/tty/n_gsm.c
> +++ b/drivers/tty/n_gsm.c
> @@ -2352,6 +2352,7 @@ static void gsm_copy_config_values(struct gsm_mux *gsm,
>   
>   static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c)
>   {
> +	int ret = 0;

Why is the initialization needed? You can as well declare the variable 
only inside the if below.

>   	int need_close = 0;
>   	int need_restart = 0;
>   
> @@ -2419,10 +2420,13 @@ static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c)
>   	 * FIXME: We need to separate activation/deactivation from adding
>   	 * and removing from the mux array
>   	 */
> -	if (need_restart)
> -		gsm_activate_mux(gsm);
> -	if (gsm->initiator && need_close)
> -		gsm_dlci_begin_open(gsm->dlci[0]);
> +	if (gsm->dead) {
> +		ret = gsm_activate_mux(gsm);
> +		if (ret)
> +			return ret;
> +		if (gsm->initiator)
> +			gsm_dlci_begin_open(gsm->dlci[0]);
> +	}
>   	return 0;
>   }
>   


-- 
js
suse labs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] tty: n_gsm: fix mux activation issues in gsm_config()
  2022-05-04  8:17 [PATCH 1/3] tty: n_gsm: fix buffer over-read in gsm_dlci_data() D. Starke
@ 2022-05-04  8:17 ` D. Starke
  2022-05-09 10:28   ` Jiri Slaby
  0 siblings, 1 reply; 4+ messages in thread
From: D. Starke @ 2022-05-04  8:17 UTC (permalink / raw)
  To: linux-serial, gregkh, jirislaby; +Cc: linux-kernel, Daniel Starke

From: Daniel Starke <daniel.starke@siemens.com>

The current implementation activates the mux if it was restarted and opens
the control channel if the mux was previously closed and we are now acting
as initiator instead of responder, which is the default setting.
This has two issues.
1) No mux is activated if we keep all default values and only switch to
initiator. The control channel is not allocated but will be opened next
which results in a NULL pointer dereference.
2) Switching the configuration after it was once configured while keeping
the initiator value the same will not reopen the control channel if it was
closed due to parameter incompatibilities. The mux remains dead.

Fix 1) by always activating the mux if it is dead after configuration.
Fix 2) by always opening the control channel after mux activation.

Fixes: e1eaea46bb40 ("tty: n_gsm line discipline")
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
---
 drivers/tty/n_gsm.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 9b0b435cf26e..bcb714031d69 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -2352,6 +2352,7 @@ static void gsm_copy_config_values(struct gsm_mux *gsm,
 
 static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c)
 {
+	int ret = 0;
 	int need_close = 0;
 	int need_restart = 0;
 
@@ -2419,10 +2420,13 @@ static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c)
 	 * FIXME: We need to separate activation/deactivation from adding
 	 * and removing from the mux array
 	 */
-	if (need_restart)
-		gsm_activate_mux(gsm);
-	if (gsm->initiator && need_close)
-		gsm_dlci_begin_open(gsm->dlci[0]);
+	if (gsm->dead) {
+		ret = gsm_activate_mux(gsm);
+		if (ret)
+			return ret;
+		if (gsm->initiator)
+			gsm_dlci_begin_open(gsm->dlci[0]);
+	}
 	return 0;
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-05-09 11:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09 11:03 [PATCH 2/3] tty: n_gsm: fix mux activation issues in gsm_config() Starke, Daniel
2022-05-09 11:13 ` Jiri Slaby
  -- strict thread matches above, loose matches on Subject: below --
2022-05-04  8:17 [PATCH 1/3] tty: n_gsm: fix buffer over-read in gsm_dlci_data() D. Starke
2022-05-04  8:17 ` [PATCH 2/3] tty: n_gsm: fix mux activation issues in gsm_config() D. Starke
2022-05-09 10:28   ` Jiri Slaby

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.