Skip to content

Commit eb8281a

Browse files
committed
bgpd: fix bgp_pbr_or_filter memory leaks
Note that bgp_pbr_policyroute_add_from_zebra() and bgp_pbr_policyroute_remove_from_zebra() are only called from bgp_pbr_handle_entry(). > ==966967==ERROR: LeakSanitizer: detected memory leaks > > Direct leak of 40 byte(s) in 1 object(s) allocated from: > #0 0x7fd447ab4a57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154 > #1 0x7fd44746f8dd in qcalloc lib/memory.c:105 > #2 0x7fd44744401a in list_new lib/linklist.c:49 > #3 0x560f8c094490 in bgp_pbr_handle_entry bgpd/bgp_pbr.c:2818 > FRRouting#4 0x560f8c095993 in bgp_pbr_update_entry bgpd/bgp_pbr.c:2941 > FRRouting#5 0x560f8c2164f3 in bgp_zebra_announce bgpd/bgp_zebra.c:1618 > FRRouting#6 0x560f8c0bd668 in bgp_process_main_one bgpd/bgp_route.c:3691 > FRRouting#7 0x560f8c0be7fe in process_subq_other_route bgpd/bgp_route.c:3856 > FRRouting#8 0x560f8c0bf280 in process_subq bgpd/bgp_route.c:3955 > FRRouting#9 0x560f8c0bf320 in meta_queue_process bgpd/bgp_route.c:3980 > FRRouting#10 0x7fd44759fdfc in work_queue_run lib/workqueue.c:282 > FRRouting#11 0x7fd4475779b2 in event_call lib/event.c:2011 > FRRouting#12 0x7fd447442ff1 in frr_run lib/libfrr.c:1216 > FRRouting#13 0x560f8bef0a15 in main bgpd/bgp_main.c:545 > FRRouting#14 0x7fd446e29d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 > > Direct leak of 40 byte(s) in 1 object(s) allocated from: > #0 0x7fd447ab4a57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154 > #1 0x7fd44746f8dd in qcalloc lib/memory.c:105 > #2 0x7fd44744401a in list_new lib/linklist.c:49 > #3 0x560f8c09439d in bgp_pbr_handle_entry bgpd/bgp_pbr.c:2812 > FRRouting#4 0x560f8c095993 in bgp_pbr_update_entry bgpd/bgp_pbr.c:2941 > FRRouting#5 0x560f8c2164f3 in bgp_zebra_announce bgpd/bgp_zebra.c:1618 > FRRouting#6 0x560f8c0bd668 in bgp_process_main_one bgpd/bgp_route.c:3691 > FRRouting#7 0x560f8c0be7fe in process_subq_other_route bgpd/bgp_route.c:3856 > FRRouting#8 0x560f8c0bf280 in process_subq bgpd/bgp_route.c:3955 > FRRouting#9 0x560f8c0bf320 in meta_queue_process bgpd/bgp_route.c:3980 > FRRouting#10 0x7fd44759fdfc in work_queue_run lib/workqueue.c:282 > FRRouting#11 0x7fd4475779b2 in event_call lib/event.c:2011 > FRRouting#12 0x7fd447442ff1 in frr_run lib/libfrr.c:1216 > FRRouting#13 0x560f8bef0a15 in main bgpd/bgp_main.c:545 > FRRouting#14 0x7fd446e29d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 > > Direct leak of 4 byte(s) in 1 object(s) allocated from: > #0 0x7fd447ab4a57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154 > #1 0x7fd44746f8dd in qcalloc lib/memory.c:105 > #2 0x560f8c080cec in bgp_pbr_extract_enumerate_unary bgpd/bgp_pbr.c:362 > #3 0x560f8c080f7e in bgp_pbr_extract_enumerate bgpd/bgp_pbr.c:400 > FRRouting#4 0x560f8c094530 in bgp_pbr_handle_entry bgpd/bgp_pbr.c:2819 > FRRouting#5 0x560f8c095993 in bgp_pbr_update_entry bgpd/bgp_pbr.c:2941 > FRRouting#6 0x560f8c2164f3 in bgp_zebra_announce bgpd/bgp_zebra.c:1618 > FRRouting#7 0x560f8c0bd668 in bgp_process_main_one bgpd/bgp_route.c:3691 > FRRouting#8 0x560f8c0be7fe in process_subq_other_route bgpd/bgp_route.c:3856 > FRRouting#9 0x560f8c0bf280 in process_subq bgpd/bgp_route.c:3955 > FRRouting#10 0x560f8c0bf320 in meta_queue_process bgpd/bgp_route.c:3980 > FRRouting#11 0x7fd44759fdfc in work_queue_run lib/workqueue.c:282 > FRRouting#12 0x7fd4475779b2 in event_call lib/event.c:2011 > FRRouting#13 0x7fd447442ff1 in frr_run lib/libfrr.c:1216 > FRRouting#14 0x560f8bef0a15 in main bgpd/bgp_main.c:545 > FRRouting#15 0x7fd446e29d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 > > Direct leak of 4 byte(s) in 1 object(s) allocated from: > #0 0x7fd447ab4a57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154 > #1 0x7fd44746f8dd in qcalloc lib/memory.c:105 > #2 0x560f8c080cec in bgp_pbr_extract_enumerate_unary bgpd/bgp_pbr.c:362 > #3 0x560f8c080f7e in bgp_pbr_extract_enumerate bgpd/bgp_pbr.c:400 > FRRouting#4 0x560f8c09443d in bgp_pbr_handle_entry bgpd/bgp_pbr.c:2813 > FRRouting#5 0x560f8c095993 in bgp_pbr_update_entry bgpd/bgp_pbr.c:2941 > FRRouting#6 0x560f8c2164f3 in bgp_zebra_announce bgpd/bgp_zebra.c:1618 > FRRouting#7 0x560f8c0bd668 in bgp_process_main_one bgpd/bgp_route.c:3691 > FRRouting#8 0x560f8c0be7fe in process_subq_other_route bgpd/bgp_route.c:3856 > FRRouting#9 0x560f8c0bf280 in process_subq bgpd/bgp_route.c:3955 > FRRouting#10 0x560f8c0bf320 in meta_queue_process bgpd/bgp_route.c:3980 > FRRouting#11 0x7fd44759fdfc in work_queue_run lib/workqueue.c:282 > FRRouting#12 0x7fd4475779b2 in event_call lib/event.c:2011 > FRRouting#13 0x7fd447442ff1 in frr_run lib/libfrr.c:1216 > FRRouting#14 0x560f8bef0a15 in main bgpd/bgp_main.c:545 > FRRouting#15 0x7fd446e29d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 Signed-off-by: Louis Scalbert <[email protected]>
1 parent 442d8bc commit eb8281a

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

