Skip to content

Commit

Permalink
via-cuda: Prevent read buffer overflow
Browse files Browse the repository at this point in the history
If the Cuda driver does not enter the 'read_done' state for some
reason, it may continue in the 'reading' state until the buffer
overflows. Add a bounds check to prevent this.

Tested-by: Stan Johnson <userm57@yahoo.com>
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
  • Loading branch information
Finn Thain authored and Michael Ellerman committed Feb 7, 2017
1 parent fd7a65a commit fe73b58
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion drivers/macintosh/via-cuda.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ cuda_poll(void)
}
EXPORT_SYMBOL(cuda_poll);

#define ARRAY_FULL(a, p) ((p) - (a) == ARRAY_SIZE(a))

static irqreturn_t
cuda_interrupt(int irq, void *arg)
{
Expand Down Expand Up @@ -558,7 +560,11 @@ cuda_interrupt(int irq, void *arg)
break;

case reading:
*reply_ptr++ = in_8(&via[SR]);
if (reading_reply ? ARRAY_FULL(current_req->reply, reply_ptr)
: ARRAY_FULL(cuda_rbuf, reply_ptr))
(void)in_8(&via[SR]);
else
*reply_ptr++ = in_8(&via[SR]);
if (!TREQ_asserted(status)) {
/* that's all folks */
negate_TIP_and_TACK();
Expand Down

0 comments on commit fe73b58

Please sign in to comment.