From: Desmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
To: maarten.lankhorst@linux.intel.com, mripard@kernel.org,
tzimmermann@suse.de, airlied@linux.ie, sumit.semwal@linaro.org,
christian.koenig@amd.com, jani.nikula@linux.intel.com,
joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com,
chris@chris-wilson.co.uk, ville.syrjala@linux.intel.com,
matthew.auld@intel.com, dan.carpenter@oracle.com,
tvrtko.ursulin@intel.com, matthew.d.roper@intel.com,
lucas.demarchi@intel.com, karthik.b.s@intel.com,
jose.souza@intel.com, manasi.d.navare@intel.com,
airlied@redhat.com, aditya.swarup@intel.com,
andrescj@chromium.org, linux-graphics-maintainer@vmware.com,
zackr@vmware.com, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org,
linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org,
skhan@linuxfoundation.org, gregkh@linuxfoundation.org,
linux-kernel-mentees@lists.linuxfoundation.org
Subject: Re: [PATCH v8 1/7] drm: fix null ptr dereference in drm_master_release
Date: Thu, 26 Aug 2021 19:53:58 +0800 [thread overview]
Message-ID: <05f4d472-7a76-598a-e792-a847a3e8516a@gmail.com> (raw)
In-Reply-To: <YSdkjvWN9RAijZJy@phenom.ffwll.local>
On 26/8/21 5:53 pm, Daniel Vetter wrote:
> On Thu, Aug 26, 2021 at 10:01:16AM +0800, Desmond Cheong Zhi Xi wrote:
>> drm_master_release can be called on a drm_file without a master, which
>> results in a null ptr dereference of file_priv->master->magic_map. The
>> three cases are:
>>
>> 1. Error path in drm_open_helper
>> drm_open():
>> drm_open_helper():
>> drm_master_open():
>> drm_new_set_master(); <--- returns -ENOMEM,
>> drm_file.master not set
>> drm_file_free():
>> drm_master_release(); <--- NULL ptr dereference
>> (file_priv->master->magic_map)
>>
>> 2. Error path in mock_drm_getfile
>> mock_drm_getfile():
>> anon_inode_getfile(); <--- returns error, drm_file.master not set
>> drm_file_free():
>> drm_master_release(); <--- NULL ptr dereference
>> (file_priv->master->magic_map)
>>
>> 3. In drm_client_close, as drm_client_open doesn't set up a master
>>
>> drm_file.master is set up in drm_open_helper through the call to
>> drm_master_open, so we mirror it with a call to drm_master_release in
>> drm_close_helper, and remove drm_master_release from drm_file_free to
>> avoid the null ptr dereference.
>>
>> Signed-off-by: Desmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
>
> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
>
> I guess we should also have a cc: stable on this one? I think this bug
> existed since pretty much forever, but maybe more prominent with the
> drm_client stuff added a while ago.
> -Daniel
>
Thanks for the reviews, Daniel.
Took a closer look. I think if we cc: stable, this fix should accompany
commit 7eeaeb90a6a5 ("drm/file: Don't set master on in-kernel clients")
which moves the drm_master_open out from drm_file_alloc into
drm_open_helper.
>> ---
>> drivers/gpu/drm/drm_file.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
>> index ed25168619fc..90b62f360da1 100644
>> --- a/drivers/gpu/drm/drm_file.c
>> +++ b/drivers/gpu/drm/drm_file.c
>> @@ -282,9 +282,6 @@ void drm_file_free(struct drm_file *file)
>>
>> drm_legacy_ctxbitmap_flush(dev, file);
>>
>> - if (drm_is_primary_client(file))
>> - drm_master_release(file);
>> -
>> if (dev->driver->postclose)
>> dev->driver->postclose(dev, file);
>>
>> @@ -305,6 +302,9 @@ static void drm_close_helper(struct file *filp)
>> list_del(&file_priv->lhead);
>> mutex_unlock(&dev->filelist_mutex);
>>
>> + if (drm_is_primary_client(file_priv))
>> + drm_master_release(file_priv);
>> +
>> drm_file_free(file_priv);
>> }
>>
>> --
>> 2.25.1
>>
>
next prev parent reply other threads:[~2021-08-26 11:54 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-26 2:01 [PATCH v8 0/7] drm: update locking for modesetting Desmond Cheong Zhi Xi
2021-08-26 2:01 ` [PATCH v8 1/7] drm: fix null ptr dereference in drm_master_release Desmond Cheong Zhi Xi
2021-08-26 9:53 ` Daniel Vetter
2021-08-26 11:53 ` Desmond Cheong Zhi Xi [this message]
2021-08-26 12:51 ` [Intel-gfx] " Daniel Vetter
2021-08-26 2:01 ` [PATCH v8 2/7] drm: convert drm_device.master_mutex into a rwsem Desmond Cheong Zhi Xi
2021-08-26 9:55 ` Daniel Vetter
2021-08-26 2:01 ` [PATCH v8 3/7] drm: lock drm_global_mutex earlier in the ioctl handler Desmond Cheong Zhi Xi
2021-08-26 9:58 ` Daniel Vetter
2021-08-30 21:04 ` Desmond Cheong Zhi Xi
2021-08-26 2:01 ` [PATCH v8 4/7] drm: avoid races with modesetting rights Desmond Cheong Zhi Xi
2021-08-26 12:59 ` Daniel Vetter
2021-08-30 21:36 ` Desmond Cheong Zhi Xi
2021-08-26 2:01 ` [PATCH v8 5/7] drm: avoid circular locks in drm_mode_object_find Desmond Cheong Zhi Xi
2021-08-26 13:13 ` Daniel Vetter
2021-08-26 2:01 ` [PATCH v8 6/7] drm: avoid circular locks in drm_lease_held Desmond Cheong Zhi Xi
2021-08-26 2:01 ` [PATCH v8 7/7] drm: remove drm_file.master_lookup_lock Desmond Cheong Zhi Xi
2021-08-26 13:21 ` Daniel Vetter
2021-08-31 6:02 ` Desmond Cheong Zhi Xi
2021-08-31 12:28 ` Daniel Vetter
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=05f4d472-7a76-598a-e792-a847a3e8516a@gmail.com \
--to=desmondcheongzx@gmail.com \
--cc=aditya.swarup@intel.com \
--cc=airlied@linux.ie \
--cc=airlied@redhat.com \
--cc=andrescj@chromium.org \
--cc=chris@chris-wilson.co.uk \
--cc=christian.koenig@amd.com \
--cc=dan.carpenter@oracle.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=jose.souza@intel.com \
--cc=karthik.b.s@intel.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-graphics-maintainer@vmware.com \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=lucas.demarchi@intel.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=manasi.d.navare@intel.com \
--cc=matthew.auld@intel.com \
--cc=matthew.d.roper@intel.com \
--cc=mripard@kernel.org \
--cc=rodrigo.vivi@intel.com \
--cc=skhan@linuxfoundation.org \
--cc=sumit.semwal@linaro.org \
--cc=tvrtko.ursulin@intel.com \
--cc=tzimmermann@suse.de \
--cc=ville.syrjala@linux.intel.com \
--cc=zackr@vmware.com \
/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;
as well as URLs for NNTP newsgroup(s).