Discussion:
[PATCH] staging: speakup: fix wraparound in uaccess length check
Samuel Thibault
2018-07-07 08:13:47 UTC
Permalink
@@ -257,6 +257,8 @@ static ssize_t softsynthx_read(struct file *fp, char __user *buf, size_t count,
0x80 | (ch & 0x3f)
};
+ if (chars_sent + 2 > count)
+ break;
if (copy_to_user(cp, s, sizeof(s)))
return -EFAULT;
Err, but then we have lost 'ch' that was consumed by the
synth_buffer_getc() call, so the fix seems wrong to me.

Nacked-by: Samuel Thibault <***@ens-lyon.org>

Samuel
Samuel Thibault
2018-07-07 08:29:26 UTC
Permalink
Re,

Could you review, test, and resubmit the patch below instead?

Samuel


If softsynthx_read() is called with `count < 3`, `count - 3` wraps, causing
the loop to copy as much data as available to the provided buffer. If
softsynthx_read() is invoked through sys_splice(), this causes an
unbounded kernel write; but even when userspace just reads from it
normally, a small size could cause userspace crashes.

Fixes: 425e586cf95b ("speakup: add unicode variant of /dev/softsynth")
Cc: ***@vger.kernel.org
Signed-off-by: Samuel Thibault <***@ens-lyon.org>

--- a/drivers/staging/speakup/speakup_soft.c
+++ b/drivers/staging/speakup/speakup_soft.c
@@ -198,11 +198,15 @@ static ssize_t softsynthx_read(struct fi
int chars_sent = 0;
char __user *cp;
char *init;
+ size_t bytes_per_ch = unicode ? 3 : 1;
u16 ch;
int empty;
unsigned long flags;
DEFINE_WAIT(wait);

+ if (count < bytes_per_ch)
+ return -EINVAL;
+
spin_lock_irqsave(&speakup_info.spinlock, flags);
while (1) {
prepare_to_wait(&speakup_event, &wait, TASK_INTERRUPTIBLE);
@@ -228,7 +232,7 @@ static ssize_t softsynthx_read(struct fi
init = get_initstring();

/* Keep 3 bytes available for a 16bit UTF-8-encoded character */
- while (chars_sent <= count - 3) {
+ while (chars_sent <= count - bytes_per_ch) {
if (speakup_info.flushing) {
speakup_info.flushing = 0;
ch = '\x18';
Samuel Thibault
2018-07-11 09:44:51 UTC
Permalink
Hello,
On Sat, Jul 7, 2018 at 1:29 AM Samuel Thibault
Post by Samuel Thibault
Could you review, test, and resubmit the patch below instead?
Er... you mean, you want me to take your patch, add my Signed-off-by
below yours, and then send that?
Yes, please.
Some random thing I noticed, but I don't think it has anything to do
with this issue: In some runs, when the console is repeatedly printing
"Debian GNU/Linux 9 debian tty1\n\ndebian login: " in response to me
pressing enter repeatedly, /dev/softsynthu (read in 1-byte steps)
seems to return things like "Debian GNU slash Linux 9 debian tty1 \n
debi login: ". I don't understand why it sometimes says "debi login"
instead of "debian login".
It's odd indeed, but I agree it's unrelated.

Samuel

Samuel Thibault
2018-07-07 08:32:19 UTC
Permalink
Or should I rewrite the
patch to be simple and just bail out on `count < 3`?
Our mails have crossed :)

I believe what I sent is correct: for softsynth it does not make sense
to have room for less than 1 (non-unicode) or 3 (unicode) bytes.

Samuel
Loading...