Skip to content

Commit d91b101

Browse files
committed
spapr: Generate random HASHPKEYR for spapr machines
The hypervisor is expected to create a value for the HASHPKEY SPR for each partition. Currently it uses zero for all partitions, use a random number instead, which in theory might make kernel ROP protection more secure. Signed-of-by: Nicholas Piggin <[email protected]> Reviewed-by: Harsh Prateek Bora <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Message-ID: <[email protected]> Signed-off-by: Nicholas Piggin <[email protected]>
1 parent b4aa82d commit d91b101

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

hw/ppc/spapr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,6 +2917,9 @@ static void spapr_machine_init(MachineState *machine)
29172917
spapr_ovec_set(spapr->ov5, OV5_XIVE_EXPLOIT);
29182918
}
29192919

2920+
qemu_guest_getrandom_nofail(&spapr->hashpkey_val,
2921+
sizeof(spapr->hashpkey_val));
2922+
29202923
/* init CPUs */
29212924
spapr_init_cpus(spapr);
29222925

hw/ppc/spapr_cpu_core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
273273
env->spr_cb[SPR_PIR].default_value = cs->cpu_index;
274274
env->spr_cb[SPR_TIR].default_value = thread_index;
275275

276+
env->spr_cb[SPR_HASHPKEYR].default_value = spapr->hashpkey_val;
277+
276278
cpu_ppc_set_1lpar(cpu);
277279

278280
/* Set time-base frequency to 512 MHz. vhyp must be set first. */

include/hw/ppc/spapr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ struct SpaprMachineState {
203203
uint32_t fdt_initial_size;
204204
void *fdt_blob;
205205
uint8_t fdt_rng_seed[32];
206+
uint64_t hashpkey_val;
206207
long kernel_size;
207208
bool kernel_le;
208209
uint64_t kernel_addr;

0 commit comments

Comments
 (0)