* [PATCH] tpm: fix potential buffer overruns caused by bit glitches on the bus
@ 2018-03-16 11:27 Jarkko Sakkinen
2018-03-16 13:11 ` Greg KH
0 siblings, 1 reply; 6+ messages in thread
From: Jarkko Sakkinen @ 2018-03-16 11:27 UTC (permalink / raw)
To: stable; +Cc: Jeremy Boone, James Bottomley, Jarkko Sakkinen
From: Jeremy Boone <jeremy.boone@nccgroup.trust>
commit c8e3e06d252155ad0e38a64a65ebb85638893025 upstream
Discrete TPMs are often connected over slow serial buses which, on
some platforms, can have glitches causing bit flips. If a bit does
flip it could cause an overrun if it's in one of the size parameters,
so sanity check that we're not overrunning the provided buffer when
doing a memcpy().
Signed-off-by: Jeremy Boone <jeremy.boone@nccgroup.trust>
Cc: stable@vger.kernel.org
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
Backport for v4.9 because of the merge conflict.
drivers/char/tpm/tpm-interface.c | 5 +++++
drivers/char/tpm/tpm2-cmd.c | 6 ++++++
2 files changed, 11 insertions(+)
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index d0ac2d56520f..830d7e30e508 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -1078,6 +1078,11 @@ int tpm_get_random(u32 chip_num, u8 *out, size_t max)
break;
recd = be32_to_cpu(tpm_cmd.params.getrandom_out.rng_data_len);
+ if (recd > num_bytes) {
+ total = -EFAULT;
+ break;
+ }
+
memcpy(dest, tpm_cmd.params.getrandom_out.rng_data, recd);
dest += recd;
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 17896d654033..a5780ebe15ef 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -668,6 +668,11 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
if (!rc) {
data_len = be16_to_cpup(
(__be16 *) &buf.data[TPM_HEADER_SIZE + 4]);
+ if (data_len < MIN_KEY_SIZE || data_len > MAX_KEY_SIZE + 1) {
+ rc = -EFAULT;
+ goto out;
+ }
+
data = &buf.data[TPM_HEADER_SIZE + 6];
memcpy(payload->key, data, data_len - 1);
@@ -675,6 +680,7 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
payload->migratable = data[data_len - 1];
}
+out:
tpm_buf_destroy(&buf);
return rc;
}
--
2.15.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] tpm: fix potential buffer overruns caused by bit glitches on the bus
2018-03-16 11:27 [PATCH] tpm: fix potential buffer overruns caused by bit glitches on the bus Jarkko Sakkinen
@ 2018-03-16 13:11 ` Greg KH
2018-03-16 14:35 ` Jarkko Sakkinen
0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2018-03-16 13:11 UTC (permalink / raw)
To: Jarkko Sakkinen; +Cc: stable, Jeremy Boone, James Bottomley
On Fri, Mar 16, 2018 at 01:27:26PM +0200, Jarkko Sakkinen wrote:
> From: Jeremy Boone <jeremy.boone@nccgroup.trust>
>
> commit c8e3e06d252155ad0e38a64a65ebb85638893025 upstream
There is no such id upstream :(
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tpm: fix potential buffer overruns caused by bit glitches on the bus
2018-03-16 13:11 ` Greg KH
@ 2018-03-16 14:35 ` Jarkko Sakkinen
2018-03-16 14:41 ` Greg KH
0 siblings, 1 reply; 6+ messages in thread
From: Jarkko Sakkinen @ 2018-03-16 14:35 UTC (permalink / raw)
To: Greg KH; +Cc: stable, Jeremy Boone, James Bottomley
On Fri, Mar 16, 2018 at 02:11:26PM +0100, Greg KH wrote:
> On Fri, Mar 16, 2018 at 01:27:26PM +0200, Jarkko Sakkinen wrote:
> > From: Jeremy Boone <jeremy.boone@nccgroup.trust>
> >
> > commit c8e3e06d252155ad0e38a64a65ebb85638893025 upstream
>
> There is no such id upstream :(
Oops: the correct upstream ID is 3be23274755ee85771270a23af7691dc9b3a95db
Sorry.
/Jarkko
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tpm: fix potential buffer overruns caused by bit glitches on the bus
2018-03-16 14:35 ` Jarkko Sakkinen
@ 2018-03-16 14:41 ` Greg KH
2018-03-19 20:24 ` Jarkko Sakkinen
0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2018-03-16 14:41 UTC (permalink / raw)
To: Jarkko Sakkinen; +Cc: stable, Jeremy Boone, James Bottomley
On Fri, Mar 16, 2018 at 04:35:02PM +0200, Jarkko Sakkinen wrote:
> On Fri, Mar 16, 2018 at 02:11:26PM +0100, Greg KH wrote:
> > On Fri, Mar 16, 2018 at 01:27:26PM +0200, Jarkko Sakkinen wrote:
> > > From: Jeremy Boone <jeremy.boone@nccgroup.trust>
> > >
> > > commit c8e3e06d252155ad0e38a64a65ebb85638893025 upstream
> >
> > There is no such id upstream :(
>
> Oops: the correct upstream ID is 3be23274755ee85771270a23af7691dc9b3a95db
Can you please resend it with the correct one so I don't have to
hand-edit things?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tpm: fix potential buffer overruns caused by bit glitches on the bus
2018-03-16 14:41 ` Greg KH
@ 2018-03-19 20:24 ` Jarkko Sakkinen
0 siblings, 0 replies; 6+ messages in thread
From: Jarkko Sakkinen @ 2018-03-19 20:24 UTC (permalink / raw)
To: Greg KH; +Cc: stable, Jeremy Boone, James Bottomley
On Fri, Mar 16, 2018 at 03:41:21PM +0100, Greg KH wrote:
> On Fri, Mar 16, 2018 at 04:35:02PM +0200, Jarkko Sakkinen wrote:
> > On Fri, Mar 16, 2018 at 02:11:26PM +0100, Greg KH wrote:
> > > On Fri, Mar 16, 2018 at 01:27:26PM +0200, Jarkko Sakkinen wrote:
> > > > From: Jeremy Boone <jeremy.boone@nccgroup.trust>
> > > >
> > > > commit c8e3e06d252155ad0e38a64a65ebb85638893025 upstream
> > >
> > > There is no such id upstream :(
> >
> > Oops: the correct upstream ID is 3be23274755ee85771270a23af7691dc9b3a95db
>
> Can you please resend it with the correct one so I don't have to
> hand-edit things?
>
> thanks,
>
> greg k-h
Yes, sure.
/Jarkko
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] tpm: fix potential buffer overruns caused by bit glitches on the bus
@ 2018-03-21 8:50 Jarkko Sakkinen
0 siblings, 0 replies; 6+ messages in thread
From: Jarkko Sakkinen @ 2018-03-21 8:50 UTC (permalink / raw)
To: stable; +Cc: Jeremy Boone, James Bottomley, Jarkko Sakkinen
From: Jeremy Boone <jeremy.boone@nccgroup.trust>
commit 3be23274755ee85771270a23af7691dc9b3a95db upstream
Discrete TPMs are often connected over slow serial buses which, on
some platforms, can have glitches causing bit flips. If a bit does
flip it could cause an overrun if it's in one of the size parameters,
so sanity check that we're not overrunning the provided buffer when
doing a memcpy().
Signed-off-by: Jeremy Boone <jeremy.boone@nccgroup.trust>
Cc: stable@vger.kernel.org
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
Backported to v4.9
v2: fixed the upstream ID
drivers/char/tpm/tpm-interface.c | 5 +++++
drivers/char/tpm/tpm2-cmd.c | 6 ++++++
2 files changed, 11 insertions(+)
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index d0ac2d56520f..830d7e30e508 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -1078,6 +1078,11 @@ int tpm_get_random(u32 chip_num, u8 *out, size_t max)
break;
recd = be32_to_cpu(tpm_cmd.params.getrandom_out.rng_data_len);
+ if (recd > num_bytes) {
+ total = -EFAULT;
+ break;
+ }
+
memcpy(dest, tpm_cmd.params.getrandom_out.rng_data, recd);
dest += recd;
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 17896d654033..a5780ebe15ef 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -668,6 +668,11 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
if (!rc) {
data_len = be16_to_cpup(
(__be16 *) &buf.data[TPM_HEADER_SIZE + 4]);
+ if (data_len < MIN_KEY_SIZE || data_len > MAX_KEY_SIZE + 1) {
+ rc = -EFAULT;
+ goto out;
+ }
+
data = &buf.data[TPM_HEADER_SIZE + 6];
memcpy(payload->key, data, data_len - 1);
@@ -675,6 +680,7 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
payload->migratable = data[data_len - 1];
}
+out:
tpm_buf_destroy(&buf);
return rc;
}
--
2.15.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-03-21 8:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-16 11:27 [PATCH] tpm: fix potential buffer overruns caused by bit glitches on the bus Jarkko Sakkinen
2018-03-16 13:11 ` Greg KH
2018-03-16 14:35 ` Jarkko Sakkinen
2018-03-16 14:41 ` Greg KH
2018-03-19 20:24 ` Jarkko Sakkinen
2018-03-21 8:50 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.