Skip to content

Commit b4e2eb0

Browse files
jgunthorpeJarkko Sakkinen
authored andcommitted
tpm crb: Work around BIOS's that report the wrong ACPI region size
The expectation is that the if the CRB cmd/rsp buffer falls within the ACPI region that the entire buffer will be within the reason. Otherwise resource reservation will fail when it crosses regions. Work around this BIOS bug by limiting the cmd/rsp buffer to the length of the declared ACPI region. BIOS vendors should fix this by making the ACPI and register length declarations consistent. Reported-by: Davide Guerri <davide.guerri@gmail.com> Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Tested-by: Davide Guerri <davide.guerri@gmail.com> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
1 parent 302a6ad commit b4e2eb0

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

drivers/char/tpm/tpm_crb.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,27 @@ static void __iomem *crb_map_res(struct device *dev, struct crb_priv *priv,
295295
return priv->iobase + (new_res.start - io_res->start);
296296
}
297297

298+
/*
299+
* Work around broken BIOSs that return inconsistent values from the ACPI
300+
* region vs the registers. Trust the ACPI region. Such broken systems
301+
* probably cannot send large TPM commands since the buffer will be truncated.
302+
*/
303+
static u64 crb_fixup_cmd_size(struct device *dev, struct resource *io_res,
304+
u64 start, u64 size)
305+
{
306+
if (io_res->start > start || io_res->end < start)
307+
return size;
308+
309+
if (start + size - 1 <= io_res->end)
310+
return size;
311+
312+
dev_err(dev,
313+
FW_BUG "ACPI region does not cover the entire command/response buffer. %pr vs %llx %llx\n",
314+
io_res, start, size);
315+
316+
return io_res->end - start + 1;
317+
}
318+
298319
static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
299320
struct acpi_table_tpm2 *buf)
300321
{
@@ -340,7 +361,8 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
340361
pa_high = ioread32(&priv->cca->cmd_pa_high);
341362
pa_low = ioread32(&priv->cca->cmd_pa_low);
342363
cmd_pa = ((u64)pa_high << 32) | pa_low;
343-
cmd_size = ioread32(&priv->cca->cmd_size);
364+
cmd_size = crb_fixup_cmd_size(dev, &io_res, cmd_pa,
365+
ioread32(&priv->cca->cmd_size));
344366

345367
dev_dbg(dev, "cmd_hi = %X cmd_low = %X cmd_size %X\n",
346368
pa_high, pa_low, cmd_size);
@@ -353,7 +375,8 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
353375

354376
memcpy_fromio(&rsp_pa, &priv->cca->rsp_pa, 8);
355377
rsp_pa = le64_to_cpu(rsp_pa);
356-
rsp_size = ioread32(&priv->cca->rsp_size);
378+
rsp_size = crb_fixup_cmd_size(dev, &io_res, rsp_pa,
379+
ioread32(&priv->cca->rsp_size));
357380

358381
if (cmd_pa != rsp_pa) {
359382
priv->rsp = crb_map_res(dev, priv, &io_res, rsp_pa, rsp_size);

0 commit comments

Comments
 (0)