All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Andrew James <ajames3254@gmail.com>
Cc: linux-integrity@vger.kernel.org
Subject: Re: Fwd: TPM unaligned memory accesses
Date: Wed, 10 Mar 2021 21:32:10 +0200	[thread overview]
Message-ID: <YEkeuk06i3dGZn+b@kernel.org> (raw)
In-Reply-To: <CA+dP_Q3o8r-0h5W1dVOppeEFoyfz2F4A9Ve_-zOB9hWWQSS7ng@mail.gmail.com>

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

      reply	other threads:[~2021-03-10 19:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YEkeuk06i3dGZn+b@kernel.org \
    --to=jarkko@kernel.org \
    --cc=ajames3254@gmail.com \
    --cc=linux-integrity@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.