* Fwd: TPM unaligned memory accesses
[not found] <CA+dP_Q1Siy7CEMABgEtUAVnbWxiQ8DLc2LkgVY+W29QEcC1YDA@mail.gmail.com>
@ 2021-03-10 5:41 ` Andrew James
2021-03-10 19:32 ` Jarkko Sakkinen
0 siblings, 1 reply; 2+ messages in thread
From: Andrew James @ 2021-03-10 5:41 UTC (permalink / raw)
To: linux-integrity
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.
Thanks!.
Andrew
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Fwd: TPM unaligned memory accesses
2021-03-10 5:41 ` Fwd: TPM unaligned memory accesses Andrew James
@ 2021-03-10 19:32 ` Jarkko Sakkinen
0 siblings, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2021-03-10 19:32 UTC (permalink / raw)
To: Andrew James; +Cc: linux-integrity
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@intel.com/
It's years since this was sent but I recall the issues were fairly
easy to fix.
/Jarkko
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-10 19:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CA+dP_Q1Siy7CEMABgEtUAVnbWxiQ8DLc2LkgVY+W29QEcC1YDA@mail.gmail.com>
2021-03-10 5:41 ` Fwd: TPM unaligned memory accesses Andrew James
2021-03-10 19:32 ` Jarkko Sakkinen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.