Skip to contentSkip to conversation

Macro for checking insance amounts of data on the ring (Xen patch).

PATCH New Konrad Rzeszutek Wilk 3 participants 4 messages Jun 10, 2013 – Jun 11, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Macro for checking insance amounts of data on the ring (Xen patch).

Hey,

This patch had been posted in the past but had a glaring issue that Jan spotted. This version fixes it. Said macro is being used in the xen-blkback to check whether the indexes are bogus and the ring is overflowed.

 xen/include/public/io/ring.h | 6 ++++++
 1 file changed, 6 insertions(+)

Konrad Rzeszutek Wilk (1):
ring/macro: Add a new macro to detect whether there is an overflow in requests and response.

#1 lore raw

PATCH v2 1/1 ring/macro: Add a new macro to detect whether there is an overflow in requests and response.

We want to be able to exit if the difference between the request produced (what the frontend tells us) and the requests consumed (what we have so far processed) is greater than the ring size.

If so, we should terminate the loop as the request produced is not trusted and it means it is bogus.

[v1: Make sure we have both _prod and _cons in the macro, not just _prod)

---
 xen/include/public/io/ring.h | 6 ++++++
 1 file changed, 6 insertions(+)
xen/include/public/io/ring.h +6 -0
index d9884f5..277d296 100644
@@ -234,6 +234,12 @@ typedef struct __name##_back_ring __name##_back_ring_t
 #define RING_REQUEST_CONS_OVERFLOW(_r, _cons)                           \
     (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
 
+/* Loop termination condition: Is the difference between request produced
+ * and request consumed greater than the ring size. If so, terminate the
+ * loop. */
+#define RING_REQUEST_PROD_OVERFLOW(_r, _cons, _prod)                     \
+    (((_prod) - (_cons)) > RING_SIZE(_r))
+
 #define RING_PUSH_REQUESTS(_r) do {                                     \
     xen_wmb(); /* back sees requests /before/ updated producer index */ \
     (_r)->sring->req_prod = (_r)->req_prod_pvt;                         \
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH v3 1/1 io/ring.h: new macro to detect whether there are too many requests on the ring

Backends may need to protect themselves against an insane number of produced requests stored by a frontend, in case they iterate over requests until reaching the req_prod value. There can't be more requests on the ring than the difference between produced requests and produced (but possibly not yet published) responses.

This is a more strict alternative to a patch previously posted by Konrad Rzeszutek Wilk <[email protected]>.

xen/include/public/io/ring.h +4 -0
@@ -234,6 +234,10 @@ typedef struct __name##_back_ring __name
 #define RING_REQUEST_CONS_OVERFLOW(_r, _cons)                           \
     (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
 
+/* Ill-behaved frontend determination: Can there be this many requests? */
+#define RING_REQUEST_PROD_OVERFLOW(_r, _prod)                           \
+    (((_prod) - (_r)->rsp_prod_pvt) > RING_SIZE(_r))
+
 #define RING_PUSH_REQUESTS(_r) do {                                     \
     xen_wmb(); /* back sees requests /before/ updated producer index */ \
     (_r)->sring->req_prod = (_r)->req_prod_pvt;                         \

io/ring.h: new macro to detect whether there are too many requests on the ring

Backends may need to protect themselves against an insane number of produced requests stored by a frontend, in case they iterate over requests until reaching the req_prod value. There can't be more requests on the ring than the difference between produced requests and produced (but possibly not yet published) responses.

This is a more strict alternative to a patch previously posted by Konrad Rzeszutek Wilk <[email protected]>.

xen/include/public/io/ring.h +4 -0
@@ -234,6 +234,10 @@ typedef struct __name##_back_ring __name
 #define RING_REQUEST_CONS_OVERFLOW(_r, _cons)                           \
     (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
 
+/* Ill-behaved frontend determination: Can there be this many requests? */
+#define RING_REQUEST_PROD_OVERFLOW(_r, _prod)                           \
+    (((_prod) - (_r)->rsp_prod_pvt) > RING_SIZE(_r))
+
 #define RING_PUSH_REQUESTS(_r) do {                                     \
     xen_wmb(); /* back sees requests /before/ updated producer index */ \
     (_r)->sring->req_prod = (_r)->req_prod_pvt;                         \

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by on v3 1/1
#3 lore raw

Re: [PATCH v3] io/ring.h: new macro to detect whether there are too many requests on the ring

Quoted 10 lines · Jan Beulich

Backends may need to protect themselves against an insane number of produced requests stored by a frontend, in case they iterate over requests until reaching the req_prod value. There can't be more requests on the ring than the difference between produced requests and produced (but possibly not yet published) responses.

This is a more strict alternative to a patch previously posted by Konrad Rzeszutek Wilk <[email protected]>.

Quoted 20 lines
xen/include/public/io/ring.h +4 -0
@@ -234,6 +234,10 @@ typedef struct __name##_back_ring __name
 #define RING_REQUEST_CONS_OVERFLOW(_r, _cons)                           \
     (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
 
+/* Ill-behaved frontend determination: Can there be this many requests? */
+#define RING_REQUEST_PROD_OVERFLOW(_r, _prod)                           \
+    (((_prod) - (_r)->rsp_prod_pvt) > RING_SIZE(_r))
+
 #define RING_PUSH_REQUESTS(_r) do {                                     \
     xen_wmb(); /* back sees requests /before/ updated producer index */ \
     (_r)->sring->req_prod = (_r)->req_prod_pvt;                         \

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel