• Gui-Dong Han's avatar
    Bluetooth: Fix atomicity violation in {min,max}_key_size_set · da9065ca
    Gui-Dong Han authored
    In min_key_size_set():
        if (val > hdev->le_max_key_size || val < SMP_MIN_ENC_KEY_SIZE)
            return -EINVAL;
        hci_dev_lock(hdev);
        hdev->le_min_key_size = val;
        hci_dev_unlock(hdev);
    
    In max_key_size_set():
        if (val > SMP_MAX_ENC_KEY_SIZE || val < hdev->le_min_key_size)
            return -EINVAL;
        hci_dev_lock(hdev);
        hdev->le_max_key_size = val;
        hci_dev_unlock(hdev);
    
    The atomicity violation occurs due to concurrent execution of set_min and
    set_max funcs.Consider a scenario where setmin writes a new, valid 'min'
    value, and concurrently, setmax writes a value that is greater than the
    old 'min' but smaller than the new 'min'. In this case, setmax might check
    against the old 'min' value (before acquiring the lock) but write its
    value after the 'min' has been updated by setmin. This leads to a
    situation where the 'max' value ends up being smaller than the 'min'
    value, which is an inconsistency.
    
    This possible bug is found by...
    da9065ca
hci_debugfs.c 33.1 KB