xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Macro for checking insance amounts of data on the ring (Xen patch).
@ 2013-06-10 16:02 Konrad Rzeszutek Wilk
  2013-06-10 16:02 ` [v2] ring/macro: Add a new macro to detect whether there is an overflow in requests and response Konrad Rzeszutek Wilk
  0 siblings, 1 reply; 4+ messages in thread
From: Konrad Rzeszutek Wilk @ 2013-06-10 16:02 UTC (permalink / raw)
  To: xen-devel

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [v2] ring/macro: Add a new macro to detect whether there is an overflow in requests and response.
  2013-06-10 16:02 [PATCH] Macro for checking insance amounts of data on the ring (Xen patch) Konrad Rzeszutek Wilk
@ 2013-06-10 16:02 ` Konrad Rzeszutek Wilk
  2013-06-11  8:23   ` [PATCH v3] io/ring.h: new macro to detect whether there are too many requests on the ring Jan Beulich
  0 siblings, 1 reply; 4+ messages in thread
From: Konrad Rzeszutek Wilk @ 2013-06-10 16:02 UTC (permalink / raw)
  To: xen-devel; +Cc: Konrad Rzeszutek Wilk

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.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
[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(+)

diff --git a/xen/include/public/io/ring.h b/xen/include/public/io/ring.h
index d9884f5..277d296 100644
--- a/xen/include/public/io/ring.h
+++ b/xen/include/public/io/ring.h
@@ -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;                         \
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v3] io/ring.h: new macro to detect whether there are too many requests on the ring
  2013-06-10 16:02 ` [v2] ring/macro: Add a new macro to detect whether there is an overflow in requests and response Konrad Rzeszutek Wilk
@ 2013-06-11  8:23   ` Jan Beulich
  2013-06-11 10:10     ` Keir Fraser
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Beulich @ 2013-06-11  8:23 UTC (permalink / raw)
  To: xen-devel; +Cc: Konrad Rzeszutek Wilk

[-- Attachment #1: Type: text/plain, Size: 1212 bytes --]

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 <konrad.wilk@oracle.com>.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/include/public/io/ring.h
+++ b/xen/include/public/io/ring.h
@@ -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;                         \




[-- Attachment #2: ring-request-prod-overflow.patch --]
[-- Type: text/plain, Size: 1288 bytes --]

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 <konrad.wilk@oracle.com>.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/include/public/io/ring.h
+++ b/xen/include/public/io/ring.h
@@ -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;                         \

[-- Attachment #3: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] io/ring.h: new macro to detect whether there are too many requests on the ring
  2013-06-11  8:23   ` [PATCH v3] io/ring.h: new macro to detect whether there are too many requests on the ring Jan Beulich
@ 2013-06-11 10:10     ` Keir Fraser
  0 siblings, 0 replies; 4+ messages in thread
From: Keir Fraser @ 2013-06-11 10:10 UTC (permalink / raw)
  To: Jan Beulich, xen-devel; +Cc: Konrad Rzeszutek Wilk

On 11/06/2013 09:23, "Jan Beulich" <JBeulich@suse.com> wrote:

> 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 <konrad.wilk@oracle.com>.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Keir Fraser <keir@xen.org>

> --- a/xen/include/public/io/ring.h
> +++ b/xen/include/public/io/ring.h
> @@ -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
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-06-11 10:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-10 16:02 [PATCH] Macro for checking insance amounts of data on the ring (Xen patch) Konrad Rzeszutek Wilk
2013-06-10 16:02 ` [v2] ring/macro: Add a new macro to detect whether there is an overflow in requests and response Konrad Rzeszutek Wilk
2013-06-11  8:23   ` [PATCH v3] io/ring.h: new macro to detect whether there are too many requests on the ring Jan Beulich
2013-06-11 10:10     ` Keir Fraser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).