Skip to content

Commit ad97989

Browse files
Alan Coxdavem330
authored andcommitted
6pack: fix buffer length mishandling
Dmitry Vyukov wrote: > different runs). Looking at code, the following looks suspicious -- we > limit copy by 512 bytes, but use the original count which can be > larger than 512: > > static void sixpack_receive_buf(struct tty_struct *tty, > const unsigned char *cp, char *fp, int count) > { > unsigned char buf[512]; > .... > memcpy(buf, cp, count < sizeof(buf) ? count : sizeof(buf)); > .... > sixpack_decode(sp, buf, count1); With the sane tty locking we now have I believe the following is safe as we consume the bytes and move them into the decoded buffer before returning. Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5737f6c commit ad97989

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

‎drivers/net/hamradio/6pack.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ struct sixpack {
127127

128128
#define AX25_6PACK_HEADER_LEN 0
129129

130-
static void sixpack_decode(struct sixpack *, unsigned char[], int);
130+
static void sixpack_decode(struct sixpack *, const unsigned char[], int);
131131
static int encode_sixpack(unsigned char *, unsigned char *, int, unsigned char);
132132

133133
/*
@@ -428,15 +428,14 @@ static void sixpack_write_wakeup(struct tty_struct *tty)
428428

429429
/*
430430
* Handle the 'receiver data ready' interrupt.
431-
* This function is called by the 'tty_io' module in the kernel when
431+
* This function is called by the tty module in the kernel when
432432
* a block of 6pack data has been received, which can now be decapsulated
433433
* and sent on to some IP layer for further processing.
434434
*/
435435
static void sixpack_receive_buf(struct tty_struct *tty,
436436
const unsigned char *cp, char *fp, int count)
437437
{
438438
struct sixpack *sp;
439-
unsigned char buf[512];
440439
int count1;
441440

442441
if (!count)
@@ -446,10 +445,7 @@ static void sixpack_receive_buf(struct tty_struct *tty,
446445
if (!sp)
447446
return;
448447

449-
memcpy(buf, cp, count < sizeof(buf) ? count : sizeof(buf));
450-
451448
/* Read the characters out of the buffer */
452-
453449
count1 = count;
454450
while (count) {
455451
count--;
@@ -459,7 +455,7 @@ static void sixpack_receive_buf(struct tty_struct *tty,
459455
continue;
460456
}
461457
}
462-
sixpack_decode(sp, buf, count1);
458+
sixpack_decode(sp, cp, count1);
463459

464460
sp_put(sp);
465461
tty_unthrottle(tty);
@@ -992,7 +988,7 @@ static void decode_std_command(struct sixpack *sp, unsigned char cmd)
992988
/* decode a 6pack packet */
993989

994990
static void
995-
sixpack_decode(struct sixpack *sp, unsigned char *pre_rbuff, int count)
991+
sixpack_decode(struct sixpack *sp, const unsigned char *pre_rbuff, int count)
996992
{
997993
unsigned char inbyte;
998994
int count1;

0 commit comments

Comments
 (0)