diff --git a/add-ebpf-collector.patch b/add-ebpf-collector.patch index 2cd5b28..03be83d 100644 --- a/add-ebpf-collector.patch +++ b/add-ebpf-collector.patch @@ -3478,4 +3478,5 @@ index ac35be2..a83bd9b 100644 if not lat_sec and not iodump_sec: return common_param -- -2.33.0 \ No newline at end of file +2.33.0 + diff --git a/ebpf-fix-dead-loop.patch b/ebpf-fix-dead-loop.patch new file mode 100644 index 0000000..e16bde2 --- /dev/null +++ b/ebpf-fix-dead-loop.patch @@ -0,0 +1,111 @@ +From b2881b6f3e441061afba3be5f9802b639fb4dca2 Mon Sep 17 00:00:00 2001 +From: zhangnan +Date: Mon, 14 Oct 2024 12:01:27 +0800 +Subject: [PATCH] ebpf fix dead loop + +--- + src/c/ebpf_collector/ebpf_collector.c | 53 +++++++++++++++++---------- + 1 file changed, 33 insertions(+), 20 deletions(-) + +diff --git a/src/c/ebpf_collector/ebpf_collector.c b/src/c/ebpf_collector/ebpf_collector.c +index 6e981da..0885a5f 100644 +--- a/src/c/ebpf_collector/ebpf_collector.c ++++ b/src/c/ebpf_collector/ebpf_collector.c +@@ -117,41 +117,46 @@ char* find_device_name(dev_t dev) { + return device_name; + } + +-static int print_map_res(struct bpf_map *map_res, struct bpf_map *map_res_2, char *stage, int *map_size) +-{ +- int err; +- struct stage_data counter; ++static void update_io_dump(struct bpf_map *map_res, int *io_dump, int *map_size, char *stage) { + struct time_range_io_count time_count; +- int key = 0; +- int io_dump[MAP_SIZE] = {0}; + u32 io_dump_key = 0, io_dump_next_key = 0; +- + struct sysinfo info; + sysinfo(&info); + +- while (bpf_map_get_next_key(map_res_2, &io_dump_key, &io_dump_next_key) == 0) { +- err = bpf_map_lookup_elem(map_res_2, &io_dump_next_key, &time_count); ++ while (bpf_map_get_next_key(map_res, &io_dump_key, &io_dump_next_key) == 0) { ++ int err = bpf_map_lookup_elem(map_res, &io_dump_next_key, &time_count); + if (err < 0) { + fprintf(stderr, "failed to lookup %s io dump: %d\n", stage, err); +- continue; ++ break; ++ } ++ if (io_dump_key == io_dump_next_key) { ++ break; + } ++ + io_dump_key = io_dump_next_key; +- if ((info.uptime - io_dump_key) > 2) { ++ ++ if ((info.uptime - io_dump_key) >= 2) { + int isempty = 1; +- for (key = 0; key < map_size; key++){ ++ for (int key = 0; key < map_size; key++) { + if (time_count.count[key] > 0) { + io_dump[key] += time_count.count[key]; + isempty = 0; + } + } + if (isempty || (info.uptime - io_dump_key) > IO_DUMP_THRESHOLD) { +- bpf_map_delete_elem(map_res_2, &io_dump_key); ++ bpf_map_delete_elem(map_res, &io_dump_key); + } + } + } ++} ++ ++static int print_map_res(struct bpf_map *map_res, char *stage, int *map_size, int *io_dump) ++{ ++ struct stage_data counter; ++ int key = 0; + + for (key = 0; key < map_size; key++) { +- err = bpf_map_lookup_elem(map_res, &key, &counter); ++ int err = bpf_map_lookup_elem(map_res, &key, &counter); + if (err < 0) { + fprintf(stderr, "failed to lookup %s map_res: %d\n", stage, err); + return -1; +@@ -274,19 +279,27 @@ int main(int argc, char **argv) { + + sleep(1); + +- err = print_map_res(BLK_RES, BLK_RES_2, "rq_driver", device_count); ++ int io_dump_blk[MAP_SIZE] = {0}; ++ update_io_dump(BLK_RES_2, io_dump_blk, device_count,"rq_driver"); ++ err = print_map_res(BLK_RES, "rq_driver", device_count, io_dump_blk); + if (err) + break; + +- err = print_map_res(BIO_RES, BIO_RES_2, "bio", device_count); ++ int io_dump_bio[MAP_SIZE] = {0}; ++ update_io_dump(BIO_RES_2, io_dump_bio, device_count,"bio"); ++ err = print_map_res(BIO_RES, "bio", device_count, io_dump_bio); + if (err) + break; +- +- err = print_map_res(TAG_RES, TAG_RES_2, "gettag", device_count); ++ ++ int io_dump_tag[MAP_SIZE] = {0}; ++ update_io_dump(TAG_RES_2, io_dump_tag, device_count,"gettag"); ++ err = print_map_res(TAG_RES, "gettag", device_count, io_dump_tag); + if (err) + break; +- +- err = print_map_res(WBT_RES, WBT_RES_2, "wbt", device_count); ++ ++ int io_dump_wbt[MAP_SIZE] = {0}; ++ update_io_dump(WBT_RES_2, io_dump_wbt, device_count,"wbt"); ++ err = print_map_res(WBT_RES, "wbt", device_count, io_dump_wbt); + if (err) + break; + +-- +2.33.0 + diff --git a/sysSentry.spec b/sysSentry.spec index 5005ef7..873dfae 100644 --- a/sysSentry.spec +++ b/sysSentry.spec @@ -4,7 +4,7 @@ Summary: System Inspection Framework Name: sysSentry Version: 1.0.2 -Release: 41 +Release: 42 License: Mulan PSL v2 Group: System Environment/Daemons Source0: https://gitee.com/openeuler/sysSentry/releases/download/v%{version}/%{name}-%{version}.tar.gz @@ -57,6 +57,7 @@ Patch44: add-root-cause-analysis.patch Patch45: update-collect-log.patch Patch46: modify-abnormal-stack-when-the-disk-field-is-not-con.patch Patch47: precise-alarm-query-time.patch +Patch48: ebpf-fix-dead-loop.patch BuildRequires: cmake gcc-c++ BuildRequires: python3 python3-setuptools @@ -329,6 +330,12 @@ rm -rf %{buildroot} %attr(0550,root,root) %{python3_sitelib}/sentryCollector/__pycache__/collect_plugin* %changelog +* Mon Oct 14 2024 zhangnan - 1.0.2-42 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:fix dead loop when find next bpf map key + * Mon Oct 14 2024 zhuofeng - 1.0.2-41 - Type:bugfix - CVE:NA @@ -378,7 +385,7 @@ rm -rf %{buildroot} - SUG:NA - DESC:add parameter valication for time_range and alarm_id and alarm_clear_time -* Thu Oct 11 2024 gaoruoshu - 1.0.2-33 +* Fri Oct 11 2024 gaoruoshu - 1.0.2-33 - Type:requirement - CVE:NA - SUG:NA