bgpd/bgp_pbr.c

+30-25
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ static void bgp_pbr_policyroute_add_to_zebra_unit(struct bgp *bgp,
279279

280280
static void bgp_pbr_dump_entry(struct bgp_pbr_filter *bpf, bool add);
281281

282+
static void bgp_pbr_val_mask_free(void *arg)
283+
{
284+
struct bgp_pbr_val_mask *pbr_val_mask = arg;
285+
286+
XFREE(MTYPE_PBR_VALMASK, pbr_val_mask);
287+
}
288+
282289
static bool bgp_pbr_extract_enumerate_unary_opposite(
283290
uint8_t unary_operator,
284291
struct bgp_pbr_val_mask *and_valmask,
@@ -2130,17 +2137,6 @@ static void bgp_pbr_policyroute_remove_from_zebra(
21302137
bgp, path, bpf, bpof, FLOWSPEC_ICMP_TYPE);
21312138
else
21322139
bgp_pbr_policyroute_remove_from_zebra_unit(bgp, path, bpf);
2133-
/* flush bpof */
2134-
if (bpof->tcpflags)
2135-
list_delete_all_node(bpof->tcpflags);
2136-
if (bpof->dscp)
2137-
list_delete_all_node(bpof->dscp);
2138-
if (bpof->flowlabel)
2139-
list_delete_all_node(bpof->flowlabel);
2140-
if (bpof->pkt_len)
2141-
list_delete_all_node(bpof->pkt_len);
2142-
if (bpof->fragment)
2143-
list_delete_all_node(bpof->fragment);
21442140
}
21452141

21462142
static void bgp_pbr_dump_entry(struct bgp_pbr_filter *bpf, bool add)
@@ -2625,19 +2621,6 @@ static void bgp_pbr_policyroute_add_to_zebra(struct bgp *bgp,
26252621
bgp, path, bpf, bpof, nh, rate, FLOWSPEC_ICMP_TYPE);
26262622
else
26272623
bgp_pbr_policyroute_add_to_zebra_unit(bgp, path, bpf, nh, rate);
2628-
/* flush bpof */
2629-
if (bpof->tcpflags)
2630-
list_delete_all_node(bpof->tcpflags);
2631-
if (bpof->dscp)
2632-
list_delete_all_node(bpof->dscp);
2633-
if (bpof->pkt_len)
2634-
list_delete_all_node(bpof->pkt_len);
2635-
if (bpof->fragment)
2636-
list_delete_all_node(bpof->fragment);
2637-
if (bpof->icmp_type)
2638-
list_delete_all_node(bpof->icmp_type);
2639-
if (bpof->icmp_code)
2640-
list_delete_all_node(bpof->icmp_code);
26412624
}
26422625

