• Jeremy Cline's avatar
    drm/nouveau: clean up all clients on device removal · f55aaf63
    Jeremy Cline authored
    The postclose handler can run after the device has been removed (or the
    driver has been unbound) since userspace clients are free to hold the
    file open as long as they want. Because the device removal callback
    frees the entire nouveau_drm structure, any reference to it in the
    postclose handler will result in a use-after-free.
    
    To reproduce this, one must simply open the device file, unbind the
    driver (or physically remove the device), and then close the device
    file. This was found and can be reproduced easily with the IGT
    core_hotunplug tests.
    
    To avoid this, all clients are cleaned up in the device finalization
    rather than deferring it to the postclose handler, and the postclose
    handler is protected by a critical section which ensures the
    drm_dev_unplug() and the postclose handler won't race.
    
    This is not an ideal fix, since as I understand the proposed plan for
    the kernel<->userspace interface for hotplug support, destroying the
    client before the file is closed will cause problems. However, I believe
    to properly fix this issue, the lifetime of the nouveau_drm structure
    needs to be extended to match the drm_device, and this proved to be a
    rather invasive change. Thus, I've broken this out so the fix can be
    easily backported.
    
    This fixes with the two previous commits CVE-2020-27820 (Karol).
    
    Cc: stable@vger.kernel.org # 5.4+
    Signed-off-by: default avatarJeremy Cline <jcline@redhat.com>
    Reviewed-by: default avatarLyude Paul <lyude@redhat.com>
    Reviewed-by: default avatarBen Skeggs <bskeggs@redhat.com>
    Tested-by: default avatarKarol Herbst <kherbst@redhat.com>
    Signed-off-by: default avatarKarol Herbst <kherbst@redhat.com>
    Link: https://patchwork.freedesktop.org/patch/msgid/20201125202648.5220-4-jcline@redhat.com
    Link: https://gitlab.freedesktop.org/drm/nouveau/-/merge_requests/14
    f55aaf63
nouveau_drm.c 35.6 KB