Skip to content

Commit 914aca7

Browse files
rjarrychristophefontaine
authored andcommitted
infra: fix mbuf leak when control input ring is full
post_to_stack() can fail if the control input ring is full. In several places, the return value was ignored causing mbufs to leak silently. Add __rte_warn_unused_result to post_to_stack() to catch future occurrences at compile time. Check the return value at all call sites and free the mbuf on error. Signed-off-by: Robin Jarry <rjarry@redhat.com> Reviewed-by: Christophe Fontaine <cfontain@redhat.com>
1 parent 86636b4 commit 914aca7

File tree

6 files changed

+25
-6
lines changed

6 files changed

+25
-6
lines changed

modules/infra/control/ctlplane.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,18 @@ static void iface_cp_poll(evutil_socket_t, short reason, void *ev_iface) {
209209

210210
mbuf_data(mbuf)->iface = iface;
211211

212+
if (post_to_stack(iface_output, mbuf) < 0) {
213+
LOG(ERR, "post_to_stack: %s", strerror(errno));
214+
goto err;
215+
}
216+
212217
stats = iface_get_stats(rte_lcore_id(), iface->id);
213218
stats->cp_rx_packets += 1;
214219
stats->cp_rx_bytes += rte_pktmbuf_pkt_len(mbuf);
215220

216221
if (gr_config.log_packets)
217222
trace_log_packet(mbuf, "cp rx", iface->name);
218223

219-
post_to_stack(iface_output, mbuf);
220224
return;
221225

222226
err:

modules/infra/control/loopback.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,15 @@ static void iface_loopback_poll(evutil_socket_t, short reason, void *ev_iface) {
161161
e->iface = iface;
162162
e->domain = ETH_DOMAIN_LOOPBACK;
163163

164+
if (post_to_stack(loopback_get_control_id(), mbuf) < 0) {
165+
LOG(ERR, "post_to_stack: %s", strerror(errno));
166+
goto err;
167+
}
168+
164169
stats = iface_get_stats(rte_lcore_id(), iface->id);
165170
stats->cp_rx_packets += 1;
166171
stats->cp_rx_bytes += rte_pktmbuf_pkt_len(mbuf);
167172

168-
post_to_stack(loopback_get_control_id(), mbuf);
169173
return;
170174

171175
err:

modules/infra/datapath/gr_control_input.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
#include <gr_mbuf.h>
77

8+
#include <rte_common.h>
9+
810
GR_MBUF_PRIV_DATA_TYPE(control_input_mbuf_data, { void *data; });
911

1012
typedef uint8_t control_input_t;
1113

1214
control_input_t gr_control_input_register_handler(const char *node_name, bool data_is_mbuf);
1315

14-
int post_to_stack(control_input_t type, void *data);
16+
__rte_warn_unused_result int post_to_stack(control_input_t type, void *data);

modules/ip/control/nexthop.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ void arp_probe_input_cb(void *obj, uintptr_t, const struct control_queue_drain *
206206
o = ip_output_mbuf_data(held);
207207
o->nh = nh;
208208
o->iface = NULL;
209-
post_to_stack(ip_output_node, held);
209+
if (post_to_stack(ip_output_node, held) < 0) {
210+
LOG(ERR, "post_to_stack: %s", strerror(errno));
211+
rte_pktmbuf_free(held);
212+
}
210213
held = next;
211214
}
212215
l3->held_pkts_head = NULL;

modules/ip6/control/nexthop.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,10 @@ void ndp_probe_input_cb(void *obj, uintptr_t, const struct control_queue_drain *
249249
o = ip6_output_mbuf_data(held);
250250
o->nh = nh;
251251
o->iface = NULL;
252-
post_to_stack(ip6_output_node, held);
252+
if (post_to_stack(ip6_output_node, held) < 0) {
253+
LOG(ERR, "post_to_stack: %s", strerror(errno));
254+
rte_pktmbuf_free(held);
255+
}
253256
held = next;
254257
}
255258
l3->held_pkts_head = NULL;

modules/ip6/control/router_advert.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ static void send_ra_cb(evutil_socket_t, short /*what*/, void *priv) {
180180
}
181181
mbuf_data(m)->iface = iface;
182182
build_ra_packet(m, &l3->ipv6);
183-
post_to_stack(ra_output, m);
183+
if (post_to_stack(ra_output, m) < 0) {
184+
rte_pktmbuf_free(m);
185+
LOG(ERR, "post_to_stack: %s", strerror(errno));
186+
}
184187
}
185188
}
186189

0 commit comments

Comments
 (0)