]> git.baikalelectronics.ru Git - kernel.git/commit
thunderbolt: Prevent crash if non-active NVMem file is read
authorMika Westerberg <mika.westerberg@linux.intel.com>
Thu, 13 Feb 2020 09:56:04 +0000 (12:56 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 28 Feb 2020 16:22:13 +0000 (17:22 +0100)
commitdde142f6182f72f2ed2faa12c11b5f465988cc56
tree61ed29cfe6d0e2c0d05081464a4deded09562004
parent366145ba7a35b0f32c9b1015a0ad3fd252f9d010
thunderbolt: Prevent crash if non-active NVMem file is read

commit 9b4a47e447042956aebb607cd8c8dbf74ee8775a upstream.

The driver does not populate .reg_read callback for the non-active NVMem
because the file is supposed to be write-only. However, it turns out
NVMem subsystem does not yet support this and expects that the .reg_read
callback is provided. If user reads the binary attribute it triggers
NULL pointer dereference like this one:

  BUG: kernel NULL pointer dereference, address: 0000000000000000
  ...
  Call Trace:
   bin_attr_nvmem_read+0x64/0x80
   kernfs_fop_read+0xa7/0x180
   vfs_read+0xbd/0x170
   ksys_read+0x5a/0xd0
   do_syscall_64+0x43/0x150
   entry_SYSCALL_64_after_hwframe+0x44/0xa9

Fix this in the driver by providing .reg_read callback that always
returns an error.

Reported-by: Nicholas Johnson <nicholas.johnson-opensource@outlook.com.au>
Fixes: 2eb235f2e720 ("thunderbolt: Add support for host and device NVM firmware upgrade")
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20200213095604.1074-1-mika.westerberg@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/thunderbolt/switch.c