From: Loke Berne <[email protected]>

ukey_create_from_dpif_flow() fetches the full flow into a fixed-size
OFPBUF_STACK buffer of DPIF_FLOW_BUFSIZE when the dump did not provide
the key or the actions.  The datapath may return more than that, for
instance a tc flow with many tunnel outputs, in which case
ofpbuf_resize__() hits OVS_NOT_REACHED() and ovs-vswitchd aborts.

Use the stack memory as a stub instead, so the buffer can grow onto the
heap.

Fixes: 64bb477f0568 ("dpif: Minimize memory copy for revalidation.")
Assisted-by: Claude Fable 5.1, Claude Code
Signed-off-by: Loke Berne <[email protected]>
---
 ofproto/ofproto-dpif-upcall.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c
index c877a0c24..ba8a9f49b 100644
--- a/ofproto/ofproto-dpif-upcall.c
+++ b/ofproto/ofproto-dpif-upcall.c
@@ -1896,19 +1896,19 @@ ukey_create_from_dpif_flow(const struct udpif *udpif,
     uint64_t stub[DPIF_FLOW_BUFSIZE / 8];
     const struct nlattr *a;
     unsigned int left;
+    struct ofpbuf buf;
+    int err = 0;
 
-    if (!flow->key_len || !flow->actions_len) {
-        struct ofpbuf buf;
-        int err;
+    ofpbuf_use_stub(&buf, &stub, sizeof stub);
 
+    if (!flow->key_len || !flow->actions_len) {
         /* If the key or actions were not provided by the datapath, fetch the
          * full flow. */
-        ofpbuf_use_stack(&buf, &stub, sizeof stub);
         err = dpif_flow_get(udpif->dpif, flow->key, flow->key_len,
                             flow->ufid_present ? &flow->ufid : NULL,
                             flow->pmd_id, &buf, &full_flow);
         if (err) {
-            return err;
+            goto out;
         }
         flow = &full_flow;
     }
@@ -1920,12 +1920,14 @@ ukey_create_from_dpif_flow(const struct udpif *udpif,
     NL_ATTR_FOR_EACH (a, left, flow->key, flow->key_len) {
         if (nl_attr_type(a) == OVS_KEY_ATTR_RECIRC_ID
             && nl_attr_get_u32(a) != 0) {
-            return EINVAL;
+            err = EINVAL;
+            goto out;
         }
     }
     NL_ATTR_FOR_EACH (a, left, flow->actions, flow->actions_len) {
         if (nl_attr_type(a) == OVS_ACTION_ATTR_RECIRC) {
-            return EINVAL;
+            err = EINVAL;
+            goto out;
         }
     }
 
@@ -1936,7 +1938,9 @@ ukey_create_from_dpif_flow(const struct udpif *udpif,
                           &flow->ufid, flow->pmd_id, &actions,
                           reval_seq, flow->stats.used, 0, NULL);
 
-    return 0;
+out:
+    ofpbuf_uninit(&buf);
+    return err;
 }
 
 static bool
-- 
2.56.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to