OSDN Git Service

thunderbolt: dma_port: Fix NVM read buffer bounds and offset issue
authorMathias Nyman <mathias.nyman@linux.intel.com>
Tue, 27 Apr 2021 12:48:29 +0000 (15:48 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Jun 2021 06:38:04 +0000 (08:38 +0200)
commit73d4262de798478a1fc5055fe6f58b507a8315bf
tree8acab1a9acb8699083a2cebcf6341ba4ef9184ae
parent386918878ce4cd676e4607233866e03c9399a46a
thunderbolt: dma_port: Fix NVM read buffer bounds and offset issue

commit b106776080a1cf953a1b2fd50cb2a995db4732be upstream.

Up to 64 bytes of data can be read from NVM in one go. Read address
must be dword aligned. Data is read into a local buffer.

If caller asks to read data starting at an unaligned address then full
dword is anyway read from NVM into a local buffer. Data is then copied
from the local buffer starting at the unaligned offset to the caller
buffer.

In cases where asked data length + unaligned offset is over 64 bytes
we need to make sure we don't read past the 64 bytes in the local
buffer when copying to caller buffer, and make sure that we don't
skip copying unaligned offset bytes from local buffer anymore after
the first round of 64 byte NVM data read.

Fixes: 3e13676862f9 ("thunderbolt: Add support for DMA configuration based mailbox")
Cc: stable@vger.kernel.org
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/thunderbolt/dma_port.c