Skip to content

Commit fac842f

Browse files
gregkhJiri Slaby
authored andcommitted
lz4: add overrun checks to lz4_uncompress_unknownoutputsize()
commit 4a3a990 upstream. 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 <JBeulich@suse.com> Cc: "Don A. Bailey" <donb@securitymouse.com> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
1 parent 2f18244 commit fac842f

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎lib/lz4/lz4_decompress.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ static int lz4_uncompress_unknownoutputsize(const char *source, char *dest,
192192
int s = 255;
193193
while ((ip < iend) && (s == 255)) {
194194
s = *ip++;
195+
if (unlikely(length > (size_t)(length + s)))
196+
goto _output_error;
195197
length += s;
196198
}
197199
}
@@ -232,6 +234,8 @@ static int lz4_uncompress_unknownoutputsize(const char *source, char *dest,
232234
if (length == ML_MASK) {
233235
while (ip < iend) {
234236
int s = *ip++;
237+
if (unlikely(length > (size_t)(length + s)))
238+
goto _output_error;
235239
length += s;
236240
if (s == 255)
237241
continue;
@@ -284,7 +288,7 @@ static int lz4_uncompress_unknownoutputsize(const char *source, char *dest,
284288

285289
/* write overflow error detected */
286290
_output_error:
287-
return (int) (-(((char *) ip) - source));
291+
return -1;
288292
}
289293

290294
int lz4_decompress(const unsigned char *src, size_t *src_len,

0 commit comments

Comments
 (0)