From: Desmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
To: Emil Velikov <emil.l.velikov@gmail.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
Dave Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Linux-Kernel@Vger. Kernel. Org" <linux-kernel@vger.kernel.org>,
ML dri-devel <dri-devel@lists.freedesktop.org>,
Daniel Vetter <daniel.vetter@ffwll.ch>,
skhan@linuxfoundation.org,
linux-kernel-mentees@lists.linuxfoundation.org
Subject: Re: [PATCH 2/2] drm: Protect drm_master pointers in drm_lease.c
Date: Tue, 15 Jun 2021 10:15:29 +0800 [thread overview]
Message-ID: <7bd0d514-efc6-8118-0b28-dfa0bcf5d842@gmail.com> (raw)
In-Reply-To: <CACvgo51r3NK_ddQPPD9vBzkJq7A4CcYS4nawxZqqDB8FXK5gcA@mail.gmail.com>
On 15/6/21 3:41 am, Emil Velikov wrote:
> On Sat, 12 Jun 2021 at 13:55, Desmond Cheong Zhi Xi
> <desmondcheongzx@gmail.com> wrote:
>>
>> This patch ensures that the device's master mutex is acquired before
>> accessing pointers to struct drm_master that are subsequently
>> dereferenced. Without the mutex, the struct drm_master may be freed
>> concurrently by another process calling drm_setmaster_ioctl(). This
>> could then lead to use-after-free errors.
>>
>> Reported-by: Daniel Vetter <daniel.vetter@ffwll.ch>
>> Signed-off-by: Desmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
>> ---
>
> <snip>
>
>> @@ -578,6 +594,7 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
>> /* Hook up the fd */
>> fd_install(fd, lessee_file);
>>
>> + mutex_unlock(&dev->master_mutex);
>
> I was going to suggest pushing the unlock call further up - after the
> drm_lease_create call. Although that would make the error path rather
> messy, so let's keep it as-is.
>
> <snip>
>
>> @@ -662,7 +684,7 @@ int drm_mode_get_lease_ioctl(struct drm_device *dev,
>> struct drm_mode_get_lease *arg = data;
>> __u32 __user *object_ids = (__u32 __user *) (uintptr_t) (arg->objects_ptr);
>> __u32 count_objects = arg->count_objects;
>> - struct drm_master *lessee = lessee_priv->master;
>> + struct drm_master *lessee;
>> struct idr *object_idr;
>> int count;
>> void *entry;
>> @@ -678,8 +700,10 @@ int drm_mode_get_lease_ioctl(struct drm_device *dev,
>>
>> DRM_DEBUG_LEASE("get lease for %d\n", lessee->lessee_id);
>>
>> + mutex_lock(&dev->master_mutex);
>
> As-is we're dereferencing an uninitialised pointer in DRM_DEBUG_LEASE.
> Move the lock and assignment before the DRM_DEBUG_LEASE, just like
> you've done in the list ioctl.
>
> With this fix, the patch is;
> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
>
> -Emil
>
Good catch, thanks for the feedback Emil. I'll fix this up in a v2 patchset.
Best wishes,
Desmond
prev parent reply other threads:[~2021-06-15 2:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-12 12:54 [PATCH 0/2] drm: Address potential UAF bugs with drm_master ptrs Desmond Cheong Zhi Xi
2021-06-12 12:54 ` [PATCH 1/2] drm: Add a locked version of drm_is_current_master Desmond Cheong Zhi Xi
2021-06-14 19:09 ` Emil Velikov
2021-06-12 12:54 ` [PATCH 2/2] drm: Protect drm_master pointers in drm_lease.c Desmond Cheong Zhi Xi
2021-06-14 19:41 ` Emil Velikov
2021-06-15 2:15 ` Desmond Cheong Zhi Xi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7bd0d514-efc6-8118-0b28-dfa0bcf5d842@gmail.com \
--to=desmondcheongzx@gmail.com \
--cc=airlied@linux.ie \
--cc=daniel.vetter@ffwll.ch \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=emil.l.velikov@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®