Skip to content

Commit

Permalink
lib: Add zstd support to decompress
Browse files Browse the repository at this point in the history
- Add unzstd() and the zstd decompress interface.

- Add zstd support to decompress_method().

The decompress_method() and unzstd() functions are used to decompress
the initramfs and the initrd. The __decompress() function is used in
the preboot environment to decompress a zstd compressed kernel.

The zstd decompression function allows the input and output buffers to
overlap because that is used by x86 kernel decompression.

Signed-off-by: Nick Terrell <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Tested-by: Sedat Dilek <[email protected]>
Reviewed-by: Kees Cook <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
terrelln authored and Ingo Molnar committed Jul 31, 2020
1 parent 6d25a63 commit 4963bb2
Show file tree
Hide file tree
Showing 5 changed files with 366 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/linux/decompress/unzstd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef LINUX_DECOMPRESS_UNZSTD_H
#define LINUX_DECOMPRESS_UNZSTD_H

int unzstd(unsigned char *inbuf, long len,
long (*fill)(void*, unsigned long),
long (*flush)(void*, unsigned long),
unsigned char *output,
long *pos,
void (*error_fn)(char *x));
#endif
4 changes: 4 additions & 0 deletions lib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ config DECOMPRESS_LZ4
select LZ4_DECOMPRESS
tristate

config DECOMPRESS_ZSTD
select ZSTD_DECOMPRESS
tristate

#
# Generic allocator support is selected if needed
#
Expand Down
1 change: 1 addition & 0 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o
lib-$(CONFIG_DECOMPRESS_XZ) += decompress_unxz.o
lib-$(CONFIG_DECOMPRESS_LZO) += decompress_unlzo.o
lib-$(CONFIG_DECOMPRESS_LZ4) += decompress_unlz4.o
lib-$(CONFIG_DECOMPRESS_ZSTD) += decompress_unzstd.o

obj-$(CONFIG_TEXTSEARCH) += textsearch.o
obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o
Expand Down
5 changes: 5 additions & 0 deletions lib/decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/decompress/inflate.h>
#include <linux/decompress/unlzo.h>
#include <linux/decompress/unlz4.h>
#include <linux/decompress/unzstd.h>

#include <linux/types.h>
#include <linux/string.h>
Expand All @@ -37,6 +38,9 @@
#ifndef CONFIG_DECOMPRESS_LZ4
# define unlz4 NULL
#endif
#ifndef CONFIG_DECOMPRESS_ZSTD
# define unzstd NULL
#endif

struct compress_format {
unsigned char magic[2];
Expand All @@ -52,6 +56,7 @@ static const struct compress_format compressed_formats[] __initconst = {
{ {0xfd, 0x37}, "xz", unxz },
{ {0x89, 0x4c}, "lzo", unlzo },
{ {0x02, 0x21}, "lz4", unlz4 },
{ {0x28, 0xb5}, "zstd", unzstd },
{ {0, 0}, NULL, NULL }
};

Expand Down
Loading

0 comments on commit 4963bb2

Please sign in to comment.