Skip to content

Commit

Permalink
lzma/gzip: fix potential oops when input data is truncated
Browse files Browse the repository at this point in the history
If the lzma/gzip decompressors are called with insufficient input data
(len > 0 & fill = NULL), they will attempt to call the fill function to
obtain more data, leading to a kernel oops.

Signed-off-by: Phillip Lougher <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Phillip Lougher authored and torvalds committed Sep 24, 2009
1 parent 3354f73 commit 6a88116
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/decompress_inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@

#define GZIP_IOBUF_SIZE (16*1024)

static int nofill(void *buffer, unsigned int len)
{
return -1;
}

/* Included from initramfs et al code */
STATIC int INIT gunzip(unsigned char *buf, int len,
int(*fill)(void*, unsigned int),
Expand Down Expand Up @@ -76,6 +81,9 @@ STATIC int INIT gunzip(unsigned char *buf, int len,
goto gunzip_nomem4;
}

if (!fill)
fill = nofill;

if (len == 0)
len = fill(zbuf, GZIP_IOBUF_SIZE);

Expand Down
10 changes: 9 additions & 1 deletion lib/decompress_unlzma.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ struct rc {
#define RC_MODEL_TOTAL_BITS 11


static int nofill(void *buffer, unsigned int len)
{
return -1;
}

/* Called twice: once at startup and once in rc_normalize() */
static void INIT rc_read(struct rc *rc)
{
Expand All @@ -97,7 +102,10 @@ static inline void INIT rc_init(struct rc *rc,
int (*fill)(void*, unsigned int),
char *buffer, int buffer_size)
{
rc->fill = fill;
if (fill)
rc->fill = fill;
else
rc->fill = nofill;
rc->buffer = (uint8_t *)buffer;
rc->buffer_size = buffer_size;
rc->buffer_end = rc->buffer + rc->buffer_size;
Expand Down

0 comments on commit 6a88116

Please sign in to comment.