qubes-linux-kernel/0007-xen-Add-RING_COPY_RESPONSE.patch

59 lines
2.2 KiB
Diff
Raw Normal View History

2019-07-27 21:01:02 +00:00
From 28ff22aa85bfbe4cc535ffbcc4cf45a271e1ff70 Mon Sep 17 00:00:00 2001
2015-12-17 08:24:01 +00:00
From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?=
<marmarek@invisiblethingslab.com>
Date: Tue, 15 Dec 2015 21:35:14 +0100
2018-08-15 12:57:19 +00:00
Subject: [PATCH] xen: Add RING_COPY_RESPONSE()
2015-12-17 08:24:01 +00:00
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Using RING_GET_RESPONSE() on a shared ring is easy to use incorrectly
(i.e., by not considering that the other end may alter the data in the
shared ring while it is being inspected). Safe usage of a response
generally requires taking a local copy.
Provide a RING_COPY_RESPONSE() macro to use instead of
RING_GET_RESPONSE() and an open-coded memcpy(). This takes care of
ensuring that the copy is done correctly regardless of any possible
compiler optimizations.
Use a volatile source to prevent the compiler from reordering or
omitting the copy.
This is part of XSA155.
CC: stable@vger.kernel.org
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
include/xen/interface/io/ring.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/include/xen/interface/io/ring.h b/include/xen/interface/io/ring.h
2018-08-15 12:57:19 +00:00
index 3f40501fc60b..03702f6874df 100644
2015-12-17 08:24:01 +00:00
--- a/include/xen/interface/io/ring.h
+++ b/include/xen/interface/io/ring.h
2018-08-15 12:57:19 +00:00
@@ -201,6 +201,20 @@ struct __name##_back_ring { \
2015-12-17 08:24:01 +00:00
#define RING_GET_RESPONSE(_r, _idx) \
(&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].rsp))
+/*
+ * Get a local copy of a response.
+ *
+ * Use this in preference to RING_GET_RESPONSE() so all processing is
+ * done on a local copy that cannot be modified by the other end.
+ *
+ * Note that https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58145 may cause this
+ * to be ineffective where _rsp is a struct which consists of only bitfields.
+ */
+#define RING_COPY_RESPONSE(_r, _idx, _rsp) do { \
+ /* Use volatile to force the copy into _rsp. */ \
+ *(_rsp) = *(volatile typeof(_rsp))RING_GET_RESPONSE(_r, _idx); \
+} while (0)
+
/* Loop termination condition: Would the specified index overflow the ring? */
#define RING_REQUEST_CONS_OVERFLOW(_r, _cons) \
(((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
--
2019-03-15 21:28:57 +00:00
2.20.1
2015-12-17 08:24:01 +00:00