fix ebpf.plugin segfault when ebpf_load_program return null pointer (#11203)
wangpei committed
May 29, 2021 at 00:08 UTC
19acfc90667e81a00b54909db594819441a18541
5 files changed
+40
-30
collectors/ebpf.plugin/ebpf_cachestat.c
+8
-6
@@ -80,13 +80,15 @@ static void ebpf_cachestat_cleanup(void *ptr)
80
freez(cachestat_vector);
81
freez(cachestat_hash_values);
82
83
- struct bpf_program *prog;
84
- size_t i = 0 ;
85
- bpf_object__for_each_program(prog, objects) {
86
- bpf_link__destroy(probe_links[i]);
87
- i++;
83
+ if (probe_links) {
84
+ struct bpf_program *prog;
85
+ size_t i = 0 ;
86
+ bpf_object__for_each_program(prog, objects) {
87
+ bpf_link__destroy(probe_links[i]);
88
+ i++;
89
+ }
90
+ bpf_object__close(objects);
91
}
89
- bpf_object__close(objects);
92
}
93
94
/*****************************************************************
collectors/ebpf.plugin/ebpf_dcstat.c
+8
-6
@@ -122,13 +122,15 @@ static void ebpf_dcstat_cleanup(void *ptr)
122
123
ebpf_dcstat_clean_names();
124
125
- struct bpf_program *prog;
126
- size_t i = 0 ;
127
- bpf_object__for_each_program(prog, objects) {
128
- bpf_link__destroy(probe_links[i]);
129
- i++;
125
+ if (probe_links) {
126
+ struct bpf_program *prog;
127
+ size_t i = 0 ;
128
+ bpf_object__for_each_program(prog, objects) {
129
+ bpf_link__destroy(probe_links[i]);
130
+ i++;
131
+ }
132
+ bpf_object__close(objects);
133
}
131
- bpf_object__close(objects);
134
}
135
136
/*****************************************************************
collectors/ebpf.plugin/ebpf_process.c
+8
-6
@@ -934,13 +934,15 @@ static void ebpf_process_cleanup(void *ptr)
934
935
freez(process_data.map_fd);
936
937
- struct bpf_program *prog;
938
- size_t i = 0 ;
939
- bpf_object__for_each_program(prog, objects) {
940
- bpf_link__destroy(probe_links[i]);
941
- i++;
937
+ if (probe_links) {
938
+ struct bpf_program *prog;
939
+ size_t i = 0 ;
940
+ bpf_object__for_each_program(prog, objects) {
941
+ bpf_link__destroy(probe_links[i]);
942
+ i++;
943
+ }
944
+ bpf_object__close(objects);
945
}
943
- bpf_object__close(objects);
946
}
947
948
/*****************************************************************
collectors/ebpf.plugin/ebpf_socket.c
+8
-6
@@ -1889,13 +1889,15 @@ static void ebpf_socket_cleanup(void *ptr)
1889
1890
freez(socket_threads.thread);
1891
1892
- struct bpf_program *prog;
1893
- size_t i = 0 ;
1894
- bpf_object__for_each_program(prog, objects) {
1895
- bpf_link__destroy(probe_links[i]);
1896
- i++;
1892
+ if (probe_links) {
1893
+ struct bpf_program *prog;
1894
+ size_t i = 0 ;
1895
+ bpf_object__for_each_program(prog, objects) {
1896
+ bpf_link__destroy(probe_links[i]);
1897
+ i++;
1898
+ }
1899
+ bpf_object__close(objects);
1900
}
1898
- bpf_object__close(objects);
1901
finalized_threads = 1;
1902
}
1903
collectors/ebpf.plugin/ebpf_swap.c
+8
-6
@@ -73,13 +73,15 @@ static void ebpf_swap_cleanup(void *ptr)
73
74
freez(swap_vector);
75
76
- struct bpf_program *prog;
77
- size_t i = 0 ;
78
- bpf_object__for_each_program(prog, objects) {
79
- bpf_link__destroy(probe_links[i]);
80
- i++;
76
+ if (probe_links) {
77
+ struct bpf_program *prog;
78
+ size_t i = 0 ;
79
+ bpf_object__for_each_program(prog, objects) {
80
+ bpf_link__destroy(probe_links[i]);
81
+ i++;
82
+ }
83
+ bpf_object__close(objects);
84
}
82
- bpf_object__close(objects);
85
}
86
87
/*****************************************************************