1
0
Fork 0
alistair23-linux/lib/zlib_inflate
Jann Horn b7ce2e4538 lib/zlib: remove outdated and incorrect pre-increment optimization
[ Upstream commit acaab7335b ]

The zlib inflate code has an old micro-optimization based on the
assumption that for pre-increment memory accesses, the compiler will
generate code that fits better into the processor's pipeline than what
would be generated for post-increment memory accesses.

This optimization was already removed in upstream zlib in 2016:
https://github.com/madler/zlib/commit/9aaec95e8211

This optimization causes UB according to C99, which says in section 6.5.6
"Additive operators": "If both the pointer operand and the result point to
elements of the same array object, or one past the last element of the
array object, the evaluation shall not produce an overflow; otherwise, the
behavior is undefined".

This UB is not only a theoretical concern, but can also cause trouble for
future work on compiler-based sanitizers.

According to the zlib commit, this optimization also is not optimal
anymore with modern compilers.

Replace uses of OFF, PUP and UP_UNALIGNED with their definitions in the
POSTINC case, and remove the macro definitions, just like in the upstream
patch.

Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Link: http://lkml.kernel.org/r/20200507123112.252723-1-jannh@google.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-06-24 17:50:39 +02:00
..
Makefile treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
inffast.c lib/zlib: remove outdated and incorrect pre-increment optimization 2020-06-24 17:50:39 +02:00
inffast.h
inffixed.h
inflate.c lib/zlib_inflate/inflate.c: remove fall through warnings 2018-10-31 08:54:13 -07:00
inflate.h bzip2/lzma: library support for gzip, bzip2 and lzma decompression 2009-01-04 15:53:34 -08:00
inflate_syms.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
inftrees.c lib/zlib_inflate/inftrees.c: fix potential buffer overflow 2017-05-08 17:15:12 -07:00
inftrees.h bzip2/lzma: library support for gzip, bzip2 and lzma decompression 2009-01-04 15:53:34 -08:00
infutil.c [ZLIB]: Fix external builds of zlib_inflate code. 2007-10-11 22:17:20 -07:00
infutil.h