Skip to content

Commit

Permalink
lz4: add overrun checks to lz4_uncompress_unknownoutputsize()
Browse files Browse the repository at this point in the history
Jan points out that I forgot to make the needed fixes to the
lz4_uncompress_unknownoutputsize() function to mirror the changes done
in lz4_decompress() with regards to potential pointer overflows.

The only in-kernel user of this function is the zram code, which only
takes data from a valid compressed buffer that it made itself, so it's
not a big issue.  But due to external kernel modules using this
function, it's better to be safe here.

Reported-by: Jan Beulich <[email protected]>
Cc: "Don A. Bailey" <[email protected]>
Cc: stable <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
gregkh committed Jul 3, 2014
1 parent ecca47c commit 4a3a990
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/lz4/lz4_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ static int lz4_uncompress_unknownoutputsize(const char *source, char *dest,
int s = 255;
while ((ip < iend) && (s == 255)) {
s = *ip++;
if (unlikely(length > (size_t)(length + s)))
goto _output_error;
length += s;
}
}
Expand Down Expand Up @@ -232,6 +234,8 @@ static int lz4_uncompress_unknownoutputsize(const char *source, char *dest,
if (length == ML_MASK) {
while (ip < iend) {
int s = *ip++;
if (unlikely(length > (size_t)(length + s)))
goto _output_error;
length += s;
if (s == 255)
continue;
Expand Down Expand Up @@ -284,7 +288,7 @@ static int lz4_uncompress_unknownoutputsize(const char *source, char *dest,

/* write overflow error detected */
_output_error:
return (int) (-(((char *) ip) - source));
return -1;
}

int lz4_decompress(const unsigned char *src, size_t *src_len,
Expand Down

0 comments on commit 4a3a990

Please sign in to comment.