All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for 4.19] speakup: Reject setting the speakup line discipline outside of speakup
@ 2020-12-09 10:26 Samuel Thibault
  2020-12-09 10:54 ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: Samuel Thibault @ 2020-12-09 10:26 UTC (permalink / raw)
  To: stable

[backport of 5.10 commit f0992098cadb4c9c6a00703b66cafe604e178fea]

Speakup exposing a line discipline allows userland to try to use it,
while it is deemed to be useless, and thus uselessly exposes potential
bugs. One of them is simply that in such a case if the line sends data,
spk_ttyio_receive_buf2 is called and crashes since spk_ttyio_synth
is NULL.

This change restricts the use of the speakup line discipline to
speakup drivers, thus avoiding such kind of issues altogether.

Cc: stable@vger.kernel.org
Reported-by: Shisong Qin <qinshisong1205@gmail.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Tested-by: Shisong Qin <qinshisong1205@gmail.com>
Link: https://lore.kernel.org/r/20201129193523.hm3f6n5xrn6fiyyc@function
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

diff --git a/drivers/staging/speakup/spk_ttyio.c b/drivers/staging/speakup/spk_ttyio.c
index 669392f31d4e..6284aff434a1 100644
--- a/drivers/staging/speakup/spk_ttyio.c
+++ b/drivers/staging/speakup/spk_ttyio.c
@@ -47,27 +47,20 @@ static int spk_ttyio_ldisc_open(struct tty_struct *tty)
 {
 	struct spk_ldisc_data *ldisc_data;
 
+	if (tty != speakup_tty)
+		/* Somebody tried to use this line discipline outside speakup */
+		return -ENODEV;
+
 	if (tty->ops->write == NULL)
 		return -EOPNOTSUPP;
 
-	mutex_lock(&speakup_tty_mutex);
-	if (speakup_tty) {
-		mutex_unlock(&speakup_tty_mutex);
-		return -EBUSY;
-	}
-	speakup_tty = tty;
-
 	ldisc_data = kmalloc(sizeof(struct spk_ldisc_data), GFP_KERNEL);
-	if (!ldisc_data) {
-		speakup_tty = NULL;
-		mutex_unlock(&speakup_tty_mutex);
+	if (!ldisc_data)
 		return -ENOMEM;
-	}
 
 	sema_init(&ldisc_data->sem,  0);
 	ldisc_data->buf_free = true;
-	speakup_tty->disc_data = ldisc_data;
-	mutex_unlock(&speakup_tty_mutex);
+	tty->disc_data = ldisc_data;
 
 	return 0;
 }
@@ -191,9 +184,25 @@ static int spk_ttyio_initialise_ldisc(struct spk_synth *synth)
 
 	tty_unlock(tty);
 
+	mutex_lock(&speakup_tty_mutex);
+	speakup_tty = tty;
 	ret = tty_set_ldisc(tty, N_SPEAKUP);
 	if (ret)
-		pr_err("speakup: Failed to set N_SPEAKUP on tty\n");
+		speakup_tty = NULL;
+	mutex_unlock(&speakup_tty_mutex);
+
+	if (!ret)
+		/* Success */
+		return 0;
+
+	pr_err("speakup: Failed to set N_SPEAKUP on tty\n");
+
+	tty_lock(tty);
+	if (tty->ops->close)
+		tty->ops->close(tty, NULL);
+	tty_unlock(tty);
+
+	tty_kclose(tty);
 
 	return ret;
 }



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

* Re: [PATCH for 4.19] speakup: Reject setting the speakup line discipline outside of speakup
  2020-12-09 10:26 [PATCH for 4.19] speakup: Reject setting the speakup line discipline outside of speakup Samuel Thibault
@ 2020-12-09 10:54 ` Greg KH
  2020-12-09 11:03   ` Samuel Thibault
  0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2020-12-09 10:54 UTC (permalink / raw)
  To: Samuel Thibault, stable

