android_kernel_xiaomi_sm7250/lib
Dimitri John Ledkov a12a6a2d7c lib/decompress_unlz4.c: correctly handle zero-padding around initrds.
[ Upstream commit 2c484419efc09e7234c667aa72698cb79ba8d8ed ]

lz4 compatible decompressor is simple.  The format is underspecified and
relies on EOF notification to determine when to stop.  Initramfs buffer
format[1] explicitly states that it can have arbitrary number of zero
padding.  Thus when operating without a fill function, be extra careful to
ensure that sizes less than 4, or apperantly empty chunksizes are treated
as EOF.

To test this I have created two cpio initrds, first a normal one,
main.cpio.  And second one with just a single /test-file with content
"second" second.cpio.  Then i compressed both of them with gzip, and with
lz4 -l.  Then I created a padding of 4 bytes (dd if=/dev/zero of=pad4 bs=1
count=4).  To create four testcase initrds:

 1) main.cpio.gzip + extra.cpio.gzip = pad0.gzip
 2) main.cpio.lz4  + extra.cpio.lz4 = pad0.lz4
 3) main.cpio.gzip + pad4 + extra.cpio.gzip = pad4.gzip
 4) main.cpio.lz4  + pad4 + extra.cpio.lz4 = pad4.lz4

The pad4 test-cases replicate the initrd load by grub, as it pads and
aligns every initrd it loads.

All of the above boot, however /test-file was not accessible in the initrd
for the testcase #4, as decoding in lz4 decompressor failed.  Also an
error message printed which usually is harmless.

Whith a patched kernel, all of the above testcases now pass, and
/test-file is accessible.

This fixes lz4 initrd decompress warning on every boot with grub.  And
more importantly this fixes inability to load multiple lz4 compressed
initrds with grub.  This patch has been shipping in Ubuntu kernels since
January 2021.

[1] ./Documentation/driver-api/early-userspace/buffer-format.rst

