[PATCH kernel 2/4] crypto/ccp/tsm: Fix potential size mismatch in releasing SPDM buffers

From: Alexey Kardashevskiy

Date: Thu Nov 19 2026 - 07:58:50 EST


At the moment the CCP driver allocates buffers of the maximum supported
sizes which are reported by the PSP, and potentially expands some.

The spdm_ctrl_free() helper though releases all buffers with (incorrectly)
calculated sizes.

Drop the calculation for request/response and use the maximum size
for free.

Use the actual size (potentially expanded) of scratch and output buffers.

While at this, replace the incorrect check for dev_ctx with the correct
check of the output buffer.

This did not bite so far as the maximum for request/response is 4K,
alloc and free are page aligned and the expansion is not implemented yet
in the PSP.

Fixes: 4be423572da1 ("crypto/ccp: Implement SEV-TIO PCIe IDE (phase1)")
Signed-off-by: Alexey Kardashevskiy <aik@xxxxxxx>
---
drivers/crypto/ccp/sev-dev-tio.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/crypto/ccp/sev-dev-tio.c b/drivers/crypto/ccp/sev-dev-tio.c
index c84e23982b434..37ace91a7d4d8 100644
--- a/drivers/crypto/ccp/sev-dev-tio.c
+++ b/drivers/crypto/ccp/sev-dev-tio.c
@@ -639,25 +639,23 @@ static void spdm_ctrl_init(struct spdm_ctrl *ctrl, struct tsm_dsm_tio *dev_data)
static void spdm_ctrl_free(struct tsm_dsm_tio *dev_data)
{
struct sev_tio_status *tio_status = to_tio_status(dev_data);
- size_t len = tio_status->spdm_req_size_max -
- (sla_dobj_id_to_size(SPDM_DOBJ_ID_RESP) +
- sizeof(struct sla_buffer_hdr));
struct tsm_spdm *spdm = &dev_data->spdm;

sla_buffer_unmap(dev_data->resp, dev_data->respbuf);
sla_buffer_unmap(dev_data->req, dev_data->reqbuf);
spdm->rsp = NULL;
spdm->req = NULL;
- sla_free(dev_data->req, len, true);
- sla_free(dev_data->resp, len, false);
- sla_free(dev_data->scratch, tio_status->spdm_scratch_size_max, true);
+ sla_free(dev_data->req, tio_status->spdm_req_size_max, true);
+ sla_free(dev_data->resp, tio_status->spdm_req_size_max, false);
+ sla_free(dev_data->scratch, dev_data->scratch_len, true);

dev_data->req.sla = 0;
dev_data->resp.sla = 0;
dev_data->scratch.sla = 0;
dev_data->respbuf = NULL;
dev_data->reqbuf = NULL;
- sla_free(dev_data->output, tio_status->spdm_out_size_max, true);
+ sla_free(dev_data->output, dev_data->output_len, true);
+ dev_data->output.sla = 0;
}

static int spdm_ctrl_alloc(struct tsm_dsm_tio *dev_data)
@@ -674,7 +672,7 @@ static int spdm_ctrl_alloc(struct tsm_dsm_tio *dev_data)
dev_data->output = sla_alloc(dev_data->output_len, true);

if (IS_SLA_NULL(dev_data->req) || IS_SLA_NULL(dev_data->resp) ||
- IS_SLA_NULL(dev_data->scratch) || IS_SLA_NULL(dev_data->dev_ctx)) {
+ IS_SLA_NULL(dev_data->scratch) || IS_SLA_NULL(dev_data->output)) {
ret = -ENOMEM;
goto free_spdm_exit;
}
--
2.55.0