diff options
author | Phillip Lougher <phillip@lougher.demon.co.uk> | 2009-08-06 18:09:31 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-08-07 13:39:56 -0400 |
commit | b1af4315d823a2b6659c5b14bc17f7bc61878ef4 (patch) | |
tree | d9a04709f52c27f59a93875fd705dbed2c581b09 /lib | |
parent | daeb6b6fbe27049f465c48a7d0ee5555c3b84064 (diff) |
bzip2/lzma: remove nasty uncompressed size hack in pre-boot environment
decompress_bunzip2 and decompress_unlzma have a nasty hack that subtracts
4 from the input length if being called in the pre-boot environment.
This is a nasty hack because it relies on the fact that flush = NULL only
when called from the pre-boot environment (i.e.
arch/x86/boot/compressed/misc.c). initramfs.c/do_mounts_rd.c pass in a
flush buffer (flush != NULL).
This hack prevents the decompressors from being used with flush = NULL by
other callers unless knowledge of the hack is propagated to them.
This patch removes the hack by making decompress (called only from the
pre-boot environment) a wrapper function that subtracts 4 from the input
length before calling the decompressor.
Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/decompress_bunzip2.c | 22 | ||||
-rw-r--r-- | lib/decompress_unlzma.c | 21 |
2 files changed, 32 insertions, 11 deletions
diff --git a/lib/decompress_bunzip2.c b/lib/decompress_bunzip2.c index 708e2a86d87b..d3dc9f2beb27 100644 --- a/lib/decompress_bunzip2.c +++ b/lib/decompress_bunzip2.c | |||
@@ -45,9 +45,11 @@ | |||
45 | */ | 45 | */ |
46 | 46 | ||
47 | 47 | ||
48 | #ifndef STATIC | 48 | #ifdef STATIC |
49 | #define PREBOOT | ||
50 | #else | ||
49 | #include <linux/decompress/bunzip2.h> | 51 | #include <linux/decompress/bunzip2.h> |
50 | #endif /* !STATIC */ | 52 | #endif /* STATIC */ |
51 | 53 | ||
52 | #include <linux/decompress/mm.h> | 54 | #include <linux/decompress/mm.h> |
53 | #include <linux/slab.h> | 55 | #include <linux/slab.h> |
@@ -681,9 +683,7 @@ STATIC int INIT bunzip2(unsigned char *buf, int len, | |||
681 | set_error_fn(error_fn); | 683 | set_error_fn(error_fn); |
682 | if (flush) | 684 | if (flush) |
683 | outbuf = malloc(BZIP2_IOBUF_SIZE); | 685 | outbuf = malloc(BZIP2_IOBUF_SIZE); |
684 | else | 686 | |
685 | len -= 4; /* Uncompressed size hack active in pre-boot | ||
686 | environment */ | ||
687 | if (!outbuf) { | 687 | if (!outbuf) { |
688 | error("Could not allocate output bufer"); | 688 | error("Could not allocate output bufer"); |
689 | return -1; | 689 | return -1; |
@@ -733,4 +733,14 @@ exit_0: | |||
733 | return i; | 733 | return i; |
734 | } | 734 | } |
735 | 735 | ||
736 | #define decompress bunzip2 | 736 | #ifdef PREBOOT |
737 | STATIC int INIT decompress(unsigned char *buf, int len, | ||
738 | int(*fill)(void*, unsigned int), | ||
739 | int(*flush)(void*, unsigned int), | ||
740 | unsigned char *outbuf, | ||
741 | int *pos, | ||
742 | void(*error_fn)(char *x)) | ||
743 | { | ||
744 | return bunzip2(buf, len - 4, fill, flush, outbuf, pos, error_fn); | ||
745 | } | ||
746 | #endif | ||
diff --git a/lib/decompress_unlzma.c b/lib/decompress_unlzma.c index 32123a1340e6..d3f9468e49dc 100644 --- a/lib/decompress_unlzma.c +++ b/lib/decompress_unlzma.c | |||
@@ -29,7 +29,9 @@ | |||
29 | *Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 29 | *Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
30 | */ | 30 | */ |
31 | 31 | ||
32 | #ifndef STATIC | 32 | #ifdef STATIC |
33 | #define PREBOOT | ||
34 | #else | ||
33 | #include <linux/decompress/unlzma.h> | 35 | #include <linux/decompress/unlzma.h> |
34 | #endif /* STATIC */ | 36 | #endif /* STATIC */ |
35 | 37 | ||
@@ -543,9 +545,7 @@ STATIC inline int INIT unlzma(unsigned char *buf, int in_len, | |||
543 | int ret = -1; | 545 | int ret = -1; |
544 | 546 | ||
545 | set_error_fn(error_fn); | 547 | set_error_fn(error_fn); |
546 | if (!flush) | 548 | |
547 | in_len -= 4; /* Uncompressed size hack active in pre-boot | ||
548 | environment */ | ||
549 | if (buf) | 549 | if (buf) |
550 | inbuf = buf; | 550 | inbuf = buf; |
551 | else | 551 | else |
@@ -645,4 +645,15 @@ exit_0: | |||
645 | return ret; | 645 | return ret; |
646 | } | 646 | } |
647 | 647 | ||
648 | #define decompress unlzma | 648 | #ifdef PREBOOT |
649 | STATIC int INIT decompress(unsigned char *buf, int in_len, | ||
650 | int(*fill)(void*, unsigned int), | ||
651 | int(*flush)(void*, unsigned int), | ||
652 | unsigned char *output, | ||
653 | int *posp, | ||
654 | void(*error_fn)(char *x) | ||
655 | ) | ||
656 | { | ||
657 | return unlzma(buf, in_len - 4, fill, flush, output, posp, error_fn); | ||
658 | } | ||
659 | #endif | ||