BugLink: https://bugs.launchpad.net/bugs/1835660
Link: https://lore.kernel.org/lkml/20210114200256.196589-1-xnox@ubuntu.com/ # v0
Link: https://lkml.kernel.org/r/20210513104831.432975-1-dimitri.ledkov@canonical.com
Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
Cc: Kyungsik Lee <kyungsik.lee@lge.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Bongkyu Kim <bongkyu.kim@lge.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Sven Schmidt <4sschmid@informatik.uni-hamburg.de>
Cc: Rajat Asthana <thisisrast7@gmail.com>
Cc: Nick Terrell <terrelln@fb.com>
Cc: Gao Xiang <hsiangkao@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-07-20 16:16:10 +02:00
..
842
fonts Fonts: Replace discarded const qualifier 2020-11-10 12:35:57 +01:00
lz4
lzo
mpi lib/mpi: Fix 64-bit MIPS build with Clang 2020-06-22 09:05:14 +02:00
raid6 lib/raid6: use vdupq_n_u8 to avoid endianness warnings 2020-04-23 10:30:15 +02:00
reed_solomon
xz
zlib_deflate
zlib_inflate lib/zlib: remove outdated and incorrect pre-increment optimization 2020-06-25 15:33:02 +02:00
zstd
.gitignore
argv_split.c
ashldi3.c
ashrdi3.c
asn1_decoder.c
assoc_array.c
atomic64_test.c
atomic64.c
audit.c
bcd.c
bch.c
bitmap.c lib/bitmap.c: fix remaining space computation in bitmap_print_to_pagebuf 2019-12-01 09:17:08 +01:00
bitrev.c
bsearch.c
btree.c
bucket_locks.c
bug.c bug: Remove redundant condition check in report_bug 2021-05-22 10:59:35 +02:00
build_OID_registry
bust_spinlocks.c
chacha20.c crypto: chacha20 - Fix chacha20_block() keystream alignment (again) 2019-11-20 18:47:11 +01:00
check_signature.c
checksum.c
clz_ctz.c
clz_tab.c
cmdline.c
cmpdi2.c
compat_audit.c
cordic.c
cpu_rmap.c
cpumask.c
crc4.c
crc7.c
crc8.c
crc16.c
crc32.c lib/crc32.c: fix trivial typo in preprocessor condition 2020-10-30 10:38:21 +01:00
crc32defs.h
crc32test.c lib/crc32test: remove extra local_irq_disable/enable 2020-11-10 12:35:57 +01:00
crc64.c
crc-ccitt.c
crc-itu-t.c
crc-t10dif.c
ctype.c
debug_info.c
debug_locks.c
debugobjects.c
dec_and_lock.c
decompress_bunzip2.c
decompress_inflate.c
decompress_unlz4.c lib/decompress_unlz4.c: correctly handle zero-padding around initrds. 2021-07-20 16:16:10 +02:00
decompress_unlzma.c
decompress_unlzo.c
decompress_unxz.c
decompress.c
devres.c lib: devres: add a helper function for ioremap_uc 2020-05-10 10:30:11 +02:00
digsig.c
div64.c
dump_stack.c dump_stack: avoid the livelock of the dump_lock 2019-11-12 19:20:37 +01:00
dynamic_debug.c dyndbg: fix a BUG_ON in ddebug_describe_flags 2020-08-19 08:14:53 +02:00
dynamic_queue_limits.c
earlycpio.c
error-inject.c
errseq.c
extable.c
fault-inject.c
fdt_empty_tree.c
fdt_ro.c
fdt_rw.c
fdt_strerror.c
fdt_sw.c
fdt_wip.c
fdt.c
find_bit_benchmark.c
find_bit.c uapi: rename ext2_swab() to swab() and share globally in swab.h 2020-04-17 10:48:43 +02:00
flex_array.c
flex_proportions.c
gcd.c
gen_crc32table.c
gen_crc64table.c
genalloc.c lib/genalloc: fix the overflow when size is too big 2021-01-12 20:10:16 +01:00
glob.c
globtest.c
hexdump.c
hweight.c
idr.c idr: Fix idr_get_next_ul race with idr_remove 2019-12-17 20:36:02 +01:00
inflate.c
int_sqrt.c
interval_tree_test.c
interval_tree.c
iomap_copy.c
iomap.c
iommu-helper.c
ioremap.c
iov_iter.c iov_iter_fault_in_readable() should do nothing in xarray case 2021-07-20 16:15:39 +02:00
irq_poll.c
irq_regs.c
is_single_threaded.c
jedec_ddr_data.c
kasprintf.c
Kconfig
Kconfig.debug
Kconfig.kasan
Kconfig.kgdb
Kconfig.ubsan
kfifo.c Partially revert "kfifo: fix kfifo_alloc() and kfifo_init()" 2020-01-27 14:51:08 +01:00
klist.c
kobject_uevent.c kobject_uevent: remove warning in init_uevent_argv() 2021-05-22 10:59:47 +02:00
kobject.c
kstrtox.c lib: vsprintf: Fix handling of number field widths in vsscanf 2021-07-20 16:15:45 +02:00
kstrtox.h lib: vsprintf: Fix handling of number field widths in vsscanf 2021-07-20 16:15:45 +02:00
lcm.c
libcrc32c.c
list_debug.c
list_sort.c
llist.c
locking-selftest-hardirq.h
locking-selftest-mutex.h
locking-selftest-rlock-hardirq.h
locking-selftest-rlock-softirq.h
locking-selftest-rlock.h
locking-selftest-rsem.h
locking-selftest-rtmutex.h
locking-selftest-softirq.h
locking-selftest-spin-hardirq.h
locking-selftest-spin-softirq.h
locking-selftest-spin.h
locking-selftest-wlock-hardirq.h
locking-selftest-wlock-softirq.h
locking-selftest-wlock.h
locking-selftest-wsem.h
locking-selftest.c
lockref.c
logic_pio.c PCI: Fix pci_register_io_range() memory leak 2021-03-17 16:43:46 +01:00
lru_cache.c
lshrdi3.c
Makefile ubsan: build ubsan.c more conservatively 2020-05-27 17:37:27 +02:00
memory-notifier-error-inject.c
memweight.c
muldi3.c
net_utils.c
netdev-notifier-error-inject.c
nlattr.c net: fix nla_strcmp to handle more then one trailing null character 2021-05-22 10:59:44 +02:00
nmi_backtrace.c
nodemask.c
notifier-error-inject.c
notifier-error-inject.h
of-reconfig-notifier-error-inject.c
oid_registry.c
once.c
parman.c
parser.c
pci_iomap.c
percpu_counter.c
percpu_test.c
percpu-refcount.c
plist.c
pm-notifier-error-inject.c
prime_numbers.c
radix-tree.c idr: Fix idr_alloc_u32 on 32-bit systems 2019-12-05 09:19:40 +01:00
random32.c random32: make prandom_u32() output unpredictable 2020-11-18 19:18:52 +01:00
ratelimit.c
rational.c
rbtree_test.c
rbtree.c
reciprocal_div.c
refcount.c
rhashtable.c
sbitmap.c
scatterlist.c sgl_alloc_order: fix memory leak 2020-11-05 11:08:45 +01:00
seq_buf.c seq_buf: Fix overflow in seq_buf_putmem_hex() 2021-07-20 16:16:05 +02:00
sg_pool.c
sg_split.c
sha1.c
sha256.c
show_mem.c
siphash.c
smp_processor_id.c
sort.c
stackdepot.c lib: stackdepot: turn depot_lock spinlock to raw_spinlock 2021-05-22 10:59:49 +02:00
stmp_device.c
string_helpers.c
string.c lib/string: Add strscpy_pad() function 2021-02-13 13:51:15 +01:00
strncpy_from_user.c lib: Reduce user_access_begin() boundaries in strncpy_from_user() and strnlen_user() 2020-06-22 09:04:59 +02:00
strnlen_user.c lib: Reduce user_access_begin() boundaries in strncpy_from_user() and strnlen_user() 2020-06-22 09:04:59 +02:00
syscall.c
test_bitfield.c
test_bitmap.c
test_bpf.c
test_debug_virtual.c
test_firmware.c
test_hash.c
test_hexdump.c
test_ida.c
test_kasan.c lib/test_kasan.c: fix memory leak in kmalloc_oob_krealloc_more() 2020-02-11 04:33:57 -08:00
test_kmod.c test_kmod: avoid potential double free in trigger_config_run_type() 2020-08-21 11:05:38 +02:00
test_list_sort.c
test_module.c
test_overflow.c
test_parman.c
test_printf.c
test_rhashtable.c
test_siphash.c
test_sort.c
test_static_key_base.c
test_static_keys.c
test_string.c
test_sysctl.c
test_ubsan.c
test_user_copy.c
test_uuid.c
test-kstrtox.c
test-string_helpers.c
textsearch.c
timerqueue.c
ts_bm.c
ts_fsm.c
ts_kmp.c
ubsan.c
ubsan.h
ucmpdi2.c
ucs2_string.c
usercopy.c
uuid.c
vsprintf.c lib: vsprintf: Fix handling of number field widths in vsscanf 2021-07-20 16:15:45 +02:00
win_minmax.c
xxhash.c