linux/drivers/misc/ocxl
Frederic Barrat a58d37bce0 ocxl: Fix concurrent AFU open and device removal
If an ocxl device is unbound through sysfs at the same time its AFU is
being opened by a user process, the open code may dereference freed
stuctures, which can lead to kernel oops messages. You'd have to hit a
tiny time window, but it's possible. It's fairly easy to test by
making the time window bigger artificially.

Fix it with a combination of 2 changes:
  - when an AFU device is found in the IDR by looking for the device
    minor number, we should hold a reference on the device until after
    the context is allocated. A reference on the AFU structure is kept
    when the context is allocated, so we can release the reference on
    the device after the context allocation.
  - with the fix above, there's still another even tinier window,
    between the time the AFU device is found in the IDR and the
    reference on the device is taken. We can fix this one by removing
    the IDR entry earlier, when the device setup is removed, instead
    of waiting for the 'release' device callback. With proper locking
    around the IDR.

Fixes: 75ca758adb ("ocxl: Create a clear delineation between ocxl backend & frontend")
Cc: stable@vger.kernel.org # v5.2+
Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20190624144148.32022-1-fbarrat@linux.ibm.com
2019-12-10 20:34:23 +11:00
..
afu_irq.c ocxl: move event_fd handling to frontend 2019-05-03 02:55:02 +10:00
config.c ocxl: Update for AFU descriptor template version 1.1 2019-07-10 13:20:44 +10:00
context.c ocxl: Allow contexts to be attached with a NULL mm 2019-07-03 21:29:47 +02:00
core.c ocxl: Create a clear delineation between ocxl backend & frontend 2019-05-03 02:55:01 +10:00
file.c ocxl: Fix concurrent AFU open and device removal 2019-12-10 20:34:23 +11:00
Kconfig Merge 5.2-rc4 into char-misc-next 2019-06-09 09:11:21 +02:00
link.c ocxl: Allow contexts to be attached with a NULL mm 2019-07-03 21:29:47 +02:00
main.c powerpc/64s/radix: introduce options to disable use of the tlbie instruction 2019-09-05 14:22:41 +10:00
Makefile ocxl: Provide global MMIO accessors for external drivers 2019-05-03 02:55:02 +10:00
mmio.c ocxl: Provide global MMIO accessors for external drivers 2019-05-03 02:55:02 +10:00
ocxl_internal.h ocxl: Use the correct style for SPDX License Identifier 2019-10-10 15:34:40 +02:00
pasid.c
pci.c ocxl: Make ocxl_remove() static 2019-05-28 12:08:11 +10:00
sysfs.c ocxl: Create a clear delineation between ocxl backend & frontend 2019-05-03 02:55:01 +10:00
trace.c ocxl: Add trace points 2018-01-24 11:42:59 +11:00
trace.h ocxl: Use the correct style for SPDX License Identifier 2019-10-10 15:34:40 +02:00