[ovs-dev] dpif-netdev: Fix a zero-rate bug for meter

Message ID 7ca4f1c0c058403789d1f16ed1f40695@MX2.argela.com.tr
State New
Headers show
Series
  • [ovs-dev] dpif-netdev: Fix a zero-rate bug for meter
Related show

Commit Message

Ali Volkan Atli Sept. 27, 2017, 4:23 p.m.
From 23bc166eecd6e4db7b55720cdd780012df62a0cc Mon Sep 17 00:00:00 2001
From: Ali Volkan ATLI <volkan.atli@argela.com.tr>
Date: Wed, 27 Sep 2017 18:33:57 +0300
Subject: [PATCH] dpif-netdev: Fix a zero-rate bug for meter

Open vSwitch daemon crashes (by receiving signal SIGFPE,
Arithmetic exception) when a controller tries to send
a meter-mod message with zero rate.

Signed-off-by: Ali Volkan ATLI <volkan.atli@argela.com.tr>
---
 lib/dpif-netdev.c      | 8 ++++++++
 ofproto/ofproto-dpif.c | 2 ++
 2 files changed, 10 insertions(+)

Comments

Andy Zhou Sept. 27, 2017, 5:48 p.m. | #1
On Wed, Sep 27, 2017 at 9:23 AM, Ali Volkan Atli
<Volkan.Atli@argela.com.tr> wrote:
> From 23bc166eecd6e4db7b55720cdd780012df62a0cc Mon Sep 17 00:00:00 2001
> From: Ali Volkan ATLI <volkan.atli@argela.com.tr>
> Date: Wed, 27 Sep 2017 18:33:57 +0300
> Subject: [PATCH] dpif-netdev: Fix a zero-rate bug for meter
>
> Open vSwitch daemon crashes (by receiving signal SIGFPE,
> Arithmetic exception) when a controller tries to send
> a meter-mod message with zero rate.
>
> Signed-off-by: Ali Volkan ATLI <volkan.atli@argela.com.tr>

Thanks for the fix! Pushed to master with some minor style
adjustments.  Also back ported to branch 2.8.

Patch

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index cb6cf06..ab52809 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -4276,10 +4276,18 @@  dpif_netdev_meter_set(struct dpif *dpif, ofproto_meter_id *meter_id,
         !(config->flags & (OFPMF13_KBPS | OFPMF13_PKTPS))) {
         return EBADF; /* Unsupported flags set */
     }
+
     /* Validate bands */
     if (config->n_bands == 0 || config->n_bands > MAX_BANDS) {
         return EINVAL; /* Too many bands */
     }
+
+    /* Validate rates */
+    for (i = 0; i < config->n_bands; ++i) {
+        if (config->bands[i].rate == 0)
+            return EBADRQC; /* rate must be non-zero */
+    }
+
     for (i = 0; i < config->n_bands; ++i) {
         switch (config->bands[i].type) {
         case OFPMBT13_DROP:
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 1a8e829..d99dc9d 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -5695,6 +5695,8 @@  meter_set(struct ofproto *ofproto_, ofproto_meter_id *meter_id,
         return OFPERR_OFPMMFC_OUT_OF_BANDS;
     case ENODEV: /* Unsupported band type */
         return OFPERR_OFPMMFC_BAD_BAND;
+    case EBADRQC: /* Rate must be non-zero */
+        return OFPERR_OFPMMFC_BAD_RATE;
     default:
         return OFPERR_OFPMMFC_UNKNOWN;
     }