• Lin Ma's avatar
    net: nfc: Fix use-after-free caused by nfc_llcp_find_local · 6709d4b7
    Lin Ma authored
    This commit fixes several use-after-free that caused by function
    nfc_llcp_find_local(). For example, one UAF can happen when below buggy
    time window occurs.
    
    // nfc_genl_llc_get_params   | // nfc_unregister_device
                                 |
    dev = nfc_get_device(idx);   | device_lock(...)
    if (!dev)                    | dev->shutting_down = true;
        return -ENODEV;          | device_unlock(...);
                                 |
    device_lock(...);            |   // nfc_llcp_unregister_device
                                 |   nfc_llcp_find_local()
    nfc_llcp_find_local(...);    |
                                 |   local_cleanup()
    if (!local) {                |
        rc = -ENODEV;            |     // nfc_llcp_local_put
        goto exit;               |     kref_put(.., local_release)
    }                            |
                                 |       // local_release
                                 |       list_del(&local->list)
      // nfc_genl_send_params    |    ...
    6709d4b7
llcp_sock.c 22.2 KB