On Wed, Mar 10, 2021 at 04:41:54PM +1100, Andrew James wrote: > Hi everyone, > > I noticed the following potential unaligned memory access in > tpm-interface.c, and I was wondering how it would be handled on > architectures that don't support unaligned accesses. Is this TPM code > expected to work on all architectures? > > ssize_t tpm_transmit_cmd(...) > { > const struct tpm_header *header = (struct tpm_header *)buf->data; > int err; > ssize_t len; > > len = tpm_transmit(chip, buf->data, PAGE_SIZE); > if (len < 0) > return len; > > err = be32_to_cpu(header->return_code); > ... > } > > I'm referring to the line at the bottom, before the ellipsis where we > read 'return_code'. > > struct tpm_header has a __be16 tag followed by a __be32 return code. > If we are reading 'return_code', is this an unaligned access? > Similarly this would apply to the 'length' member too? > > Documentation/unaligned-memory-access.txt recommends going through the > kernel API get_unaligned() and put_unaligned() in <asm/unaligned.h> to > avoid unaligned accesses, but I don't see this anywhere in the TPM > code. I'm just trying to wrap my head around this. There's a patch for this in existence: https://lore.kernel.org/tpmdd-devel/1479899094-9486-1-git-send-email-tomas.winkler@xxxxxxxxx/ It's years since this was sent but I recall the issues were fairly easy to fix. /Jarkko