Skip to content

Commit

Permalink
[storage] Ignore inotify if service is already removed. Fixes JB#53294
Browse files Browse the repository at this point in the history
Ignore inotify for a service that has been already removed. This may
happen in cases when the service is removed normally using storage.c
functionality but inotify still gets the notify about the removal of a
dir as it is triggered by the actual removal.

With this change the processing of the event is simply stopped if it
does not exist anymore. Otherwise it would result in double freeing of
the service causing connmand later on to segfault with:

Thread 1 "connmand" received signal SIGSEGV, Segmentation fault.
0x0007fb64 in __connman_access_service_policy_check (p=0xf7ac60, method=CONNMAN_ACCESS_SERVICE_GET_PROPERTY, arg=0x9c2a0 "Passphrase", sender=0x0,
    default_access=CONNMAN_ACCESS_DENY) at src/access.c:250
250		if (p && p->driver->service_policy_check)
(gdb) bt
0  0x0007fb64 in __connman_access_service_policy_check (p=0xf7ac60, method=CONNMAN_ACCESS_SERVICE_GET_PROPERTY, arg=0x9c2a0 "Passphrase", sender=0x0,
    default_access=CONNMAN_ACCESS_DENY) at src/access.c:250
1  0x00047552 in can_get_property (service=0xf05f30, default_access=<optimized out>, sender=0x0, name=<optimized out>) at src/service.c:3101
2  restricted_string_changed (service=service@entry=0xf05f30, name=<optimized out>, value=value@entry=0x0, default_get_access=<optimized out>) at src/service.c:3142
3  0x0004fbd2 in __connman_service_remove (service=0xf05f30) at src/service.c:5918
4  0x000507cc in __connman_service_unload_services (services=<optimized out>, len=1) at src/service.c:9609
5  0x00064ad8 in storage_inotify_cb (event=0xffaebc74, ident=<optimized out>, user_data=<optimized out>) at src/storage.c:528
6  0x000793f0 in inotify_data (channel=<optimized out>, user_data=<optimized out>, cond=<optimized out>) at src/inotify.c:140
7  0xeb9da982 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
8  0xeb9dabf0 in ?? () from /usr/lib/libglib-2.0.so.0
9  0xeb9dae34 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
10 0x00023982 in main (argc=<optimized out>, argv=<optimized out>) at src/main.c:994
  • Loading branch information
LaakkonenJussi committed Mar 11, 2021
1 parent 9f0799a commit fabe37b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions connman/src/storage.c
Expand Up @@ -502,6 +502,15 @@ static void storage_inotify_cb(struct inotify_event *event, const char *ident,

DBG("delete/move-from %s", event->name);

if (is_user_dir(event->name))
subdirs = storage.user_subdirs;
else
subdirs = storage.subdirs;

pos = g_list_find_custom(subdirs, &key, storage_subdir_cmp);
if (!pos)
return;

/*
* To support manual removal of services as well call the
* unload callback to propagate the notify about the removal
Expand Down Expand Up @@ -529,23 +538,15 @@ static void storage_inotify_cb(struct inotify_event *event, const char *ident,
storage.only_unload = unload_state;
}

if (is_user_dir(event->name))
subdirs = storage.user_subdirs;
else
subdirs = storage.subdirs;

/*
* If the service was manually removed it is removed also from
* subdirs when the unload callback reaches back to service/
* provider removal in unload only mode. But in case it was
* removed using internal functionality it must be removed from
* the subdirs here.
*/
pos = g_list_find_custom(subdirs, &key, storage_subdir_cmp);
if (pos) {
storage_subdir_unregister(pos->data);
debug_subdirs();
}
storage_subdir_unregister(pos->data);
debug_subdirs();

return;
}
Expand Down

0 comments on commit fabe37b

Please sign in to comment.