Skip to content

Commit 4963bb2

Browse files
terrellnIngo Molnar
authored and
Ingo Molnar
committed
lib: Add zstd support to decompress
- 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]
1 parent 6d25a63 commit 4963bb2

File tree

5 files changed

+366
-0
lines changed

5 files changed

+366
-0
lines changed

include/linux/decompress/unzstd.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef LINUX_DECOMPRESS_UNZSTD_H
3+
#define LINUX_DECOMPRESS_UNZSTD_H
4+
5+
int unzstd(unsigned char *inbuf, long len,
6+
long (*fill)(void*, unsigned long),
7+
long (*flush)(void*, unsigned long),
8+
unsigned char *output,
9+
long *pos,
10+
void (*error_fn)(char *x));
11+
#endif

lib/Kconfig

+4
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ config DECOMPRESS_LZ4
342342
select LZ4_DECOMPRESS
343343
tristate
344344

345+
config DECOMPRESS_ZSTD
346+
select ZSTD_DECOMPRESS
347+
tristate
348+
345349
#
346350
# Generic allocator support is selected if needed
347351
#

lib/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o
170170
lib-$(CONFIG_DECOMPRESS_XZ) += decompress_unxz.o
171171
lib-$(CONFIG_DECOMPRESS_LZO) += decompress_unlzo.o
172172
lib-$(CONFIG_DECOMPRESS_LZ4) += decompress_unlz4.o
173+
lib-$(CONFIG_DECOMPRESS_ZSTD) += decompress_unzstd.o
173174

174175
obj-$(CONFIG_TEXTSEARCH) += textsearch.o
175176
obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o

lib/decompress.c

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/decompress/inflate.h>
1414
#include <linux/decompress/unlzo.h>
1515
#include <linux/decompress/unlz4.h>
16+
#include <linux/decompress/unzstd.h>
1617

1718
#include <linux/types.h>
1819
#include <linux/string.h>
@@ -37,6 +38,9 @@
3738
#ifndef CONFIG_DECOMPRESS_LZ4
3839
# define unlz4 NULL
3940
#endif
41+
#ifndef CONFIG_DECOMPRESS_ZSTD
42+
# define unzstd NULL
43+
#endif
4044

4145
struct compress_format {
4246
unsigned char magic[2];
@@ -52,6 +56,7 @@ static const struct compress_format compressed_formats[] __initconst = {
5256
{ {0xfd, 0x37}, "xz", unxz },
5357
{ {0x89, 0x4c}, "lzo", unlzo },
5458
{ {0x02, 0x21}, "lz4", unlz4 },
59+
{ {0x28, 0xb5}, "zstd", unzstd },
5560
{ {0, 0}, NULL, NULL }
5661
};
5762

0 commit comments

Comments
 (0)