mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 05:04:02 +02:00
KEYS: trusted: Fix tpm2_load_cmd() boundary check
tpm2_load_cmd() does boundary checks against the ASN.1 size i.e.,
payload->blob_len. Address this by passing the decoded blob size to
tpm2_load_cmd(), and use it for the boundary checks.
Cc: stable@vger.kernel.org # v5.13+
Fixes: f221974525 ("security: keys: trusted: use ASN.1 TPM2 key format for the blobs")
Reported-by: co+6a581c4284f721d4@bugs.sh
Closes: https://bugs.sh/b/6a581c4284f721d4/
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Tested-by: Srish Srinivasan <ssrish@linux.ibm.com>
Link: https://lore.kernel.org/r/20260901205809.2028454-1-jarkko@kernel.org
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
This commit is contained in:
parent
0d6a4268b0
commit
114f00d738
|
|
@ -99,7 +99,7 @@ struct tpm2_key_context {
|
|||
|
||||
static int tpm2_key_decode(struct trusted_key_payload *payload,
|
||||
struct trusted_key_options *options,
|
||||
u8 **buf)
|
||||
u8 **buf, unsigned int *blob_len)
|
||||
{
|
||||
int ret;
|
||||
struct tpm2_key_context ctx;
|
||||
|
|
@ -120,6 +120,7 @@ static int tpm2_key_decode(struct trusted_key_payload *payload,
|
|||
return -ENOMEM;
|
||||
|
||||
*buf = blob;
|
||||
*blob_len = ctx.priv_len + ctx.pub_len;
|
||||
options->keyhandle = ctx.parent;
|
||||
|
||||
memcpy(blob, ctx.priv, ctx.priv_len);
|
||||
|
|
@ -384,10 +385,11 @@ static int tpm2_load_cmd(struct tpm_chip *chip,
|
|||
int rc;
|
||||
u32 attrs;
|
||||
|
||||
rc = tpm2_key_decode(payload, options, &blob);
|
||||
rc = tpm2_key_decode(payload, options, &blob, &blob_len);
|
||||
if (rc) {
|
||||
/* old form */
|
||||
blob = payload->blob;
|
||||
blob_len = payload->blob_len;
|
||||
payload->old_format = 1;
|
||||
} else {
|
||||
/* Bind for cleanup: */
|
||||
|
|
@ -399,17 +401,17 @@ static int tpm2_load_cmd(struct tpm_chip *chip,
|
|||
return -EINVAL;
|
||||
|
||||
/* must be big enough for at least the two be16 size counts */
|
||||
if (payload->blob_len < 4)
|
||||
if (blob_len < 4)
|
||||
return -EINVAL;
|
||||
|
||||
private_len = get_unaligned_be16(blob);
|
||||
|
||||
/* must be big enough for following public_len */
|
||||
if (private_len + 2 + 2 > (payload->blob_len))
|
||||
if (private_len + 2 + 2 > blob_len)
|
||||
return -E2BIG;
|
||||
|
||||
public_len = get_unaligned_be16(blob + 2 + private_len);
|
||||
if (private_len + 2 + public_len + 2 > payload->blob_len)
|
||||
if (private_len + 2 + public_len + 2 > blob_len)
|
||||
return -E2BIG;
|
||||
|
||||
pub = blob + 2 + private_len + 2;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user