NetworkManager/clients/cli
Beniamino Galvani cf1126f60b cli: avoid crash on device disconnect
When nm_device_disconnect_async() returns, the device could be still
in DEACTIVATING state, and so we also register to device-state signal
notifications to know when the device state goes to DISCONNECTED.

Sometimes it happens that the device state goes to DISCONNECTED before
nm_device_disconnect_async() returns. In this case the signal handler
exits the main loop and then the callback for disconnect_async() is
executed anyway because it was already dispatched, leading to an
invalid memory access.

To avoid this we should cancel nm_device_disconnect_async() when we
are quitting the main loop.

Reproducer:
  nmcli connection add type team ifname t1 con-name t1
  nmcli connection up t1
  nmcli device disconnect t1 & nmcli device delete t1

Crash example:
 ==14955==ERROR: AddressSanitizer: SEGV on unknown address 0xffffffff0000000b (pc 0x7f128c8ba3dd bp 0x0000004be080 sp 0x7ffcda7dc6e0 T0)
 ==14955==The signal is caused by a READ memory access.
    0 0x7f128c8ba3dc in g_string_truncate (/lib64/libglib-2.0.so.0+0x713dc)
    1 0x7f128c8bb4bb in g_string_printf (/lib64/libglib-2.0.so.0+0x724bb)
    2 0x45bdfa in disconnect_device_cb clients/cli/devices.c:2321
    3 0x7f128ca3d1a9 in g_simple_async_result_complete /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gsimpleasyncresult.c:802
    4 0x7f128cf85d0e in device_disconnect_cb libnm/nm-device.c:2354
    5 0x7f128ca4ff73 in g_task_return_now /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1148
    6 0x7f128ca508d5 in g_task_return /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1206
    7 0x7f128ca8ecfc in reply_cb /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gdbusproxy.c:2586
    8 0x7f128ca4ff73 in g_task_return_now /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1148
    9 0x7f128ca508d5 in g_task_return /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1206
    10 0x7f128ca83440 in g_dbus_connection_call_done /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gdbusconnection.c:5713
    11 0x7f128ca4ff73 in g_task_return_now /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1148
    12 0x7f128ca4ffac in complete_in_idle_cb /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1162
    13 0x7f128c893b7a in g_idle_dispatch gmain.c:5620
    14 0x7f128c89726c in g_main_dispatch gmain.c:3182
    15 0x7f128c897637 in g_main_context_iterate gmain.c:3920
    16 0x7f128c897961 in g_main_loop_run (/lib64/libglib-2.0.so.0+0x4e961)
    17 0x473afb in main clients/cli/nmcli.c:1067
    18 0x7f128c6a1412 in __libc_start_main (/lib64/libc.so.6+0x24412)
    19 0x416c39 in _start (/usr/bin/nmcli+0x416c39)

https://github.com/NetworkManager/NetworkManager/pull/254
https://bugzilla.redhat.com/show_bug.cgi?id=1546061
2018-11-30 14:15:27 +01:00
..
agent.c cli: don't use global nm_cli in nmc_readline_*() 2018-10-10 09:55:45 +02:00
agent.h cli: add 'nmcli agent' command (bgo #739568) 2014-11-07 11:58:25 +01:00
common.c cli: initialize readline before installing the redisplay handler 2018-10-23 15:42:19 +02:00
common.h cli: don't use global nm_cli in nmc_readline_*() 2018-10-10 09:55:45 +02:00
connections.c cli/connections: improve sort by active connections 2018-11-21 11:46:22 +01:00
connections.h cli/connections: export nmc_active_connection_cmp() 2018-11-21 11:46:21 +01:00
devices.c cli: avoid crash on device disconnect 2018-11-30 14:15:27 +01:00
devices.h cli: rework printing of "wired" and "wifi" device details 2018-07-09 15:43:55 +02:00
general.c all: say Wi-Fi instead of "wifi" or "WiFi" 2018-11-29 17:53:35 +01:00
general.h cli: output a short summary of devices when called without arguments 2016-07-19 14:29:05 +02:00
meson.build build: create "config-extra.h" header instead of passing directory variables via CFLAGS 2018-07-17 17:46:39 +02:00
nmcli-completion cli: make nmcli do its own command completion 2017-02-13 16:32:15 +01:00
nmcli.c cli: display double-dash long options in help 2018-11-05 09:32:20 +01:00
nmcli.h cli: don't use global variable nm_cli in nmc_terminal_spawn_pager() 2018-10-10 09:55:45 +02:00
polkit-agent.c cli: don't use global nm_cli in nmc_readline_*() 2018-10-10 09:55:45 +02:00
polkit-agent.h cli: add 'nmcli agent' command (bgo #739568) 2014-11-07 11:58:25 +01:00
settings.c cli: don't access global nm_cli variable from nmc_setting_set_property() 2018-10-10 09:55:45 +02:00
settings.h cli: don't access global nm_cli variable from nmc_setting_set_property() 2018-10-10 09:55:45 +02:00
utils.c cli: fix memory leaks 2018-11-02 14:56:40 +01:00
utils.h cli: don't use global variable nm_cli in nmc_terminal_spawn_pager() 2018-10-10 09:55:45 +02:00