openwrt / odhcpd

This repository is a mirror of https://git.openwrt.org/?p=project/odhcpd.git. Pull requests will be accepted which will be merged in odhcpd.git
GNU General Public License v2.0
160 stars 96 forks source link

config: make sure timer is not on the timeouts list before freeing #200

Closed cmonroe closed 8 months ago

cmonroe commented 1 year ago

There is a race condition where odhcpd could either hang indefinitely (consuming 100% CPU on 1 core) or crash; usually triggered by network restart. We tracked it back to the uloop timeouts linked list becoming corrupt.. it seems the ra timer is added to the uloop timer list via netlink callback without checking if the timer is already active for the interface. If this happens the interface can get free'd even though the timer is still in the timer list.

Relevant gdb backtrace from one of the failure conditions: `Program terminated with signal SIGABRT, Aborted.

0 0x0000007f9aa27220 in tv_diff (t1=t1@entry=0x7f9aae1508, t2=t2@entry=0x7ffb63faf8) at /home/mclark/sandbox/master_4_27/polecat/openwrt/build_dir/target-aarch64_cortex-a53_musl/libubox-2022-09-27-ea560134/uloop.c:256

256 (t1->tv_sec - t2->tv_sec) * 1000 +

0 0x0000007f9aa27220 in tv_diff (t1=t1@entry=0x7f9aae1508, t2=t2@entry=0x7ffb63faf8) at /home/mclark/sandbox/master_4_27/polecat/openwrt/build_dir/target-aarch64_cortex-a53_musl/libubox-2022-09-27-ea560134/uloop.c:256

1 0x0000007f9aa27a90 in uloop_process_timeouts (tv=0x7ffb63faf8) at /home/mclark/sandbox/master_4_27/polecat/openwrt/build_dir/target-aarch64_cortex-a53_musl/libubox-2022-09-27-ea560134/uloop.c:521

2 uloop_run_timeout (timeout=timeout@entry=-1) at /home/mclark/sandbox/master_4_27/polecat/openwrt/build_dir/target-aarch64_cortex-a53_musl/libubox-2022-09-27-ea560134/uloop.c:563

3 0x0000005593e577f8 in uloop_run () at /home/mclark/sandbox/master_4_27/polecat/openwrt/staging_dir/target-aarch64_cortex-a53_musl/usr/include/libubox/uloop.h:112

4 0x0000005593e54088 in main (argc=, argv=) at /home/mclark/sandbox/master_4_27/polecat/openwrt/build_dir/target-aarch64_cortex-a53_musl/odhcpd-ipv6only/odhcpd-2023-04-05-40ab806b/src/odhcpd.c:133 `

bl4kraven commented 9 months ago

I had the same problem with Openwrt SNAPSHOT, r24096-9536446965. If I restart network using /etc/config/network restart,the odhcpd consuming 100% CPU.

So can someone review this patch?

ldir-EDB0 commented 8 months ago

Thanks for your contribution, have merged :-)