[PATCH v11 0/3] tpm: robust stack allocations

Jarkko Sakkinen posted 3 patches 1 week, 1 day ago
drivers/char/tpm/tpm-buf.c                | 139 +++++----
drivers/char/tpm/tpm-dev-common.c         |   4 +-
drivers/char/tpm/tpm-dev.h                |   2 +-
drivers/char/tpm/tpm-interface.c          |  36 ++-
drivers/char/tpm/tpm-sysfs.c              |  20 +-
drivers/char/tpm/tpm.h                    |  16 +-
drivers/char/tpm/tpm1-cmd.c               | 177 +++++------
drivers/char/tpm/tpm2-cmd.c               | 349 +++++++++-------------
drivers/char/tpm/tpm2-sessions.c          | 127 ++++----
drivers/char/tpm/tpm2-space.c             |  44 ++-
drivers/char/tpm/tpm_tis_i2c.c            |   4 +-
drivers/char/tpm/tpm_vtpm_proxy.c         |  34 +--
include/linux/tpm.h                       |  28 +-
security/keys/trusted-keys/trusted_tpm1.c |  34 +--
security/keys/trusted-keys/trusted_tpm2.c | 156 +++++-----
15 files changed, 556 insertions(+), 614 deletions(-)
[PATCH v11 0/3] tpm: robust stack allocations
Posted by Jarkko Sakkinen 1 week, 1 day ago
1. These are previous changes to tpm_buf, which make stack allocations
   much more feasible than previously.
2. Migrate low-hanging fruit to use stack allocations.
3. Re-orchestrate tpm_get_random().

Jarkko Sakkinen (3):
  tpm: Make TPM buffer allocations more robust
  tpm: Use TPM_MIN_BUF_SIZE in driver commands
  tpm orchestrate tpm_get_random() in the function

 drivers/char/tpm/tpm-buf.c                | 139 +++++----
 drivers/char/tpm/tpm-dev-common.c         |   4 +-
 drivers/char/tpm/tpm-dev.h                |   2 +-
 drivers/char/tpm/tpm-interface.c          |  36 ++-
 drivers/char/tpm/tpm-sysfs.c              |  20 +-
 drivers/char/tpm/tpm.h                    |  16 +-
 drivers/char/tpm/tpm1-cmd.c               | 177 +++++------
 drivers/char/tpm/tpm2-cmd.c               | 349 +++++++++-------------
 drivers/char/tpm/tpm2-sessions.c          | 127 ++++----
 drivers/char/tpm/tpm2-space.c             |  44 ++-
 drivers/char/tpm/tpm_tis_i2c.c            |   4 +-
 drivers/char/tpm/tpm_vtpm_proxy.c         |  34 +--
 include/linux/tpm.h                       |  28 +-
 security/keys/trusted-keys/trusted_tpm1.c |  34 +--
 security/keys/trusted-keys/trusted_tpm2.c | 156 +++++-----
 15 files changed, 556 insertions(+), 614 deletions(-)

-- 
2.39.5
Re: [PATCH v11 0/3] tpm: robust stack allocations
Posted by Jarkko Sakkinen 1 week ago
On Tue, Sep 23, 2025 at 08:07:41PM +0300, Jarkko Sakkinen wrote:
> 1. These are previous changes to tpm_buf, which make stack allocations
>    much more feasible than previously.
> 2. Migrate low-hanging fruit to use stack allocations.
> 3. Re-orchestrate tpm_get_random().
> 
> Jarkko Sakkinen (3):
>   tpm: Make TPM buffer allocations more robust
>   tpm: Use TPM_MIN_BUF_SIZE in driver commands
>   tpm orchestrate tpm_get_random() in the function

I'm quite soon sending v12 because I randomly noticed a resource
over-cosumption bug. which could be theoretically triggered e.g.
via interposing a bus or a faulty device: tpm2_get_pcr_allocation()
does not have a hard limit for the number of PCR banks.

The fix:

https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git/commit/?h=tpm-buf&id=3d92f14c204d09babadaa0b7c7a82c40d11696d0

It does a bit of extra (out of scope) grouping those related
constants but I'd like to keep it that way (should not cause
much harm in the context of merge conflicts).

BR, Jarkko
Re: [PATCH v11 0/3] tpm: robust stack allocations
Posted by Jarkko Sakkinen 1 week ago
On Wed, Sep 24, 2025 at 04:31:48AM +0300, Jarkko Sakkinen wrote:
> On Tue, Sep 23, 2025 at 08:07:41PM +0300, Jarkko Sakkinen wrote:
> > 1. These are previous changes to tpm_buf, which make stack allocations
> >    much more feasible than previously.
> > 2. Migrate low-hanging fruit to use stack allocations.
> > 3. Re-orchestrate tpm_get_random().
> > 
> > Jarkko Sakkinen (3):
> >   tpm: Make TPM buffer allocations more robust
> >   tpm: Use TPM_MIN_BUF_SIZE in driver commands
> >   tpm orchestrate tpm_get_random() in the function
> 
> I'm quite soon sending v12 because I randomly noticed a resource
> over-cosumption bug. which could be theoretically triggered e.g.
> via interposing a bus or a faulty device: tpm2_get_pcr_allocation()
> does not have a hard limit for the number of PCR banks.
> 
> The fix:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git/commit/?h=tpm-buf&id=3d92f14c204d09babadaa0b7c7a82c40d11696d0

[should have "ret = -E2BIG; goto out;". The reason for that bug is that
 I just rebased the patch from tip to the bottom of the series, which
 caused some merge conflicts.]

BR, Jarkko