service: Both Cancel and Stop Online Checks where Appropriate
cover service: Both Cancel and Stop Online Checks where Appropriate
This both cancels, via 'cancel_online_check', and stops, via '__connman_wispr_stop' online checks on service disconnect or free. The former terminates any in-flight or recurring check activity in "service.c" and the latter terminates the same in "wispr.c".
Failure to cancel as well as stop can lead to a use-after-free fault in one-shot or continuous online check mode when a latent online check reschedule timer fires after the service has been disconnected or deallocated.
To support these cancelations with a single 'cancel_online_check' function call, support is added for passing 'CONNMAN_IPCONFIG_TYPE_ALL' to 'cancel_online_check' as the IP configuration type parameter.
Grant Erickson (2):
service: Add support for 'CONNMAN_IPCONFIG_TYPE_ALL' to
'cancel_online_check'.
service: Both cancel and stop online checks where appropriate.
src/service.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-)
Signature · 1 line
2.42.0
PATCH 1/2 service: Add support for 'CONNMAN_IPCONFIG_TYPE_ALL' to 'cancel_online_check'.
This adds support for passing 'CONNMAN_IPCONFIG_TYPE_ALL' to 'cancel_online_check' as the IP configuration type parameter to allow for canceling both IPv4 and IPv6 checks in a single function call.
--- src/service.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-)
src/service.c +28 -10
@@ -1615,6 +1615,8 @@ static guint online_check_timeout_compute_geometric(unsigned int interval)static void cancel_online_check (struct connman_service *service,enum connman_ipconfig_type type) { +bool do_ipv4 = false, do_ipv6 = false; + DBG("service %p (%s) type %d (%s) " "online_timeout_ipv4 %d online_timeout_ipv6 %d", service, connman_service_get_identifier(service),
@@ -1622,20 +1624,34 @@ static void cancel_online_check(struct connman_service *service, service->online_check_state_ipv4.timeout, service->online_check_state_ipv6.timeout); +if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 ) + do_ipv4 = true; +else if (type ==CONNMAN_IPCONFIG_TYPE_IPV6 ) + do_ipv6 = true; +else if (type ==CONNMAN_IPCONFIG_TYPE_ALL ) + do_ipv4 = do_ipv6 = true; +else +return ; +/* -* First, ensure that the reachability check is cancelled in the -* WISPr module. This may fail, however, we ignore any such -* failures as we still want to cancel any outstanding check from -* this module as well. +* First, ensure that the reachability check(s) is/are cancelled +* in the WISPr module. This may fail, however, we ignore any such +* failures as we still want to cancel any outstanding check(s) +* from this module as well. */ -__connman_wispr_cancel (service, type); + +if (do_ipv4) +__connman_wispr_cancel (service,CONNMAN_IPCONFIG_TYPE_IPV4 ); + +if (do_ipv6) +__connman_wispr_cancel (service,CONNMAN_IPCONFIG_TYPE_IPV6 );/* -* Now that the reachability check has been cancelled in the WISPr -* module, cancel any outstanding check that may be scheduled in -* this module. +* Now that the reachability check(s) has/have been cancelled in +* the WISPr module, cancel any outstanding check(s) that may be +* scheduled in this module. */ -if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 && +if (do_ipv4 && service->online_check_state_ipv4.timeout) {g_source_remove (service->online_check_state_ipv4.timeout); service->online_check_state_ipv4.timeout =0 ;
@@ -1646,7 +1662,9 @@ static void cancel_online_check(struct connman_service *service,* now-cancelled scheduled online check. */ connman_service_unref (service); - }else if (type ==CONNMAN_IPCONFIG_TYPE_IPV6 && + } + +if (do_ipv6 && service->online_check_state_ipv6.timeout) {g_source_remove (service->online_check_state_ipv6.timeout); service->online_check_state_ipv6.timeout =0 ;
Signature · 1 line
2.42.0
PATCH 2/2 service: Both cancel and stop online checks where appropriate.
In reply to Grant EricksonThis both cancels, via 'cancel_online_check', and stops, via '__connman_wispr_stop' online checks on service disconnect or free. The former terminates any in-flight or recurring check activity in service.c and the latter terminates the same in wispr.c.
Failure to cancel as well as stop can lead to a use-after-free fault in one-shot or continuous online check mode when a latent online check reschedule timer fires after the service has been disconnected or deallocated.
--- src/service.c | 5 +++++ 1 file changed, 5 insertions(+)
src/service.c +5 -0
@@ -6014,7 +6014,10 @@ static void service_free(gpointer user_data)__connman_notifier_service_remove (service);service_schedule_removed (service); +cancel_online_check (service,CONNMAN_IPCONFIG_TYPE_ALL ); +__connman_wispr_stop (service); +stats_stop (service); service->path =NULL ;
@@ -7193,6 +7196,8 @@ static int service_indicate_state(struct connman_service *service)default_changed (); +cancel_online_check (service,CONNMAN_IPCONFIG_TYPE_ALL ); +__connman_wispr_stop (service);__connman_wpad_stop (service);
Signature · 1 line
2.42.0
Hi Grant,
Quoted 15 lines
This both cancels, via '
cancel_online_check', and stops, via '__connman_wispr_stop' online checks on service disconnect or free. The former terminates any in-flight or recurring check activity in "service.c" and the latter terminates the same in "wispr.c".Failure to cancel as well as stop can lead to a use-after-free fault in one-shot or continuous online check mode when a latent online check reschedule timer fires after the service has been disconnected or deallocated.
To support these cancelations with a single '
cancel_online_check' function call, support is added for passing 'CONNMAN_IPCONFIG_TYPE_ALL' to 'cancel_online_check' as the IP configuration type parameter.
Quoted 7 lines
Grant Erickson (2):
service: Add support for 'CONNMAN_IPCONFIG_TYPE_ALL' to
'cancel_online_check'.
service: Both cancel and stop online checks where appropriate.
src/service.c| 43 +++++++++++++++++++++++++++++++++----------1 file changed, 33 insertions(+), 10 deletions(-)
both patches have been applied.
Regards
Marcel