* [PATCH] tpm: fix response size validation in tpm_get_random()
@ 2018-09-03 1:10 ` Jarkko Sakkinen
0 siblings, 0 replies; 7+ messages in thread
From: Jarkko Sakkinen @ 2018-09-03 1:10 UTC (permalink / raw)
To: linux-integrity
Cc: Stefan Berger, linux-security-module, Jarkko Sakkinen, stable,
Peter Huewe, Jason Gunthorpe, Arnd Bergmann, Greg Kroah-Hartman,
open list
When checking whether the response is large enough to be able to contain
the received random bytes in tpm_get_random() and tpm2_get_random(),
they fail to take account the header size, which should be added to the
minimum size. This commit fixes this issue.
Cc: stable@vger.kernel.org
Fixes: c659af78eb7b ("tpm: Check size of response before accessing data")
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
drivers/char/tpm/tpm-interface.c | 3 ++-
drivers/char/tpm/tpm2-cmd.c | 4 +++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 1a803b0cf980..318a7078b2ba 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -1321,7 +1321,8 @@ int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max)
}
rlength = be32_to_cpu(tpm_cmd.header.out.length);
- if (rlength < offsetof(struct tpm_getrandom_out, rng_data) +
+ if (rlength < TPM_HEADER_SIZE +
+ offsetof(struct tpm_getrandom_out, rng_data) +
recd) {
total = -EFAULT;
break;
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index c31b490bd41d..3acf4fd4e5a5 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -329,7 +329,9 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
&buf.data[TPM_HEADER_SIZE];
recd = min_t(u32, be16_to_cpu(out->size), num_bytes);
if (tpm_buf_length(&buf) <
- offsetof(struct tpm2_get_random_out, buffer) + recd) {
+ TPM_HEADER_SIZE +
+ offsetof(struct tpm2_get_random_out, buffer) +
+ recd) {
err = -EFAULT;
goto out;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH] tpm: fix response size validation in tpm_get_random()
@ 2018-09-03 1:10 ` Jarkko Sakkinen
0 siblings, 0 replies; 7+ messages in thread
From: Jarkko Sakkinen @ 2018-09-03 1:10 UTC (permalink / raw)
To: linux-security-module
When checking whether the response is large enough to be able to contain
the received random bytes in tpm_get_random() and tpm2_get_random(),
they fail to take account the header size, which should be added to the
minimum size. This commit fixes this issue.
Cc: stable at vger.kernel.org
Fixes: c659af78eb7b ("tpm: Check size of response before accessing data")
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
drivers/char/tpm/tpm-interface.c | 3 ++-
drivers/char/tpm/tpm2-cmd.c | 4 +++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 1a803b0cf980..318a7078b2ba 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -1321,7 +1321,8 @@ int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max)
}
rlength = be32_to_cpu(tpm_cmd.header.out.length);
- if (rlength < offsetof(struct tpm_getrandom_out, rng_data) +
+ if (rlength < TPM_HEADER_SIZE +
+ offsetof(struct tpm_getrandom_out, rng_data) +
recd) {
total = -EFAULT;
break;
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index c31b490bd41d..3acf4fd4e5a5 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -329,7 +329,9 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
&buf.data[TPM_HEADER_SIZE];
recd = min_t(u32, be16_to_cpu(out->size), num_bytes);
if (tpm_buf_length(&buf) <
- offsetof(struct tpm2_get_random_out, buffer) + recd) {
+ TPM_HEADER_SIZE +
+ offsetof(struct tpm2_get_random_out, buffer) +
+ recd) {
err = -EFAULT;
goto out;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] tpm: fix response size validation in tpm_get_random()
2018-09-03 1:10 ` Jarkko Sakkinen
@ 2018-09-05 11:12 ` Jarkko Sakkinen
-1 siblings, 0 replies; 7+ messages in thread
From: Jarkko Sakkinen @ 2018-09-05 11:12 UTC (permalink / raw)
To: linux-integrity
Cc: Stefan Berger, linux-security-module, stable, Peter Huewe,
Jason Gunthorpe, Arnd Bergmann, Greg Kroah-Hartman, open list
On Mon, Sep 03, 2018 at 04:10:04AM +0300, Jarkko Sakkinen wrote:
> When checking whether the response is large enough to be able to contain
> the received random bytes in tpm_get_random() and tpm2_get_random(),
> they fail to take account the header size, which should be added to the
> minimum size. This commit fixes this issue.
>
> Cc: stable@vger.kernel.org
> Fixes: c659af78eb7b ("tpm: Check size of response before accessing data")
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Stefan, you did the original commit. Does this look right to you?
/Jarkko
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] tpm: fix response size validation in tpm_get_random()
@ 2018-09-05 11:12 ` Jarkko Sakkinen
0 siblings, 0 replies; 7+ messages in thread
From: Jarkko Sakkinen @ 2018-09-05 11:12 UTC (permalink / raw)
To: linux-security-module
On Mon, Sep 03, 2018 at 04:10:04AM +0300, Jarkko Sakkinen wrote:
> When checking whether the response is large enough to be able to contain
> the received random bytes in tpm_get_random() and tpm2_get_random(),
> they fail to take account the header size, which should be added to the
> minimum size. This commit fixes this issue.
>
> Cc: stable at vger.kernel.org
> Fixes: c659af78eb7b ("tpm: Check size of response before accessing data")
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Stefan, you did the original commit. Does this look right to you?
/Jarkko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] tpm: fix response size validation in tpm_get_random()
2018-09-03 1:10 ` Jarkko Sakkinen
@ 2018-09-05 13:16 ` Stefan Berger
-1 siblings, 0 replies; 7+ messages in thread
From: Stefan Berger @ 2018-09-05 13:16 UTC (permalink / raw)
To: Jarkko Sakkinen, linux-integrity
Cc: linux-security-module, stable, Peter Huewe, Jason Gunthorpe,
Arnd Bergmann, Greg Kroah-Hartman, open list
On 09/02/2018 09:10 PM, Jarkko Sakkinen wrote:
> When checking whether the response is large enough to be able to contain
> the received random bytes in tpm_get_random() and tpm2_get_random(),
> they fail to take account the header size, which should be added to the
> minimum size. This commit fixes this issue.
>
> Cc: stable@vger.kernel.org
> Fixes: c659af78eb7b ("tpm: Check size of response before accessing data")
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
> drivers/char/tpm/tpm-interface.c | 3 ++-
> drivers/char/tpm/tpm2-cmd.c | 4 +++-
> 2 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index 1a803b0cf980..318a7078b2ba 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -1321,7 +1321,8 @@ int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max)
> }
>
> rlength = be32_to_cpu(tpm_cmd.header.out.length);
> - if (rlength < offsetof(struct tpm_getrandom_out, rng_data) +
> + if (rlength < TPM_HEADER_SIZE +
> + offsetof(struct tpm_getrandom_out, rng_data) +
> recd) {
> total = -EFAULT;
> break;
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index c31b490bd41d..3acf4fd4e5a5 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -329,7 +329,9 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
> &buf.data[TPM_HEADER_SIZE];
> recd = min_t(u32, be16_to_cpu(out->size), num_bytes);
> if (tpm_buf_length(&buf) <
> - offsetof(struct tpm2_get_random_out, buffer) + recd) {
> + TPM_HEADER_SIZE +
> + offsetof(struct tpm2_get_random_out, buffer) +
> + recd) {
> err = -EFAULT;
> goto out;
> }
Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] tpm: fix response size validation in tpm_get_random()
@ 2018-09-05 13:16 ` Stefan Berger
0 siblings, 0 replies; 7+ messages in thread
From: Stefan Berger @ 2018-09-05 13:16 UTC (permalink / raw)
To: linux-security-module
On 09/02/2018 09:10 PM, Jarkko Sakkinen wrote:
> When checking whether the response is large enough to be able to contain
> the received random bytes in tpm_get_random() and tpm2_get_random(),
> they fail to take account the header size, which should be added to the
> minimum size. This commit fixes this issue.
>
> Cc: stable at vger.kernel.org
> Fixes: c659af78eb7b ("tpm: Check size of response before accessing data")
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
> drivers/char/tpm/tpm-interface.c | 3 ++-
> drivers/char/tpm/tpm2-cmd.c | 4 +++-
> 2 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index 1a803b0cf980..318a7078b2ba 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -1321,7 +1321,8 @@ int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max)
> }
>
> rlength = be32_to_cpu(tpm_cmd.header.out.length);
> - if (rlength < offsetof(struct tpm_getrandom_out, rng_data) +
> + if (rlength < TPM_HEADER_SIZE +
> + offsetof(struct tpm_getrandom_out, rng_data) +
> recd) {
> total = -EFAULT;
> break;
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index c31b490bd41d..3acf4fd4e5a5 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -329,7 +329,9 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
> &buf.data[TPM_HEADER_SIZE];
> recd = min_t(u32, be16_to_cpu(out->size), num_bytes);
> if (tpm_buf_length(&buf) <
> - offsetof(struct tpm2_get_random_out, buffer) + recd) {
> + TPM_HEADER_SIZE +
> + offsetof(struct tpm2_get_random_out, buffer) +
> + recd) {
> err = -EFAULT;
> goto out;
> }
Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] tpm: fix response size validation in tpm_get_random()
@ 2019-01-16 22:35 Jarkko Sakkinen
0 siblings, 0 replies; 7+ messages in thread
From: Jarkko Sakkinen @ 2019-01-16 22:35 UTC (permalink / raw)
To: stable; +Cc: Jarkko Sakkinen
commit 84b59f6487d82d3ab4247a099aba66d4d17e8b08 upstream
When checking whether the response is large enough to be able to contain
the received random bytes in tpm_get_random() and tpm2_get_random(),
they fail to take account the header size, which should be added to the
minimum size. This commit fixes this issue.
Cc: stable@vger.kernel.org
Fixes: c659af78eb7b ("tpm: Check size of response before accessing data")
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
For v4.14 and v4.18. Fixed a merge conflict.
drivers/char/tpm/tpm-interface.c | 3 ++-
drivers/char/tpm/tpm2-cmd.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index e8822b3d10e1..a107ee2466da 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -1323,7 +1323,8 @@ int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max)
}
rlength = be32_to_cpu(tpm_cmd.header.out.length);
- if (rlength < offsetof(struct tpm_getrandom_out, rng_data) +
+ if (rlength < TPM_HEADER_SIZE +
+ offsetof(struct tpm_getrandom_out, rng_data) +
recd) {
total = -EFAULT;
break;
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index d31b09099216..79b00bc4a7c2 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -371,7 +371,8 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max)
recd = min_t(u32, be16_to_cpu(cmd.params.getrandom_out.size),
num_bytes);
rlength = be32_to_cpu(cmd.header.out.length);
- if (rlength < offsetof(struct tpm2_get_random_out, buffer) +
+ if (rlength < TPM_HEADER_SIZE +
+ offsetof(struct tpm2_get_random_out, buffer) +
recd)
return -EFAULT;
memcpy(dest, cmd.params.getrandom_out.buffer, recd);
--
2.19.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-01-16 22:35 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-03 1:10 [PATCH] tpm: fix response size validation in tpm_get_random() Jarkko Sakkinen
2018-09-03 1:10 ` Jarkko Sakkinen
2018-09-05 11:12 ` Jarkko Sakkinen
2018-09-05 11:12 ` Jarkko Sakkinen
2018-09-05 13:16 ` Stefan Berger
2018-09-05 13:16 ` Stefan Berger
2019-01-16 22:35 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.