hw/arm/virt: dt: add rng-seed property
PATCH 1/1 hw/arm/virt: dt: add rng-seed property
In 60592cfed2 ("hw/arm/virt: dt: add kaslr-seed property"), the kaslr-seed property was added, but the equally as important rng-seed property was forgotten about, which has identical semantics for a similar purpose. This commit implements it in exactly the same way as kaslr-seed.
--- hw/arm/virt.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 1 + 2 files changed, 41 insertions(+)
hw/arm/virt.c +40 -0
@@ -221,6 +221,16 @@ static bool cpu_type_valid(const char *cpu)return false; } +static void create_rng_seed (MachineState *ms,const char *node) +{ +uint8_t seed[32 ]; + +if (qemu_guest_getrandom (&seed,sizeof (seed),NULL )) { +return ; + } +qemu_fdt_setprop (ms->fdt, node,"rng-seed" , seed,sizeof (seed)); +} +static void create_kaslr_seed (MachineState *ms,const char *node) {uint64_t seed;
@@ -251,6 +261,9 @@ static void create_fdt(VirtMachineState *vms)/* /chosen must exist for load_dtb to fill in necessary properties later */ qemu_fdt_add_subnode (fdt,"/chosen" ); +if (vms->dtb_rng_seed) { +create_rng_seed (ms,"/chosen" ); + }if (vms->dtb_kaslr_seed) {create_kaslr_seed (ms,"/chosen" ); }
@@ -260,6 +273,9 @@ static void create_fdt(VirtMachineState *vms)if (vms->dtb_kaslr_seed) {create_kaslr_seed (ms,"/secure-chosen" ); } +if (vms->dtb_rng_seed) { +create_rng_seed (ms,"/secure-chosen" ); + } }/* Clock node, for the benefit of the UART. The kernel device tree
@@ -2348,6 +2364,20 @@ static void virt_set_its(Object *obj, bool value, Error **errp) vms->its = value; } +static bool virt_get_dtb_rng_seed (Object *obj,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (obj); + +return vms->dtb_rng_seed; +} + +static void virt_set_dtb_rng_seed (Object *obj,bool value,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (obj); + + vms->dtb_rng_seed = value; +} +static bool virt_get_dtb_kaslr_seed (Object *obj,Error **errp) {VirtMachineState *vms =VIRT_MACHINE (obj);
@@ -2988,6 +3018,13 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)"Set on/off to enable/disable " "ITS instantiation"); +object_class_property_add_bool (oc,"dtb-rng-seed" , + virt_get_dtb_rng_seed, + virt_set_dtb_rng_seed); +object_class_property_set_description (oc,"dtb-rng-seed" , +"Set off to disable passing of rng-seed " +"dtb node to guest" ); +object_class_property_add_bool (oc,"dtb-kaslr-seed" , virt_get_dtb_kaslr_seed, virt_set_dtb_kaslr_seed);
@@ -3061,6 +3098,9 @@ static void virt_instance_init(Object *obj)/* MTE is disabled by default. */ vms->mte = false; +/* Supply a rng-seed by default */ + vms->dtb_rng_seed = true; +/* Supply a kaslr-seed by default */ vms->dtb_kaslr_seed = true;
include/hw/arm/virt.h +1 -0
@@ -152,6 +152,7 @@ struct VirtMachineState {bool virt;bool ras;bool mte; +bool dtb_rng_seed;bool dtb_kaslr_seed;OnOffAuto acpi;VirtGICType gic_version;
Signature · 1 line
2.35.1
Quoted 6 lines · Jason A. Donenfeld
In
60592cfed2("hw/arm/virt: dt: add kaslr-seed property"), the kaslr-seed property was added, but the equally as important rng-seed property was forgotten about, which has identical semantics for a similar purpose. This commit implements it in exactly the same way as kaslr-seed.
Not an objection, since if this is what the dtb spec says we need to provide then I guess we need to provide it, but:
Why do we need to give the kernel two separate random seeds? Isn't one sufficient for the kernel to seed its RNG and generate whatever randomness it needs for whatever purposes it wants it?
thanks
-- PMM
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Jason A. Donenfeld
In
60592cfed2("hw/arm/virt: dt: add kaslr-seed property"), the kaslr-seed property was added, but the equally as important rng-seed property was forgotten about, which has identical semantics for a similar purpose. This commit implements it in exactly the same way as kaslr-seed.
Quoted 6 lines
Not an objection, since if this is what the dtb spec says we need to provide then I guess we need to provide it, but:
Why do we need to give the kernel two separate random seeds? Isn't one sufficient for the kernel to seed its RNG and generate whatever randomness it needs for whatever purposes it wants it?
Seems a bit silly to me too. rng-seed alone ought to be sufficient. After the kernel calls add_bootloader_randomness() on it, get_random_long() can be used for kaslr'ing and everything else too. So I'm not sure what's up, but here we are. Maybe down the line I'll look into the details and formulate a plan to remove kaslr-seed if my supposition is correct.
Jason
Quoted 16 lines · Jason A. Donenfeld
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Jason A. Donenfeld
In
60592cfed2("hw/arm/virt: dt: add kaslr-seed property"), the kaslr-seed property was added, but the equally as important rng-seed property was forgotten about, which has identical semantics for a similar purpose. This commit implements it in exactly the same way as kaslr-seed.Quoted 6 lines
Not an objection, since if this is what the dtb spec says we need to provide then I guess we need to provide it, but:
Why do we need to give the kernel two separate random seeds? Isn't one sufficient for the kernel to seed its RNG and generate whatever randomness it needs for whatever purposes it wants it?
Quoted 9 lines
Seems a bit silly to me too.
rng-seedalone ought to be sufficient. After the kernel callsadd_bootloader_randomness()on it,get_random_long()can be used for kaslr'ing and everything else too. So I'm not sure what's up, but here we are. Maybe down the line I'll look into the details and formulate a plan to removekaslr-seedif my supposition is correct.Jason
Was wondering if you planned to queue this up?
Jason
Quoted 25 lines · Jason A. Donenfeld
Quoted 23 lines · Jason A. Donenfeld
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Jason A. Donenfeld
In
60592cfed2("hw/arm/virt: dt: add kaslr-seed property"), the kaslr-seed property was added, but the equally as important rng-seed property was forgotten about, which has identical semantics for a similar purpose. This commit implements it in exactly the same way as kaslr-seed.Quoted 6 lines
Not an objection, since if this is what the dtb spec says we need to provide then I guess we need to provide it, but:
Why do we need to give the kernel two separate random seeds? Isn't one sufficient for the kernel to seed its RNG and generate whatever randomness it needs for whatever purposes it wants it?Seems a bit silly to me too.
rng-seedalone ought to be sufficient. After the kernel callsadd_bootloader_randomness()on it,get_random_long()can be used for kaslr'ing and everything else too. So I'm not sure what's up, but here we are. Maybe down the line I'll look into the details and formulate a plan to removekaslr-seedif my supposition is correct.
Quoted 4 lines
Quoted 2 lines
Jason
Was wondering if you planned to queue this up?
It's on my todo list to review...
-- PMM
Quoted 26 lines · Peter Maydell
Quoted 25 lines · Jason A. Donenfeld
Quoted 23 lines · Jason A. Donenfeld
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Jason A. Donenfeld
In
60592cfed2("hw/arm/virt: dt: add kaslr-seed property"), the kaslr-seed property was added, but the equally as important rng-seed property was forgotten about, which has identical semantics for a similar purpose. This commit implements it in exactly the same way as kaslr-seed.Quoted 6 lines
Not an objection, since if this is what the dtb spec says we need to provide then I guess we need to provide it, but:
Why do we need to give the kernel two separate random seeds? Isn't one sufficient for the kernel to seed its RNG and generate whatever randomness it needs for whatever purposes it wants it?Seems a bit silly to me too.
rng-seedalone ought to be sufficient. After the kernel callsadd_bootloader_randomness()on it,get_random_long()can be used for kaslr'ing and everything else too. So I'm not sure what's up, but here we are. Maybe down the line I'll look into the details and formulate a plan to removekaslr-seedif my supposition is correct.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Jason
Was wondering if you planned to queue this up?
It's on my todo list to review...
Erm isn't this replicating kaslr-seed?
static void create_kaslr_seed(MachineState *ms, const char *node)
{
uint64_t seed; if (qemu_guest_getrandom(&seed, sizeof(seed), NULL)) {
return;
}
qemu_fdt_setprop_u64(ms->fdt, node, "kaslr-seed", seed);}
which BTW we provide a knob (dtb-kaslr-seed) to suppress because it can get in the way of secure instrumentation/checksums done by secure boot.
Quoted 2 lines
-- PMM
Signature · 1 line
Alex Bennée
Quoted 19 lines · Peter Maydell
Quoted 18 lines · Jason A. Donenfeld
Quoted 16 lines · Jason A. Donenfeld
Quoted 14 lines · Peter Maydell
Quoted 6 lines · Jason A. Donenfeld
In
60592cfed2("hw/arm/virt: dt: add kaslr-seed property"), the kaslr-seed property was added, but the equally as important rng-seed property was forgotten about, which has identical semantics for a similar purpose. This commit implements it in exactly the same way as kaslr-seed.Not an objection, since if this is what the dtb spec says we need to provide then I guess we need to provide it, but:
Why do we need to give the kernel two separate random seeds? Isn't one sufficient for the kernel to seed its RNG and generate whatever randomness it needs for whatever purposes it wants it?
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Seems a bit silly to me too.
rng-seedalone ought to be sufficient. After the kernel callsadd_bootloader_randomness()on it,get_random_long()can be used for kaslr'ing and everything else too. So I'm not sure what's up, but here we are. Maybe down the line I'll look into the details and formulate a plan to removekaslr-seedif my supposition is correct.
Sorry now I've had my coffee and read properly I see you are already aware of kaslr-seed. However my point about suppression would still stand because for the secure boot flow you need checksum-able DTBs.
Signature · 1 line
Alex Bennée
Quoted 29 lines · Alex Bennée
Quoted 19 lines · Peter Maydell
Quoted 18 lines · Jason A. Donenfeld
Quoted 16 lines · Jason A. Donenfeld
Quoted 14 lines · Peter Maydell
Quoted 6 lines · Jason A. Donenfeld
In
60592cfed2("hw/arm/virt: dt: add kaslr-seed property"), the kaslr-seed property was added, but the equally as important rng-seed property was forgotten about, which has identical semantics for a similar purpose. This commit implements it in exactly the same way as kaslr-seed.Not an objection, since if this is what the dtb spec says we need to provide then I guess we need to provide it, but:
Why do we need to give the kernel two separate random seeds? Isn't one sufficient for the kernel to seed its RNG and generate whatever randomness it needs for whatever purposes it wants it?Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Seems a bit silly to me too.
rng-seedalone ought to be sufficient. After the kernel callsadd_bootloader_randomness()on it,get_random_long()can be used for kaslr'ing and everything else too. So I'm not sure what's up, but here we are. Maybe down the line I'll look into the details and formulate a plan to removekaslr-seedif my supposition is correct.
Quoted 3 lines
Sorry now I've had my coffee and read properly I see you are already aware of kaslr-seed. However my point about suppression would still stand because for the secure boot flow you need checksum-able DTBs.
Please read the patch. Maybe take a sip of coffee first. There's a knob for this too.
The code is exactly the same for kaslr-seed and rng-seed. Everytime there's some kaslr-seed thing, there is now the same rng-seed thing.
Jason
Quoted 30 lines · Jason A. Donenfeld
Quoted 29 lines · Alex Bennée
Quoted 25 lines · Peter Maydell
Quoted 24 lines · Jason A. Donenfeld
Quoted 22 lines · Jason A. Donenfeld
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Jason A. Donenfeld
In
60592cfed2("hw/arm/virt: dt: add kaslr-seed property"), the kaslr-seed property was added, but the equally as important rng-seed property was forgotten about, which has identical semantics for a similar purpose. This commit implements it in exactly the same way as kaslr-seed.Quoted 6 lines
Not an objection, since if this is what the dtb spec says we need to provide then I guess we need to provide it, but:
Why do we need to give the kernel two separate random seeds? Isn't one sufficient for the kernel to seed its RNG and generate whatever randomness it needs for whatever purposes it wants it?Seems a bit silly to me too.
rng-seedalone ought to be sufficient. After the kernel callsadd_bootloader_randomness()on it,get_random_long()can be used for kaslr'ing and everything else too. So I'm not sure what's up, but here we are. Maybe down the line I'll look into the details and formulate a plan to removekaslr-seedif my supposition is correct.
Quoted 6 lines
Quoted 3 lines
Sorry now I've had my coffee and read properly I see you are already aware of kaslr-seed. However my point about suppression would still stand because for the secure boot flow you need checksum-able DTBs.
Please read the patch. Maybe take a sip of coffee first. There's a knob for this too.
I was obviously not paying enough attention this morning. Sorry about that.
Quoted 2 lines
The code is exactly the same for kaslr-seed and rng-seed. Everytime there's some kaslr-seed thing, there is now the same rng-seed thing.
The duplication is annoying but specs are specs - where is this written by the way?
Given the use case for the dtb-kaslr-seed knob I wonder if we should have a common property and deprecate the kaslr one? As of this patch existing workflows will break until command lines are updated to suppress the second source of randomness.
Maybe it would be better to have a single a new property (dtb-rng-seeds?) which suppresses both dtb entries and make dtb-kaslr-seed an alias and mark it as deprecated.
Signature · 1 line
Alex Bennée
Hi Alex,
Quoted 5 lines · Alex Bennée
Quoted 2 lines
The code is exactly the same for kaslr-seed and rng-seed. Everytime there's some kaslr-seed thing, there is now the same rng-seed thing.
The duplication is annoying but specs are specs - where is this written by the way?
The same place as all the ordinary specs:
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/chosen.yaml
Quoted 8 lines
Given the use case for the dtb-kaslr-seed knob I wonder if we should have a common property and deprecate the kaslr one? As of this patch existing workflows will break until command lines are updated to suppress the second source of randomness.
Maybe it would be better to have a single a new property (dtb-rng-seeds?) which suppresses both dtb entries and make dtb-kaslr-seed an alias and mark it as deprecated.
No, I don't think so. If anything, I'll try to get rid of kaslr-seed upstream at some point if that makes sense. But until that happens -- that is, until I have the conversations with people who added these and care about their semantics -- assume that there's granularity for some good reason. No need to put the cart before the horse.
This is a simple patch doing a simple thing in exactly the way that things are already being done. I really don't want to do much more than that here. If you want to bikeshed it further, send a follow up patch.
Jason
Quoted 16 lines · Jason A. Donenfeld
Quoted 8 lines · Alex Bennée
Given the use case for the dtb-kaslr-seed knob I wonder if we should have a common property and deprecate the kaslr one? As of this patch existing workflows will break until command lines are updated to suppress the second source of randomness.
Maybe it would be better to have a single a new property (dtb-rng-seeds?) which suppresses both dtb entries and make dtb-kaslr-seed an alias and mark it as deprecated.
No, I don't think so. If anything, I'll try to get rid of kaslr-seed upstream at some point if that makes sense. But until that happens -- that is, until I have the conversations with people who added these and care about their semantics -- assume that there's granularity for some good reason. No need to put the cart before the horse.
Quoted 3 lines
This is a simple patch doing a simple thing in exactly the way that things are already being done. I really don't want to do much more than that here. If you want to bikeshed it further, send a follow up patch.
It's adding a command line option, though. Those we have to get right the first time, because for QEMU they're kind of like ABI to our users. We *can* clean them up if we find we've made a mistake, but we have to go through a multi-release deprecation process to do it, so it's much less effort overall to make sure we have the command line syntax right to start with.
If there's a good use case for the two seeds to be separately controllable, that's fine. But I'd rather we find that out for certain before we put a second control knob and make all our users with workflows where they want non-random dtb blobs find out about it and flip it.
thanks
-- PMM
Quoted 28 lines · Peter Maydell
Quoted 16 lines · Jason A. Donenfeld
Quoted 8 lines · Alex Bennée
Given the use case for the dtb-kaslr-seed knob I wonder if we should have a common property and deprecate the kaslr one? As of this patch existing workflows will break until command lines are updated to suppress the second source of randomness.
Maybe it would be better to have a single a new property (dtb-rng-seeds?) which suppresses both dtb entries and make dtb-kaslr-seed an alias and mark it as deprecated.
No, I don't think so. If anything, I'll try to get rid of kaslr-seed upstream at some point if that makes sense. But until that happens -- that is, until I have the conversations with people who added these and care about their semantics -- assume that there's granularity for some good reason. No need to put the cart before the horse.
Quoted 3 lines
This is a simple patch doing a simple thing in exactly the way that things are already being done. I really don't want to do much more than that here. If you want to bikeshed it further, send a follow up patch.
It's adding a command line option, though. Those we have to get right the first time, because for QEMU they're kind of like ABI to our users. We *can* clean them up if we find we've made a mistake, but we have to go through a multi-release deprecation process to do it, so it's much less effort overall to make sure we have the command line syntax right to start with.
Quoted 5 lines
If there's a good use case for the two seeds to be separately controllable, that's fine. But I'd rather we find that out for certain before we put a second control knob and make all our users with workflows where they want non-random dtb blobs find out about it and flip it.
Okay. Do you want me to just make this controllable by dtb-kaslr-seed for now, then, and we can rename that in a follow-up commit? I'll send a patch for that.
Jason
PATCH v2 1/1 hw/arm/virt: dt: add rng-seed property
In 60592cfed2 ("hw/arm/virt: dt: add kaslr-seed property"), the kaslr-seed property was added, but the equally as important rng-seed property was forgotten about, which has identical semantics for a similar purpose. This commit implements it in exactly the same way as kaslr-seed. It then changes the name of the disabling option to reflect that this has more to do with randomness vs determinism, rather than something particular about kaslr.
--- docs/system/arm/virt.rst | 17 ++++++++++------ hw/arm/virt.c | 44 ++++++++++++++++++++++++---------------- include/hw/arm/virt.h | 2 +- 3 files changed, 39 insertions(+), 24 deletions(-)
docs/system/arm/virt.rst +11 -6
@@ -126,13 +126,18 @@ ras Set ``on``/``off`` to enable/disable reporting host memory errors to a guest using ACPI and guest external abort exceptions. The default is off. +dtb-randomness + Set ``on``/``off`` to pass random seeds via the guest DTB + rng-seed and kaslr-seed nodes (in both "/chosen" and + "/secure-chosen") to use for features like the random number + generator and address space randomisation. The default is + ``on``. You will want to disable it if your trusted boot chain + will verify the DTB it is passed, since this option causes the + DTB to be non-deterministic. It would be the responsibility of + the firmware to come up with a seed and pass it on if it wants to. + dtb-kaslr-seed - Set ``on``/``off`` to pass a random seed via the guest dtb - kaslr-seed node (in both "/chosen" and /secure-chosen) to use - for features like address space randomisation. The default is - ``on``. You will want to disable it if your trusted boot chain will - verify the DTB it is passed. It would be the responsibility of the - firmware to come up with a seed and pass it on if it wants to. + A deprecated synonym for dtb-randomness. Linux guest kernel configuration """"""""""""""""""""""""""""""""
hw/arm/virt.c +27 -17
93 lines not on this page · raw message
include/hw/arm/virt.h +1 -1
@@ -152,7 +152,7 @@ struct VirtMachineState {bool virt;bool ras;bool mte; -bool dtb_kaslr_seed; +bool dtb_randomness;OnOffAuto acpi;VirtGICType gic_version;VirtIOMMUType iommu;
Signature · 1 line
2.35.1
Quoted 11 lines · Jason A. Donenfeld
In
60592cfed2("hw/arm/virt: dt: add kaslr-seed property"), the kaslr-seed property was added, but the equally as important rng-seed property was forgotten about, which has identical semantics for a similar purpose. This commit implements it in exactly the same way as kaslr-seed. It then changes the name of the disabling option to reflect that this has more to do with randomness vs determinism, rather than something particular about kaslr.Cc Peter Maydell <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>
Thanks for this respin; I think this is the right way to go.
Quoted 22 lines
--- docs/system/arm/virt.rst | 17 ++++++++++------ hw/arm/virt.c | 44 ++++++++++++++++++++++++---------------- include/hw/arm/virt.h | 2 +- 3 files changed, 39 insertions(+), 24 deletions(-)docs/system/arm/virt.rst +8
-0@@ -126,13 +126,18 @@ ras Set ``on``/``off`` to enable/disable reporting host memory errors to a guest using ACPI and guest external abort exceptions. The default is off. +dtb-randomness + Set ``on``/``off`` to pass random seeds via the guest DTB + rng-seed and kaslr-seed nodes (in both "/chosen" and + "/secure-chosen") to use for features like the random number + generator and address space randomisation. The default is + ``on``. You will want to disable it if your trusted boot chain + will verify the DTB it is passed, since this option causes the + DTB to be non-deterministic. It would be the responsibility of
docs/system/arm/virt.rst ras · line 140
Quoted 10 lines
docs/system/arm/virt.rst +3
-6+ the firmware to come up with a seed and pass it on if it wants to. + dtb-kaslr-seed - Set ``on``/``off`` to pass a random seed via the guest dtb - kaslr-seed node (in both "/chosen" and /secure-chosen) to use - for features like address space randomisation. The default is - ``on``. You will want to disable it if your trusted boot chain will - verify the DTB it is passed. It would be the responsibility of the - firmware to come up with a seed and pass it on if it wants to. + A deprecated synonym for dtb-randomness.
We should also add a section to docs/about/deprecated.rst noting that the old name is deprecated in favour of the new one. I'll fold that in when I add the patch to target-arm.next, to save you doing a respin:
docs/about/deprecated.rst +0 -0
@@ -225,6 +225,14 @@ Use the more generic event
``DEVICE_UNPLUG_GUEST_ERROR`` instead.
System emulator machines
------------------------
+Arm ``virt`` machine ``dtb-kaslr-seed`` property +''''''''''''''''''''''''''''''''''''''''''''''''
+
+The ``dtb-kaslr-seed`` property on the ``virt`` board has been +deprecated; use the new name ``dtb-randomness`` instead. The new name +better reflects the way this property affects all random data within +the device tree blob, not just the ``kaslr-seed`` node.
+
Quoted 6 lines
docs/system/arm/virt.rst +6
-0+ object_class_property_add_bool(oc, "dtb-randomness", + virt_get_dtb_randomness, + virt_set_dtb_randomness); + object_class_property_set_description(oc, "dtb-randomness", + "Set off to disable passing random or " + "non-deterministic dtb nodes to guest");
docs/system/arm/virt.rst ras
Quoted 10 lines
docs/system/arm/virt.rst +4
-4+ object_class_property_add_bool(oc, "dtb-kaslr-seed", - virt_get_dtb_kaslr_seed, - virt_set_dtb_kaslr_seed); + virt_get_dtb_randomness, + virt_set_dtb_randomness); object_class_property_set_description(oc, "dtb-kaslr-seed", - "Set off to disable passing of kaslr-seed " - "dtb node to guest"); + "Deprecated synonym of dtb-randomness");
I was going to suggest object_property_add_alias() but that works at the object level, not the class level, so never mind. This will work, and eventually we'll delete the code when it hits the deprecation-to-removal horizon. So
and applied to target-arm.next.
thanks
-- PMM
Hi Peter,
Quoted 4 lines · Peter Maydell
We should also add a section to
docs/about/deprecated.rstnoting that the old name is deprecated in favour of the new one. I'll fold that in when I add the patch to target-arm.next, to save you doing a respin:
Thanks for doing that. Your text looks good to me.
Jason