From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Simon Horman <horms@verge.net.au>, kexec@lists.infradead.org
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Subject: [PATCH kexec-tools] i386: pass rng seed via setup_data
Date: Mon, 11 Jul 2022 17:41:10 +0200 [thread overview]
Message-ID: <20220711154110.156015-1-Jason@zx2c4.com> (raw)
Linux ≥5.20 expects a RNG seed via setup_data as of the upstream commit
in the link below. That commit adjusts kexec_file_load to pass
SETUP_RNG_SEED. kexec-tools should follow suite, so add more or less the
same code here.
Link: https://git.kernel.org/tip/tip/c/68b8e9713c8
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
kexec/arch/i386/x86-linux-setup.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-setup.c
index ab54a4a..14263b0 100644
--- a/kexec/arch/i386/x86-linux-setup.c
+++ b/kexec/arch/i386/x86-linux-setup.c
@@ -24,6 +24,7 @@
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/random.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
@@ -544,6 +545,7 @@ struct setup_data {
#define SETUP_DTB 2
#define SETUP_PCI 3
#define SETUP_EFI 4
+#define SETUP_RNG_SEED 9
uint32_t len;
uint8_t data[0];
} __attribute__((packed));
@@ -824,6 +826,26 @@ static void setup_e820(struct kexec_info *info, struct x86_linux_param_header *r
}
}
+static void setup_rng_seed(struct kexec_info *info,
+ struct x86_linux_param_header *real_mode)
+{
+ struct {
+ struct setup_data header;
+ uint8_t rng_seed[32];
+ } *sd;
+
+ sd = xmalloc(sizeof(*sd));
+ sd->header.next = 0;
+ sd->header.len = sizeof(sd->rng_seed);
+ sd->header.type = SETUP_RNG_SEED;
+
+ if (getrandom(sd->rng_seed, sizeof(sd->rng_seed), GRND_NONBLOCK) !=
+ sizeof(sd->rng_seed))
+ return; /* Not initialized, so don't pass a seed. */
+
+ add_setup_data(info, real_mode, &sd->header);
+}
+
static int
get_efi_mem_desc_version(struct x86_linux_param_header *real_mode)
{
@@ -923,6 +945,9 @@ void setup_linux_system_parameters(struct kexec_info *info,
setup_e820(info, real_mode);
+ /* pass RNG seed */
+ setup_rng_seed(info, real_mode);
+
/* fill the EDD information */
setup_edd_info(real_mode);
--
2.35.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
next reply other threads:[~2022-07-11 15:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-11 15:41 Jason A. Donenfeld [this message]
2022-07-15 9:26 ` [PATCH kexec-tools] i386: pass rng seed via setup_data Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220711154110.156015-1-Jason@zx2c4.com \
--to=jason@zx2c4.com \
--cc=horms@verge.net.au \
--cc=kexec@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox