thunderbolt: usb4: Fix NVM read buffer bounds and offset issue
authorMathias Nyman <mathias.nyman@linux.intel.com>
Thu, 25 Mar 2021 08:32:50 +0000 (10:32 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Jun 2021 07:00:32 +0000 (09:00 +0200)
commit1b4a65408ec58c6cd972eca643ffad90bcb1880d
treed4b1fa6e64bbfc18921342df42b97d970c88ec35
parent5394ae9d8c7961dd93807fdf1b12a1dde96b0a55
thunderbolt: usb4: Fix NVM read buffer bounds and offset issue

commit 22c7a18ed5f007faccb7527bc890463763214081 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: b04079837b20 ("thunderbolt: Add initial support for USB4")
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/usb4.c