]> www.infradead.org Git - users/jedix/linux-maple.git/commit
net/mlx4_en: fix potential use-after-free with dma_unmap_page
authorSarah Newman <srn@prgmr.com>
Thu, 31 May 2018 01:04:05 +0000 (18:04 -0700)
committerBrian Maly <brian.maly@oracle.com>
Tue, 30 Oct 2018 17:56:26 +0000 (13:56 -0400)
commit1fb814df16a2fdac0139ae04e3bd08dbe73a1554
treeac33740df96fb028f1b174a9af285c9547b9b350
parentf19583868408a9a6b5cc46f56eeea3829a83dc9a
net/mlx4_en: fix potential use-after-free with dma_unmap_page

[ Not relevant upstream, therefore no upstream commit. ]

To fix, unmap the page as soon as possible.

When swiotlb is in use, calling dma_unmap_page means that
the original page mapped with dma_map_page must still be valid,
as swiotlb will copy data from its internal cache back to the
originally requested DMA location.

When GRO is enabled, before this patch all references to the
original frag may be put and the page freed before dma_unmap_page
in mlx4_en_free_frag is called.

It is possible there is a path where the use-after-free occurs
even with GRO disabled, but this has not been observed so far.

The bug can be trivially detected by doing the following:

* Compile the kernel with DEBUG_PAGEALLOC
* Run the kernel as a Xen Dom0
* Leave GRO enabled on the interface
* Run a 10 second or more test with iperf over the interface.

This bug was likely introduced in
commit 4cce66cdd14a ("mlx4_en: map entire pages to increase throughput"),
first part of u3.6.

It was incidentally fixed in
commit 34db548bfb95 ("mlx4: add page recycling in receive path"),
first part of v4.12.

This version applies to the v4.9 series.

Signed-off-by: Sarah Newman <srn@prgmr.com>
Tested-by: Sarah Newman <srn@prgmr.com>
Cc: Tariq Toukan <tariqt@mellanox.com>
Cc: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 5d70bd5c98d0e655bde2aae2b5251bdd44df5e71)

Orabug: 28376051

Signed-off-by: Jacob Wen <jian.w.wen@oracle.com>
Reviewed-by: HÃ¥kon Bugge <haakon.bugge@oracle.com>
Signed-off-by: Brian Maly <brian.maly@oracle.com>
Conflicts:
drivers/net/ethernet/mellanox/mlx4/en_rx.c
[ Lack of frag_info->dma_dir ]

Signed-off-by: Brian Maly <brian.maly@oracle.com>
drivers/net/ethernet/mellanox/mlx4/en_rx.c