On Wed, Dec 09, 2020 at 11:26:40AM +0100, Samuel Thibault wrote:
> [backport of 5.10 commit f0992098cadb4c9c6a00703b66cafe604e178fea]
> 
> Speakup exposing a line discipline allows userland to try to use it,
> while it is deemed to be useless, and thus uselessly exposes potential
> bugs. One of them is simply that in such a case if the line sends data,
> spk_ttyio_receive_buf2 is called and crashes since spk_ttyio_synth
> is NULL.
> 
> This change restricts the use of the speakup line discipline to
> speakup drivers, thus avoiding such kind of issues altogether.
> 
> Cc: stable@vger.kernel.org
> Reported-by: Shisong Qin <qinshisong1205@gmail.com>
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> Tested-by: Shisong Qin <qinshisong1205@gmail.com>
> Link: https://lore.kernel.org/r/20201129193523.hm3f6n5xrn6fiyyc@function
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

This, and the 4.14.y backport, fail to apply:

patching file drivers/staging/speakup/spk_ttyio.c
Hunk #1 FAILED at 47.
Hunk #2 succeeded at 187 (offset -4 lines).
1 out of 2 hunks FAILED -- rejects in file drivers/staging/speakup/spk_ttyio.c

What tree(s) did you make the patch against?

thanks,

greg k-h

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

* Re: [PATCH for 4.19] speakup: Reject setting the speakup line discipline outside of speakup
  2020-12-09 10:54 ` Greg KH
@ 2020-12-09 11:03   ` Samuel Thibault
  2020-12-09 11:06     ` Samuel Thibault
  2020-12-09 11:09     ` Greg KH
  0 siblings, 2 replies; 6+ messages in thread
From: Samuel Thibault @ 2020-12-09 11:03 UTC (permalink / raw)
  To: Greg KH; +Cc: stable

Greg KH, le mer. 09 déc. 2020 11:54:54 +0100, a ecrit:
> This, and the 4.14.y backport, fail to apply:
> 
> patching file drivers/staging/speakup/spk_ttyio.c
> Hunk #1 FAILED at 47.
> Hunk #2 succeeded at 187 (offset -4 lines).
> 1 out of 2 hunks FAILED -- rejects in file drivers/staging/speakup/spk_ttyio.c
> 
> What tree(s) did you make the patch against?

I used 4.19.162 and 4.14.211 tarballs. But now I realize that I used
patch -l, without it there are small whitespace differences. Can you
apply them with -l, or should I fix the whitespacing?

Samuel

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

* Re: [PATCH for 4.19] speakup: Reject setting the speakup line discipline outside of speakup
  2020-12-09 11:03   ` Samuel Thibault
@ 2020-12-09 11:06     ` Samuel Thibault
  2020-12-09 11:09     ` Greg KH
  1 sibling, 0 replies; 6+ messages in thread
From: Samuel Thibault @ 2020-12-09 11:06 UTC (permalink / raw)
  To: Greg KH, stable

Samuel Thibault, le mer. 09 déc. 2020 12:03:24 +0100, a ecrit:
> Can you apply them with -l, or should I fix the whitespacing?

Don't bother, I found the difference, will post fixed patches.

Samuel

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

* Re: [PATCH for 4.19] speakup: Reject setting the speakup line discipline outside of speakup
  2020-12-09 11:03   ` Samuel Thibault
  2020-12-09 11:06     ` Samuel Thibault
@ 2020-12-09 11:09     ` Greg KH
  1 sibling, 0 replies; 6+ messages in thread
From: Greg KH @ 2020-12-09 11:09 UTC (permalink / raw)
  To: Samuel Thibault, stable

On Wed, Dec 09, 2020 at 12:03:24PM +0100, Samuel Thibault wrote:
> Greg KH, le mer. 09 déc. 2020 11:54:54 +0100, a ecrit:
> > This, and the 4.14.y backport, fail to apply:
> > 
> > patching file drivers/staging/speakup/spk_ttyio.c
> > Hunk #1 FAILED at 47.
> > Hunk #2 succeeded at 187 (offset -4 lines).
> > 1 out of 2 hunks FAILED -- rejects in file drivers/staging/speakup/spk_ttyio.c
> > 
> > What tree(s) did you make the patch against?
> 
> I used 4.19.162 and 4.14.211 tarballs. But now I realize that I used
> patch -l, without it there are small whitespace differences. Can you
> apply them with -l, or should I fix the whitespacing?

