]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/3.4.25/virtio-force-vring-descriptors-to-be-allocated-from-lowmem.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.4.25 / virtio-force-vring-descriptors-to-be-allocated-from-lowmem.patch
CommitLineData
a215792c
GKH
1From b92b1b89a33c172c075edccf6afb0edc41d851fd Mon Sep 17 00:00:00 2001
2From: Will Deacon <will.deacon@arm.com>
3Date: Fri, 19 Oct 2012 14:03:33 +0100
4Subject: virtio: force vring descriptors to be allocated from lowmem
5
6From: Will Deacon <will.deacon@arm.com>
7
8commit b92b1b89a33c172c075edccf6afb0edc41d851fd upstream.
9
10Virtio devices may attempt to add descriptors to a virtqueue from atomic
11context using GFP_ATOMIC allocation. This is problematic because such
12allocations can fall outside of the lowmem mapping, causing virt_to_phys
13to report bogus physical addresses which are subsequently passed to
14userspace via the buffers for the virtual device.
15
16This patch masks out __GFP_HIGH and __GFP_HIGHMEM from the requested
17flags when allocating descriptors for a virtqueue. If an atomic
18allocation is requested and later fails, we will return -ENOSPC which
19will be handled by the driver.
20
21Signed-off-by: Will Deacon <will.deacon@arm.com>
22Cc: Sasha Levin <levinsasha928@gmail.com>
23Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
24Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
25
26---
27 drivers/virtio/virtio_ring.c | 7 +++++++
28 1 file changed, 7 insertions(+)
29
30--- a/drivers/virtio/virtio_ring.c
31+++ b/drivers/virtio/virtio_ring.c
32@@ -132,6 +132,13 @@ static int vring_add_indirect(struct vri
33 unsigned head;
34 int i;
35
36+ /*
37+ * We require lowmem mappings for the descriptors because
38+ * otherwise virt_to_phys will give us bogus addresses in the
39+ * virtqueue.
40+ */
41+ gfp &= ~(__GFP_HIGHMEM | __GFP_HIGH);
42+
43 desc = kmalloc((out + in) * sizeof(struct vring_desc), gfp);
44 if (!desc)
45 return -ENOMEM;