Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/pseries: Fix endianness issue when parsing PLPKS secvar flags

When a user updates a variable through the PLPKS secvar interface, we take
the first 8 bytes of the data written to the update attribute to pass
through to the H_PKS_SIGNED_UPDATE hcall as flags. These bytes are always
written in big-endian format.

Currently, the flags bytes are memcpy()ed into a u64, which is then loaded
into a register to pass as part of the hcall. This means that on LE
systems, the bytes are in the wrong order.

Use be64_to_cpup() instead, to ensure the flags bytes are byteswapped if
necessary.

Reported-by: Stefan Berger <stefanb@linux.ibm.com>
Fixes: ccadf154cb00 ("powerpc/pseries: Implement secvars for dynamic secure boot")
Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20230216070903.355091-1-ajd@linux.ibm.com

authored by

Andrew Donnellan and committed by
Michael Ellerman
7096deb7 748ea32d

+2 -1
+2 -1
arch/powerpc/platforms/pseries/plpks-secvar.c
··· 135 135 goto err; 136 136 var.namelen = rc * 2; 137 137 138 - memcpy(&flags, data, sizeof(flags)); 138 + // Flags are contained in the first 8 bytes of the buffer, and are always big-endian 139 + flags = be64_to_cpup((__be64 *)data); 139 140 140 141 var.datalen = data_size - sizeof(flags); 141 142 var.data = data + sizeof(flags);