Can you fix the whitespace please?  quilt and git don't like applying
patches with messed up whitespace from what I can tell :(

thanks,

greg k-h

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

* [PATCH for 4.19] speakup: Reject setting the speakup line discipline outside of speakup
@ 2020-12-09 11:07 Samuel Thibault
  0 siblings, 0 replies; 6+ messages in thread
From: Samuel Thibault @ 2020-12-09 11:07 UTC (permalink / raw)
  To: stable

[backport of 5.10 commit f0992098cadb4c9c6a00703b66cafe604e178fea]

Speakup exposing a line discipline allows userland to try to use it,
while it is deemed to be useless, and thus uselessly exposes potential
bugs. One of them is simply that in such a case if the line sends data,
spk_ttyio_receive_buf2 is called and crashes since spk_ttyio_synth
is NULL.

This change restricts the use of the speakup line discipline to
speakup drivers, thus avoiding such kind of issues altogether.

Cc: stable@vger.kernel.org
Reported-by: Shisong Qin <qinshisong1205@gmail.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Tested-by: Shisong Qin <qinshisong1205@gmail.com>
Link: https://lore.kernel.org/r/20201129193523.hm3f6n5xrn6fiyyc@function
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

diff --git a/drivers/staging/speakup/spk_ttyio.c b/drivers/staging/speakup/spk_ttyio.c
index 669392f31d4e..6284aff434a1 100644
--- a/drivers/staging/speakup/spk_ttyio.c
+++ b/drivers/staging/speakup/spk_ttyio.c
@@ -47,27 +47,20 @@ static int spk_ttyio_ldisc_open(struct tty_struct *tty)
 {
 	struct spk_ldisc_data *ldisc_data;
 
+	if (tty != speakup_tty)
+		/* Somebody tried to use this line discipline outside speakup */
+		return -ENODEV;
+
 	if (tty->ops->write == NULL)
 		return -EOPNOTSUPP;
 
-	mutex_lock(&speakup_tty_mutex);
-	if (speakup_tty) {
-		mutex_unlock(&speakup_tty_mutex);
-		return -EBUSY;
-	}
-	speakup_tty = tty;
-
 	ldisc_data = kmalloc(sizeof(struct spk_ldisc_data), GFP_KERNEL);
-	if (!ldisc_data) {
-		speakup_tty = NULL;
-		mutex_unlock(&speakup_tty_mutex);
+	if (!ldisc_data)
 		return -ENOMEM;
-	}
 
 	sema_init(&ldisc_data->sem, 0);
 	ldisc_data->buf_free = true;
-	speakup_tty->disc_data = ldisc_data;
-	mutex_unlock(&speakup_tty_mutex);
+	tty->disc_data = ldisc_data;
 
 	return 0;
 }
@@ -191,9 +184,25 @@ static int spk_ttyio_initialise_ldisc(struct spk_synth *synth)
 
 	tty_unlock(tty);
 
+	mutex_lock(&speakup_tty_mutex);
+	speakup_tty = tty;
 	ret = tty_set_ldisc(tty, N_SPEAKUP);
 	if (ret)
-		pr_err("speakup: Failed to set N_SPEAKUP on tty\n");
+		speakup_tty = NULL;
+	mutex_unlock(&speakup_tty_mutex);
+
+	if (!ret)
+		/* Success */
+		return 0;
+
+	pr_err("speakup: Failed to set N_SPEAKUP on tty\n");
+
+	tty_lock(tty);
+	if (tty->ops->close)
+		tty->ops->close(tty, NULL);
+	tty_unlock(tty);
+
+	tty_kclose(tty);
 
 	return ret;
 }




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

end of thread, other threads:[~2020-12-09 16:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-09 10:26 [PATCH for 4.19] speakup: Reject setting the speakup line discipline outside of speakup Samuel Thibault
2020-12-09 10:54 ` Greg KH
2020-12-09 11:03   ` Samuel Thibault
2020-12-09 11:06     ` Samuel Thibault
2020-12-09 11:09     ` Greg KH
2020-12-09 11:07 Samuel Thibault

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.