26432626
static void bgp_pbr_handle_entry(struct bgp *bgp, struct bgp_path_info *path,
@@ -2703,6 +2686,7 @@ static void bgp_pbr_handle_entry(struct bgp *bgp, struct bgp_path_info *path,
27032686
srcp = &range;
27042687
else {
27052688
bpof.icmp_type = list_new();
2689+
bpof.icmp_type->del = bgp_pbr_val_mask_free;
27062690
bgp_pbr_extract_enumerate(api->icmp_type,
27072691
api->match_icmp_type_num,
27082692
OPERATOR_UNARY_OR,
@@ -2718,6 +2702,7 @@ static void bgp_pbr_handle_entry(struct bgp *bgp, struct bgp_path_info *path,
27182702
dstp = &range_icmp_code;
27192703
else {
27202704
bpof.icmp_code = list_new();
2705+
bpof.icmp_code->del = bgp_pbr_val_mask_free;
27212706
bgp_pbr_extract_enumerate(api->icmp_code,
27222707
api->match_icmp_code_num,
27232708
OPERATOR_UNARY_OR,
@@ -2738,6 +2723,7 @@ static void bgp_pbr_handle_entry(struct bgp *bgp, struct bgp_path_info *path,
27382723
FLOWSPEC_TCP_FLAGS);
27392724
} else if (kind_enum == OPERATOR_UNARY_OR) {
27402725
bpof.tcpflags = list_new();
2726+
bpof.tcpflags->del = bgp_pbr_val_mask_free;
27412727
bgp_pbr_extract_enumerate(api->tcpflags,
27422728
api->match_tcpflags_num,
27432729
OPERATOR_UNARY_OR,
@@ -2755,6 +2741,7 @@ static void bgp_pbr_handle_entry(struct bgp *bgp, struct bgp_path_info *path,
27552741
bpf.pkt_len = &pkt_len;
27562742
else {
27572743
bpof.pkt_len = list_new();
2744+
bpof.pkt_len->del = bgp_pbr_val_mask_free;
27582745
bgp_pbr_extract_enumerate(api->packet_length,
27592746
api->match_packet_length_num,
27602747
OPERATOR_UNARY_OR,
@@ -2764,12 +2751,14 @@ static void bgp_pbr_handle_entry(struct bgp *bgp, struct bgp_path_info *path,
27642751
}
27652752
if (api->match_dscp_num >= 1) {
27662753
bpof.dscp = list_new();
2754+
bpof.dscp->del = bgp_pbr_val_mask_free;
27672755
bgp_pbr_extract_enumerate(api->dscp, api->match_dscp_num,
27682756
OPERATOR_UNARY_OR,
27692757
bpof.dscp, FLOWSPEC_DSCP);
27702758
}
27712759
if (api->match_fragment_num) {
27722760
bpof.fragment = list_new();
2761+
bpof.fragment->del = bgp_pbr_val_mask_free;
27732762
bgp_pbr_extract_enumerate(api->fragment,
27742763
api->match_fragment_num,
27752764
OPERATOR_UNARY_OR,
@@ -2785,7 +2774,7 @@ static void bgp_pbr_handle_entry(struct bgp *bgp, struct bgp_path_info *path,
27852774
bpf.family = afi2family(api->afi);
27862775
if (!add) {
27872776
bgp_pbr_policyroute_remove_from_zebra(bgp, path, &bpf, &bpof);
2788-
return;
2777+
goto flush_bpof;
27892778
}
27902779
/* no action for add = true */
27912780
for (i = 0; i < api->action_num; i++) {
@@ -2863,6 +2852,22 @@ static void bgp_pbr_handle_entry(struct bgp *bgp, struct bgp_path_info *path,
28632852
if (continue_loop == 0)
28642853
break;
28652854
}
2855+
2856+
flush_bpof:
2857+
if (bpof.tcpflags)
2858+
list_delete(&bpof.tcpflags);
2859+
if (bpof.dscp)
2860+
list_delete(&bpof.dscp);
2861+
if (bpof.flowlabel)
2862+
list_delete(&bpof.flowlabel);
2863+
if (bpof.pkt_len)
2864+
list_delete(&bpof.pkt_len);
2865+
if (bpof.fragment)
2866+
list_delete(&bpof.fragment);
2867+
if (bpof.icmp_type)
2868+
list_delete(&bpof.icmp_type);
2869+
if (bpof.icmp_code)
2870+
list_delete(&bpof.icmp_code);
28662871
}
28672872

28682873
void bgp_pbr_update_entry(struct bgp *bgp, const struct prefix *p,

0 commit comments

Comments
 (0)