tpm: Fix NULL return in tpm_ibmvtpm_get_desired_dma
authorHon Ching (Vicky) Lo <honclo@linux.vnet.ibm.com>
Sun, 30 Nov 2014 14:01:28 +0000 (15:01 +0100)
committerPeter Huewe <peterhuewe@gmx.de>
Sat, 17 Jan 2015 13:00:06 +0000 (14:00 +0100)
There was an oops in tpm_ibmvtpm_get_desired_dma, which caused
kernel panic during boot when vTPM is enabled in Power partition
configured in AMS mode.

vio_bus_probe calls vio_cmo_bus_probe which calls
tpm_ibmvtpm_get_desired_dma to get the size needed for DMA allocation.
The problem is, vio_cmo_bus_probe is called before calling probe, which
for vtpm is tpm_ibmvtpm_probe and it's this function that initializes
and sets up vtpm's CRQ and gets required data values.  Therefore,
since this has not yet been done, NULL is returned in attempt to get
the size for DMA allocation.

We added a NULL check.  In addition, a default buffer size will
be set when NULL is returned.

Cc: <stable@vger.kernel.org>
Signed-off-by: Hon Ching (Vicky) Lo <honclo@linux.vnet.ibm.com>
Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
drivers/char/tpm/tpm_ibmvtpm.c

index af74c57e509094a389cccfada0bf8a9a3b3f1734..4109222f2878c107f757d0a368985558c93ef19a 100644 (file)
@@ -307,6 +307,14 @@ static int tpm_ibmvtpm_remove(struct vio_dev *vdev)
 static unsigned long tpm_ibmvtpm_get_desired_dma(struct vio_dev *vdev)
 {
        struct ibmvtpm_dev *ibmvtpm = ibmvtpm_get_data(&vdev->dev);
+
+       /* ibmvtpm initializes at probe time, so the data we are
+       * asking for may not be set yet. Estimate that 4K required
+       * for TCE-mapped buffer in addition to CRQ.
+       */
+       if (!ibmvtpm)
+               return CRQ_RES_BUF_SIZE + PAGE_SIZE;
+
        return CRQ_RES_BUF_SIZE + ibmvtpm->rtce_size;
 }
 
This page took 0.036021 seconds and 5 git commands to generate.