freenode
Kernel & Low-Level

Linux to drop its aging LZ4 fork and vendor upstream instead

A nine-year gap left an unchecked decompressor in the kernel; Samsung's series imports LZ4 1.11.1 and retunes zram and erofs around it.

Michal Wilczynski of Samsung has posted a series that replaces the Linux kernel's hand-maintained LZ4 with unmodified upstream sources, ending a fork whose decompressor was last synced in 2018 and whose compressor was last synced in 2017. Upstream has made more than 600 commits to the library since then. The kernel has been absorbing that work one cherry-pick at a time, and real bugs stayed behind.

The clearest of them is in the forked fast decompressor, which does not bounds-check its input. Corrupted data can be read past the end of the buffer and before the start of the output. The series drops that entry point, moves the pre-boot image decompressor off it, and switches the compressor, the high-compression (lz4hc) path, and the decompressor to thin wrappers over LZ4 1.11.1, released in November 2026. A later re-sync is meant to be a directory copy rather than another manual merge. Wilczynski also adds the library's first MAINTAINERS entry and offers to own the version bumps.

Callers have to change with the library. zram and f2fs currently size compression state with the C sizeof operator; upstream declares those stream types as incomplete, so both move to the library's own size constants. On zram's 4K pages, lz4hc levels above 9 now select an optimal parser that is several times slower for well under 1% smaller output. The series compresses those levels as level 9 and logs it. f2fs, which compresses larger clusters, keeps the higher levels.

Erofs is the other casualty of catching up. Its in-place decode assumes a small slack margin after the output. Upstream's fast loop, on by default on x86, arm64, and ppc64, copies matches in 64-byte steps and can overwrite input it has not yet read. Of more than 170,000 otherwise valid streams laid out at the old margin, thousands fail. Wilczynski widens the margin to the figure upstream has already adopted on its development branch, taking a 4K cluster from 48 bytes of slack to 81. Images produced by the erofs formatter did not hit the bug, but the on-disk format does not forbid it.

Compressed output will differ from the fork, though each side can still decode the other. On 4K blocks the new compressor is slightly faster and slightly smaller on kernel source and binaries. Lz4hc levels 3 to 9 can be slower on page-sized input, including zram's default of level 9. Two further lz4hc changes Wilczynski has filed upstream, not yet merged, are included at the end of the series so they can be dropped: with them, zram's lz4hc is faster than today at levels 6 and 9, while level 3 stays a fraction slower.

S. Biplab Raut of AMD adds the library's first in-kernel tests, covering truncated and corrupted blocks, in-place decode, and a 32-bit length wrap the old decoder accepted. The series is aimed at Andrew Morton's tree and depends on this cycle's zram rework already in linux-next.