• David Disseldorp's avatar
    cifs: fix use-after-free bug in find_writable_file · 16f2a0d5
    David Disseldorp authored
    commit e1e9bda2 upstream.
    
    Under intermittent network outages, find_writable_file() is susceptible
    to the following race condition, which results in a user-after-free in
    the cifs_writepages code-path:
    
    Thread 1                                        Thread 2
    ========                                        ========
    
    inv_file = NULL
    refind = 0
    spin_lock(&cifs_file_list_lock)
    
    // invalidHandle found on openFileList
    
    inv_file = open_file
    // inv_file->count currently 1
    
    cifsFileInfo_get(inv_file)
    // inv_file->count = 2
    
    spin_unlock(&cifs_file_list_lock);
    
    cifs_reopen_file()                            cifs_close()
    // fails (rc != 0)                            ->cifsFileInfo_put()
                                           spin_lock(&cifs_file_list_lock)
                                           // inv_file->count = 1
                                           spin_unlock(&cifs_file_list_lock)
    
    spin_lock(&cifs_file_list_lock);
    list_move_tail...
    16f2a0d5
file.c 76.5 KB