+++ /dev/null
-From 5a45a4c5c3f5e36a03770deb102ca6ba256ff3d7 Mon Sep 17 00:00:00 2001
-From: Kees Cook <keescook@chromium.org>
-Date: Fri, 13 Jan 2017 14:09:35 -0800
-Subject: gcc-plugins: consolidate on PASS_INFO macro
-
-From: Kees Cook <keescook@chromium.org>
-
-commit 5a45a4c5c3f5e36a03770deb102ca6ba256ff3d7 upstream.
-
-Now that PASS_INFO() exists, use it in the other existing gcc plugins,
-instead of always open coding the same thing.
-
-Based on updates to the grsecurity/PaX gcc plugins.
-
-Signed-off-by: Kees Cook <keescook@chromium.org>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- scripts/gcc-plugins/cyc_complexity_plugin.c | 6 +-----
- scripts/gcc-plugins/latent_entropy_plugin.c | 8 ++------
- scripts/gcc-plugins/sancov_plugin.c | 8 ++------
- 3 files changed, 5 insertions(+), 17 deletions(-)
-
---- a/scripts/gcc-plugins/cyc_complexity_plugin.c
-+++ b/scripts/gcc-plugins/cyc_complexity_plugin.c
-@@ -52,12 +52,8 @@ static unsigned int cyc_complexity_execu
- __visible int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
- {
- const char * const plugin_name = plugin_info->base_name;
-- struct register_pass_info cyc_complexity_pass_info;
-
-- cyc_complexity_pass_info.pass = make_cyc_complexity_pass();
-- cyc_complexity_pass_info.reference_pass_name = "ssa";
-- cyc_complexity_pass_info.ref_pass_instance_number = 1;
-- cyc_complexity_pass_info.pos_op = PASS_POS_INSERT_AFTER;
-+ PASS_INFO(cyc_complexity, "ssa", 1, PASS_POS_INSERT_AFTER);
-
- if (!plugin_default_version_check(version, &gcc_version)) {
- error(G_("incompatible gcc/plugin versions"));
---- a/scripts/gcc-plugins/latent_entropy_plugin.c
-+++ b/scripts/gcc-plugins/latent_entropy_plugin.c
-@@ -592,12 +592,6 @@ __visible int plugin_init(struct plugin_
- const struct plugin_argument * const argv = plugin_info->argv;
- int i;
-
-- struct register_pass_info latent_entropy_pass_info;
--
-- latent_entropy_pass_info.pass = make_latent_entropy_pass();
-- latent_entropy_pass_info.reference_pass_name = "optimized";
-- latent_entropy_pass_info.ref_pass_instance_number = 1;
-- latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
- static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
- {
- .base = &latent_entropy_decl,
-@@ -609,6 +603,8 @@ __visible int plugin_init(struct plugin_
- LAST_GGC_ROOT_TAB
- };
-
-+ PASS_INFO(latent_entropy, "optimized", 1, PASS_POS_INSERT_BEFORE);
-+
- if (!plugin_default_version_check(version, &gcc_version)) {
- error(G_("incompatible gcc/plugin versions"));
- return 1;
---- a/scripts/gcc-plugins/sancov_plugin.c
-+++ b/scripts/gcc-plugins/sancov_plugin.c
-@@ -89,7 +89,6 @@ static void sancov_start_unit(void __unu
- __visible int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
- {
- int i;
-- struct register_pass_info sancov_plugin_pass_info;
- const char * const plugin_name = plugin_info->base_name;
- const int argc = plugin_info->argc;
- const struct plugin_argument * const argv = plugin_info->argv;
-@@ -107,14 +106,11 @@ __visible int plugin_init(struct plugin_
- };
-
- /* BBs can be split afterwards?? */
-- sancov_plugin_pass_info.pass = make_sancov_pass();
- #if BUILDING_GCC_VERSION >= 4009
-- sancov_plugin_pass_info.reference_pass_name = "asan";
-+ PASS_INFO(sancov, "asan", 0, PASS_POS_INSERT_BEFORE);
- #else
-- sancov_plugin_pass_info.reference_pass_name = "nrv";
-+ PASS_INFO(sancov, "nrv", 1, PASS_POS_INSERT_BEFORE);
- #endif
-- sancov_plugin_pass_info.ref_pass_instance_number = 0;
-- sancov_plugin_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
-
- if (!plugin_default_version_check(version, &gcc_version)) {
- error(G_("incompatible gcc/plugin versions"));
+++ /dev/null
-From c40160f2998c897231f8454bf797558d30a20375 Mon Sep 17 00:00:00 2001
-From: "Jason A. Donenfeld" <Jason@zx2c4.com>
-Date: Wed, 6 Apr 2022 00:28:15 +0200
-Subject: gcc-plugins: latent_entropy: use /dev/urandom
-
-From: Jason A. Donenfeld <Jason@zx2c4.com>
-
-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: 38addce8b600 ("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>
----
- scripts/gcc-plugins/latent_entropy_plugin.c | 44 +++++++++++++++++-----------
- 1 file changed, 27 insertions(+), 17 deletions(-)
-
---- a/scripts/gcc-plugins/latent_entropy_plugin.c
-+++ b/scripts/gcc-plugins/latent_entropy_plugin.c
-@@ -86,25 +86,31 @@ static struct plugin_info latent_entropy
- .help = "disable\tturn off latent entropy instrumentation\n",
- };
-
--static unsigned HOST_WIDE_INT seed;
--/*
-- * get_random_seed() (this is a GCC function) generates the seed.
-- * This is a simple random generator without any cryptographic security because
-- * the entropy doesn't come from here.
-- */
-+static unsigned HOST_WIDE_INT deterministic_seed;
-+static unsigned HOST_WIDE_INT rnd_buf[32];
-+static size_t rnd_idx = ARRAY_SIZE(rnd_buf);
-+static int urandom_fd = -1;
-+
- static unsigned HOST_WIDE_INT get_random_const(void)
- {
-- unsigned int i;
-- unsigned HOST_WIDE_INT ret = 0;
--
-- for (i = 0; i < 8 * sizeof(ret); i++) {
-- ret = (ret << 1) | (seed & 1);
-- seed >>= 1;
-- if (ret & 1)
-- seed ^= 0xD800000000000000ULL;
-+ if (deterministic_seed) {
-+ unsigned HOST_WIDE_INT w = deterministic_seed;
-+ w ^= w << 13;
-+ w ^= w >> 7;
-+ w ^= w << 17;
-+ deterministic_seed = w;
-+ return deterministic_seed;
- }
-
-- return ret;
-+ if (urandom_fd < 0) {
-+ urandom_fd = open("/dev/urandom", O_RDONLY);
-+ gcc_assert(urandom_fd >= 0);
-+ }
-+ if (rnd_idx >= ARRAY_SIZE(rnd_buf)) {
-+ gcc_assert(read(urandom_fd, rnd_buf, sizeof(rnd_buf)) == sizeof(rnd_buf));
-+ rnd_idx = 0;
-+ }
-+ return rnd_buf[rnd_idx++];
- }
-
- static tree tree_get_random_const(tree type)
-@@ -556,8 +562,6 @@ static void latent_entropy_start_unit(vo
- tree type, id;
- int quals;
-
-- seed = get_random_seed(false);
--
- if (in_lto_p)
- return;
-
-@@ -592,6 +596,12 @@ __visible int plugin_init(struct plugin_
- const struct plugin_argument * const argv = plugin_info->argv;
- int i;
-
-+ /*
-+ * Call get_random_seed() with noinit=true, so that this returns
-+ * 0 in the case where no seed has been passed via -frandom-seed.
-+ */
-+ deterministic_seed = get_random_seed(true);
-+
- static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
- {
- .base = &latent_entropy_decl,