[PATCH v3] keys/trusted/tpm2: Validate TPM2_Create object sizes separately

sashiko-bot at kernel.org sashiko-bot at kernel.org
Sat Sep 26 18:51:30 UTC 2026


Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] cleanup: mixing goto-based error handling with scope-based cleanup
--

commit 6bc711f0f487069cc2bd8437493ff78b9ed1f263
Author: Srish Srinivasan <ssrish at linux.ibm.com>

keys/trusted/tpm2: Validate TPM2_Create object sizes separately

This commit updates trusted key creation to validate TPM2_Create object
sizes separately from the complete response area. It also adopts scope-based
cleanup to simplify resource management.

> diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trusted-keys/trusted_tpm2.c
> index c2a69bcf381d7..eae9d81fed0ff 100644
> --- a/security/keys/trusted-keys/trusted_tpm2.c
> +++ b/security/keys/trusted-keys/trusted_tpm2.c

[ ... ]

> @@ -340,10 +345,11 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
>  		goto out;
>  
>  	blob_len = tpm_buf_read_u32(buf, &offset);
> -	if (blob_len > MAX_BLOB_SIZE || buf->flags & TPM_BUF_INVALID) {
> +	if (buf->flags & TPM_BUF_INVALID) {
>  		rc = -E2BIG;
>  		goto out;
>  	}
> +
>  	if (buf->length - offset < blob_len) {
>  		rc = -EFAULT;
>  		goto out;

[Severity: Low]
Does this function mix goto-based error handling with scope-based cleanup?

Looking at tpm2_seal_trusted() in security/keys/trusted-keys/trusted_tpm2.c, 
it defines resources using scope-based cleanup:

	struct tpm_buf *buf __free(kfree) = NULL;
	struct tpm_buf *sized __free(kfree) = NULL;

But the function still uses goto labels for TPM operations cleanup:

out:
	if (!rc)
		payload->blob_len = blob_len;

out_put:
	tpm_put_ops(chip);
	return tpm_ret_to_err(rc);

The cleanup subsystem guidelines expect that usage of goto and cleanup
helpers are never mixed in the same function.

Could the remaining goto labels in tpm2_seal_trusted() be converted to
scope-based cleanup to avoid mixing paradigms?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260926184203.479203-1-ssrish@linux.ibm.com?part=1



More information about the Linux-security-module-archive mailing list