android_kernel_xiaomi_sm7250/scripts
Jason A. Donenfeld 8b1010a6ae gcc-plugins: latent_entropy: use /dev/urandom
commit c40160f2998c897231f8454bf797558d30a20375 upstream.

While the latent entropy plugin mostly doesn't derive entropy from
get_random_const() for measuring the call graph, when __latent_entropy is
applied to a constant, then it's initialized statically to output from
get_random_const(). In that case, this data is derived from a 64-bit
seed, which means a buffer of 512 bits doesn't really have that amount
of compile-time entropy.

This patch fixes that shortcoming by just buffering chunks of
/dev/urandom output and doling it out as requested.

At the same time, it's important that we don't break the use of
-frandom-seed, for people who want the runtime benefits of the latent
entropy plugin, while still having compile-time determinism. In that
case, we detect whether gcc's set_random_seed() has been called by
making a call to get_random_seed(noinit=true) in the plugin init
function, which is called after set_random_seed() is called but before
anything that calls get_random_seed(noinit=false), and seeing if it's
zero or not. If it's not zero, we're in deterministic mode, and so we
just generate numbers with a basic xorshift prng.

Note that we don't detect if -frandom-seed is being used using the
documented local_tick variable, because it's assigned via:
   local_tick = (unsigned) tv.tv_sec * 1000 + tv.tv_usec / 1000;
which may well overflow and become -1 on its own, and so isn't
reliable: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105171

[kees: The 256 byte rnd_buf size was chosen based on average (250),
 median (64), and std deviation (575) bytes of used entropy for a
 defconfig x86_64 build]

Fixes: 38addce8b6 ("gcc-plugins: Add latent_entropy plugin")
Cc: stable@vger.kernel.org
Cc: PaX Team <pageexec@freemail.hu>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20220405222815.21155-1-Jason@zx2c4.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-04-20 09:12:50 +02:00
..
basic
coccinelle
dtc scripts/dtc: dtx_diff: remove broken example from help text 2022-01-27 09:04:33 +01:00
gcc-plugins gcc-plugins: latent_entropy: use /dev/urandom 2022-04-20 09:12:50 +02:00
gdb scripts/gdb: fix lx-symbols 'gdb.error' while loading modules 2020-07-29 10:16:51 +02:00
genksyms
kconfig kconfig: let 'shell' return enough output for deep path names 2022-02-23 11:58:42 +01:00
ksymoops
mod vmlinux.lds.h: Create section for protection against instrumentation 2021-03-24 11:07:31 +01:00
package
selinux
tracing scripts/tracing: fix the bug that can't parse raw_trace_func 2021-08-12 13:19:42 +02:00
.gitignore
adjust_autoksyms.sh
asn1_compiler.c
bin2c.c
bloat-o-meter scripts: switch explicitly to Python 3 2021-05-22 10:59:50 +02:00
bootgraph.pl
bpf_helpers_doc.py
cc-can-link.sh
check_00index.sh
check_extable.sh
checkincludes.pl
checkkconfigsymbols.py
checkpatch.pl checkpatch: fix unescaped left brace 2020-12-30 11:26:04 +01:00
checkstack.pl
checksyscalls.sh
checkversion.pl
clang-version.sh
cleanfile
cleanpatch
coccicheck
config tweewide: Fix most Shebang lines 2021-05-22 10:59:50 +02:00
conmakehash.c
const_structs.checkpatch
decode_stacktrace.sh scripts/decode_stacktrace: strip basepath from all paths 2020-07-29 10:16:51 +02:00
decodecode scripts/decodecode: fix trapping instruction formatting 2020-05-14 07:57:23 +02:00
depmod.sh depmod: handle the case of /sbin/depmod without /sbin in PATH 2021-01-12 20:10:16 +01:00
diffconfig scripts: switch explicitly to Python 3 2021-05-22 10:59:50 +02:00
documentation-file-ref-check
export_report.pl
extract_xc3028.pl
extract-cert.c
extract-ikconfig
extract-module-sig.pl
extract-sys-certs.pl
extract-vmlinux
faddr2line
file-size.sh
find-unused-docs.sh scripts/find-unused-docs: Fix massive false positives 2020-02-11 04:34:01 -08:00
gcc-goto.sh
gcc-ld
gcc-plugin.sh
gcc-version.sh
gcc-x86_32-has-stack-protector.sh
gcc-x86_64-has-stack-protector.sh
get_dvb_firmware
get_maintainer.pl
gfp-translate
headerdep.pl
headers_check.pl
headers_install.sh
headers.sh
insert-sys-cert.c
kallsyms.c scripts/kallsyms: fix definitely-lost memory leak 2020-01-04 19:13:09 +01:00
Kbuild.include kbuild: improve cc-option to clean up all temporary files 2020-06-30 23:17:15 -04:00
Kconfig.include kbuild: use -S instead of -E for precise cc-option test in Kconfig 2020-02-24 08:34:50 +01:00
kernel-doc
ld-version.sh
leaking_addresses.pl leaking_addresses: Always print a trailing newline 2021-11-26 11:36:06 +01:00
Lindent
link-vmlinux.sh
Makefile scripts: set proper OpenSSL include dir also for sign-file 2021-03-04 09:39:29 +01:00
Makefile.asm-generic
Makefile.build
Makefile.clean
Makefile.dtbinst
Makefile.extrawarn Makefile.extrawarn: Move -Wunaligned-access to W=1 2022-02-23 11:58:37 +01:00
Makefile.gcc-plugins gcc-plugins/structleak: add makefile var for disabling structleak 2021-10-27 09:53:14 +02:00
Makefile.headersinst
Makefile.host
Makefile.kasan
Makefile.kcov
Makefile.lib kbuild: disable dtc simple_bus_reg warnings by default 2019-12-13 08:52:18 +01:00
Makefile.modbuiltin
Makefile.modinst
Makefile.modpost
Makefile.modsign
Makefile.ubsan
makelst
markup_oops.pl
mkcompile_h kbuild: mkcompile_h: consider timestamp if KBUILD_BUILD_TIMESTAMP is set 2021-07-28 11:13:43 +02:00
mkmakefile
mksysmap mksysmap: Fix the mismatch of '.L' symbols in System.map 2020-06-25 15:32:51 +02:00
mkuboot.sh
module-common.lds
namespace.pl
objdiff
parse-maintainers.pl parse-maintainers: Mark as executable 2020-03-25 08:06:08 +01:00
patch-kernel
pnmtologo.c
profile2linkerlist.pl
prune-kernel
recordmcount.c scripts/recordmcount.{c,pl}: support -ffunction-sections .text.* section names 2021-03-17 16:43:43 +01:00
recordmcount.h
recordmcount.pl recordmcount.pl: fix typo in s390 mcount regex 2022-01-05 12:34:58 +01:00
setlocalversion scripts/setlocalversion: make git describe output more reliable 2020-11-05 11:08:31 +01:00
show_delta
sign-file.c
sortextable.c
sortextable.h
spdxcheck.py
spelling.txt
sphinx-pre-install
split-man.pl tweewide: Fix most Shebang lines 2021-05-22 10:59:50 +02:00
stackdelta
stackusage
subarch.include
tags.sh
unifdef.c
ver_linux
xen-hypercalls.sh
xz_wrap.sh