Message ID | 20190506173353.32206-14-richard.henderson@linaro.org |
---|---|
State | New |
Headers | show |
Series | Add qemu_getrandom and ARMv8.5-RNG etc | expand |
On 06/05/2019 19:33, Richard Henderson wrote: > Cc: Laurent Vivier <laurent@vivier.eu> > Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > --- > linux-user/main.c | 15 +++++++++++++-- > 1 file changed, 13 insertions(+), 2 deletions(-) > > diff --git a/linux-user/main.c b/linux-user/main.c > index 7dfb202e5d..e05aebe4e1 100644 > --- a/linux-user/main.c > +++ b/linux-user/main.c > @@ -39,6 +39,7 @@ > #include "trace/control.h" > #include "target_elf.h" > #include "cpu_loop-common.h" > +#include "crypto/init.h" > > char *exec_path; > > @@ -688,8 +689,18 @@ int main(int argc, char **argv, char **envp) > if (seed_optarg == NULL) { > seed_optarg = getenv("QEMU_RAND_SEED"); > } > - if (seed_optarg != NULL) { > - qemu_guest_random_seed_main(seed_optarg, &error_fatal); > + { > + Error *err = NULL; > + if (seed_optarg != NULL) { > + qemu_guest_random_seed_main(seed_optarg, &err); > + } else { > + /* ??? Assumes qcrypto is only used by qemu_guest_getrandom. */ perhaps you can add a qemu_guest_random_init() function close to this assumption to call qcrypto_init()? So we will not forget to change this if we use something else in the future. > + qcrypto_init(&err); > + } > + if (err) { > + error_reportf_err(err, "cannot initialize crypto: "); > + exit(1); > + } > } > > target_environ = envlist_to_environ(envlist, NULL); > Thanks, Laurent
On 5/7/19 7:13 AM, Laurent Vivier wrote: >> - if (seed_optarg != NULL) { >> - qemu_guest_random_seed_main(seed_optarg, &error_fatal); >> + { >> + Error *err = NULL; >> + if (seed_optarg != NULL) { >> + qemu_guest_random_seed_main(seed_optarg, &err); >> + } else { >> + /* ??? Assumes qcrypto is only used by qemu_guest_getrandom. */ > > perhaps you can add a qemu_guest_random_init() function close to this > assumption to call qcrypto_init()? So we will not forget to change this if we > use something else in the future. I'm not sure what you're suggesting. Why would putting qcrypto_init within qemu_guest_random_init make it more likely that, if something else within linux-user required qcrypto routines, we would remember to remove qemu_guest_random_init and call qcrypto_init exactly once? r~
On 08/05/2019 06:11, Richard Henderson wrote: > On 5/7/19 7:13 AM, Laurent Vivier wrote: >>> - if (seed_optarg != NULL) { >>> - qemu_guest_random_seed_main(seed_optarg, &error_fatal); >>> + { >>> + Error *err = NULL; >>> + if (seed_optarg != NULL) { >>> + qemu_guest_random_seed_main(seed_optarg, &err); >>> + } else { >>> + /* ??? Assumes qcrypto is only used by qemu_guest_getrandom. */ >> >> perhaps you can add a qemu_guest_random_init() function close to this >> assumption to call qcrypto_init()? So we will not forget to change this if we >> use something else in the future. > > I'm not sure what you're suggesting. > > Why would putting qcrypto_init within qemu_guest_random_init make it more > likely that, if something else within linux-user required qcrypto routines, we > would remember to remove qemu_guest_random_init and call qcrypto_init exactly once? Why would we need qcrypto routines rather than qemu_guest_getrandom()? The idea was if qemu_guest_getrandom() stops to use qcrypto we don't forget to remove this call. But it's only cosmetic, so: Reviewed-by: Laurent Vivier <lvivier@redhat.com>
diff --git a/linux-user/main.c b/linux-user/main.c index 7dfb202e5d..e05aebe4e1 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -39,6 +39,7 @@ #include "trace/control.h" #include "target_elf.h" #include "cpu_loop-common.h" +#include "crypto/init.h" char *exec_path; @@ -688,8 +689,18 @@ int main(int argc, char **argv, char **envp) if (seed_optarg == NULL) { seed_optarg = getenv("QEMU_RAND_SEED"); } - if (seed_optarg != NULL) { - qemu_guest_random_seed_main(seed_optarg, &error_fatal); + { + Error *err = NULL; + if (seed_optarg != NULL) { + qemu_guest_random_seed_main(seed_optarg, &err); + } else { + /* ??? Assumes qcrypto is only used by qemu_guest_getrandom. */ + qcrypto_init(&err); + } + if (err) { + error_reportf_err(err, "cannot initialize crypto: "); + exit(1); + } } target_environ = envlist_to_environ(envlist, NULL);