linux-stable/Documentation/core-api
Halil Pasic d4d975e792 swiotlb: fix info leak with DMA_FROM_DEVICE
commit ddbd89deb7 upstream.

The problem I'm addressing was discovered by the LTP test covering
cve-2018-1000204.

A short description of what happens follows:
1) The test case issues a command code 00 (TEST UNIT READY) via the SG_IO
   interface with: dxfer_len == 524288, dxdfer_dir == SG_DXFER_FROM_DEV
   and a corresponding dxferp. The peculiar thing about this is that TUR
   is not reading from the device.
2) In sg_start_req() the invocation of blk_rq_map_user() effectively
   bounces the user-space buffer. As if the device was to transfer into
   it. Since commit a45b599ad8 ("scsi: sg: allocate with __GFP_ZERO in
   sg_build_indirect()") we make sure this first bounce buffer is
   allocated with GFP_ZERO.
3) For the rest of the story we keep ignoring that we have a TUR, so the
   device won't touch the buffer we prepare as if the we had a
   DMA_FROM_DEVICE type of situation. My setup uses a virtio-scsi device
   and the  buffer allocated by SG is mapped by the function
   virtqueue_add_split() which uses DMA_FROM_DEVICE for the "in" sgs (here
   scatter-gather and not scsi generics). This mapping involves bouncing
   via the swiotlb (we need swiotlb to do virtio in protected guest like
   s390 Secure Execution, or AMD SEV).
4) When the SCSI TUR is done, we first copy back the content of the second
   (that is swiotlb) bounce buffer (which most likely contains some
   previous IO data), to the first bounce buffer, which contains all
   zeros.  Then we copy back the content of the first bounce buffer to
   the user-space buffer.
5) The test case detects that the buffer, which it zero-initialized,
  ain't all zeros and fails.

One can argue that this is an swiotlb problem, because without swiotlb
we leak all zeros, and the swiotlb should be transparent in a sense that
it does not affect the outcome (if all other participants are well
behaved).

Copying the content of the original buffer into the swiotlb buffer is
the only way I can think of to make swiotlb transparent in such
scenarios. So let's do just that if in doubt, but allow the driver
to tell us that the whole mapped buffer is going to be overwritten,
in which case we can preserve the old behavior and avoid the performance
impact of the extra bounce.

Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-04-08 14:39:46 +02:00
..
irq docs: add IRQ documentation at the core-api book 2020-05-15 12:00:56 -06:00
assoc_array.rst Documentation: Use "while" instead of "whilst" 2018-11-20 09:30:43 -07:00
atomic_ops.rst locking/atomics/Documentation: Describe atomic_set() as a write operation 2018-07-17 09:30:31 +02:00
boot-time-mm.rst docs/boot-time-mm: remove bootmem documentation 2018-10-31 08:54:16 -07:00
bus-virt-phys-mapping.rst docs: move other kAPI documents to core-api 2020-06-26 11:33:42 -06:00
cachetlb.rst mm: remove map_vm_range 2020-06-02 10:59:11 -07:00
circular-buffers.rst doc: Remove ".vnet" from paulmck email addresses 2019-05-28 09:02:57 -07:00
cpu_hotplug.rst Documentation: core-api/cpu_hotplug: fix a typo 2020-09-09 11:42:09 -06:00
debug-objects.rst
debugging-via-ohci1394.rst docs: debugging-via-ohci1394.txt: add it to the core-api book 2020-05-15 11:59:17 -06:00
dma-api-howto.rst docs: move DMA kAPI to Documentation/core-api 2020-05-15 11:51:54 -06:00
dma-api.rst dma-mapping: document dma_{alloc,free}_pages 2020-10-23 12:07:46 +02:00
dma-attributes.rst swiotlb: fix info leak with DMA_FROM_DEVICE 2022-04-08 14:39:46 +02:00
dma-isa-lpc.rst docs: fix references for DMA*.txt files 2020-06-26 10:01:32 -06:00
errseq.rst errseq: Add to documentation tree 2018-01-01 12:40:27 -07:00
genalloc.rst lib/genalloc.c: rename addr_in_gen_pool to gen_pool_has_addr 2019-12-04 19:44:13 -08:00
generic-radix-tree.rst generic radix trees 2019-03-12 10:04:02 -07:00
genericirq.rst docs: genericirq.rst: don't document chip.c functions twice 2020-10-15 07:49:41 +02:00
gfp_mask-from-fs-io.rst docs: core-api/gfp_mask-from-fs-io: add a label for cross-referencing 2018-09-20 11:02:32 -06:00
idr.rst Core-api: Documentation: Replace deprecated :c:func: Usage 2020-08-11 10:26:08 -06:00
index.rst docs: move other kAPI documents to core-api 2020-06-26 11:33:42 -06:00
kernel-api.rst docs: kernel-api.rst: drop kernel/irq/manage.c kernel-doc tag 2020-10-15 07:49:41 +02:00
kobject.rst kobject: documentation: Replace HTTP links with HTTPS ones 2020-07-13 09:30:41 -06:00
kref.rst docs: move the kref doc into the core-api book 2020-05-15 12:02:19 -06:00
librs.rst
local_ops.rst
memory-allocation.rst docs/core-api: memory-allocation: describe reclaim behaviour 2020-07-23 14:09:09 -06:00
memory-hotplug.rst docs/core-api: memory-hotplug: add some details about locking internals 2018-10-12 11:14:19 -06:00
mm-api.rst mm: add pagemap.h to the fine documentation 2020-04-02 09:35:29 -07:00
packing.rst docs: packing: move it to core-api book and adjust markups 2019-07-31 13:30:01 -06:00
padata.rst padata: fold padata_alloc_possible() into padata_alloc() 2020-07-23 17:34:18 +10:00
pin_user_pages.rst docs: mm/gup: minor documentation update 2020-06-26 00:27:37 -07:00
printk-basics.rst Documentation: printk-basics: eliminate duplicated word 2020-07-13 09:44:05 -06:00
printk-formats.rst It's been a busy cycle for documentation - hopefully the busiest for a 2020-08-04 22:47:54 -07:00
protection-keys.rst x86/Kconfig: Update config and kernel doc for MPK feature on AMD 2020-05-28 18:27:40 +02:00
rbtree.rst Replace HTTP links with HTTPS ones: documentation 2020-06-08 09:30:19 -06:00
refcount-vs-atomic.rst docs: remove :c:func: from refcount-vs-atomic.rst 2019-10-07 09:08:56 -06:00
symbol-namespaces.rst scripts/nsdeps: support nsdeps for external module builds 2019-11-11 20:10:01 +09:00
this_cpu_ops.rst docs: move other kAPI documents to core-api 2020-06-26 11:33:42 -06:00
timekeeping.rst docs: timekeeping: Use correct prototype for deprecated functions 2020-04-15 14:48:26 -06:00
tracepoint.rst
unaligned-memory-access.rst docs: move other kAPI documents to core-api 2020-06-26 11:33:42 -06:00
workqueue.rst docs: basics.rst: move kernel-doc workqueue markups to workqueue.rst 2020-10-15 07:49:41 +02:00
xarray.rst XArray: add xas_split 2020-10-16 11:11:15 -07:00