Skip to content

Commit

Permalink
drm: fix use-after-free read in drm_mode_create_lease_ioctl()
Browse files Browse the repository at this point in the history
fd_install() moves the reference given to it into the file descriptor table
of the current process. If the current process is multithreaded, then
immediately after fd_install(), another thread can close() the file
descriptor and cause the file's resources to be cleaned up.

Since the reference to "lessee" is held by the file, we must not access
"lessee" after the fd_install() call.

As far as I can tell, to reach this codepath, the caller must have an open
file descriptor to a DRI device in master mode. I'm not sure what the
requirements for that are.

Signed-off-by: Jann Horn <jannh@google.com>
Fixes: 62884cd ("drm: Add four ioctls for managing drm mode object leases [v7]")
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20181001153117.216923-1-jannh@google.com
  • Loading branch information
Jann Horn authored and Daniel Vetter committed Oct 2, 2018
1 parent 17b57b1 commit 12d43de
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/gpu/drm/drm_lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,14 +566,14 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
lessee_priv->is_master = 1;
lessee_priv->authenticated = 1;

/* Hook up the fd */
fd_install(fd, lessee_file);

/* Pass fd back to userspace */
DRM_DEBUG_LEASE("Returning fd %d id %d\n", fd, lessee->lessee_id);
cl->fd = fd;
cl->lessee_id = lessee->lessee_id;

/* Hook up the fd */
fd_install(fd, lessee_file);

DRM_DEBUG_LEASE("drm_mode_create_lease_ioctl succeeded\n");
return 0;

Expand Down

0 comments on commit 12d43de

Please sign in to comment.