android_kernel_motorola_sm6225/drivers/pci
Tyrel Datwyler f27a00f0d5 PCI: rpadlpar: Fix potential drc_name corruption in store functions
commit cc7a0bb058b85ea03db87169c60c7cfdd5d34678 upstream.

Both add_slot_store() and remove_slot_store() try to fix up the
drc_name copied from the store buffer by placing a NUL terminator at
nbyte + 1 or in place of a '\n' if present. However, the static buffer
that we copy the drc_name data into is not zeroed and can contain
anything past the n-th byte.

This is problematic if a '\n' byte appears in that buffer after nbytes
and the string copied into the store buffer was not NUL terminated to
start with as the strchr() search for a '\n' byte will mark this
incorrectly as the end of the drc_name string resulting in a drc_name
string that contains garbage data after the n-th byte.

Additionally it will cause us to overwrite that '\n' byte on the stack
with NUL, potentially corrupting data on the stack.

The following debugging shows an example of the drmgr utility writing
"PHB 4543" to the add_slot sysfs attribute, but add_slot_store()
logging a corrupted string value.

  drmgr: drmgr: -c phb -a -s PHB 4543 -d 1
  add_slot_store: drc_name = PHB 4543°|<82>!, rc = -19

Fix this by using strscpy() instead of memcpy() to ensure the string
is NUL terminated when copied into the static drc_name buffer.
Further, since the string is now NUL terminated the code only needs to
change '\n' to '\0' when present.

Cc: stable@vger.kernel.org
Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
[mpe: Reformat change log and add mention of possible stack corruption]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20210315214821.452959-1-tyreld@linux.ibm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-03-24 11:07:37 +01:00
..
controller PCI: mediatek: Add missing of_node_put() to fix reference leak 2021-03-17 16:43:46 +01:00
endpoint PCI: endpoint: Fix for concurrent memory allocation in OB address region 2020-04-17 10:48:46 +02:00
hotplug PCI: rpadlpar: Fix potential drc_name corruption in store functions 2021-03-24 11:07:37 +01:00
pcie PCI/ASPM: Add missing newline in sysfs 'policy' 2020-08-19 08:14:58 +02:00
switch PCI/switchtec: Fix init_completion race condition with poll_wait() 2020-04-17 10:48:40 +02:00
access.c PCI: Fix pci_cfg_wait queue locking problem 2020-08-19 08:14:56 +02:00
ats.c
bus.c PCI: Add device even if driver attach failed 2020-08-21 11:05:29 +02:00
ecam.c
host-bridge.c
iov.c PCI/IOV: Fix memory leak in pci_iov_add_virtfn() 2020-02-14 16:33:23 -05:00
irq.c
Kconfig
Makefile
mmap.c
msi.c PCI/MSI: Fix incorrect MSI-X masking on resume 2019-12-21 10:57:24 +01:00
of.c
pci-acpi.c PM: ACPI: PCI: Drop acpi_pm_set_bridge_wakeup() 2020-12-30 11:26:08 +01:00
pci-driver.c PM: ACPI/PCI: Resume all devices during hibernation 2020-01-27 14:50:59 +01:00
pci-label.c
pci-mid.c x86/cpu: Sanitize FAM6_ATOM naming 2019-05-14 19:17:53 +02:00
pci-pf-stub.c
pci-stub.c
pci-sysfs.c PCI: sysfs: Ignore lockdep for remove attribute 2019-07-31 07:27:02 +02:00
pci.c PCI: Fix pci_register_io_range() memory leak 2021-03-17 16:43:46 +01:00
pci.h PCI/ERR: Use slot reset if available 2019-11-20 18:47:13 +01:00
probe.c PCI: Probe bridge window attributes once at enumeration-time 2020-08-21 11:05:29 +02:00
proc.c
quirks.c PCI: Add function 1 DMA alias quirk for Marvell 9215 SATA controller 2021-03-11 14:05:02 +01:00
remove.c
rom.c PCI: Use ioremap(), not phys_to_virt() for platform ROM 2020-10-01 13:14:40 +02:00
search.c
setup-bus.c PCI: Probe bridge window attributes once at enumeration-time 2020-08-21 11:05:29 +02:00
setup-irq.c
setup-res.c PCI: Allow pci_resize_resource() for devices on root bus 2020-06-25 15:32:48 +02:00
slot.c PCI: Fix pci_slot_release() NULL pointer dereference 2020-12-30 11:26:17 +01:00
syscall.c PCI: Align checking of syscall user config accessors 2021-03-04 09:39:48 +01:00
vc.c
vpd.c
xen-pcifront.c