diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2021-09-27 03:44:41 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2021-09-27 03:44:41 +0000 |
commit | 6fa706f7525f04bf67cd53ed62612b148b7a3f3b (patch) | |
tree | e52e65b945651596f97efee0a449dca07c677ec2 /sys/dev/pci/drm | |
parent | 05019eacd21630e808524a5fb69d682a089cfa6d (diff) |
drm: protect drm_master pointers in drm_lease.c
From Desmond Cheong Zhi Xi
34609faad0c9f9f08d4b59d25c94b78bf5710d93 in linux 5.10.y/5.10.67
56f0729a510f92151682ff6c89f69724d5595d6e in mainline linux
Diffstat (limited to 'sys/dev/pci/drm')
-rw-r--r-- | sys/dev/pci/drm/drm_auth.c | 25 | ||||
-rw-r--r-- | sys/dev/pci/drm/include/drm/drm_auth.h | 1 | ||||
-rw-r--r-- | sys/dev/pci/drm/include/drm/drm_file.h | 6 |
3 files changed, 32 insertions, 0 deletions
diff --git a/sys/dev/pci/drm/drm_auth.c b/sys/dev/pci/drm/drm_auth.c index a711e05c700..e8ead2bd29a 100644 --- a/sys/dev/pci/drm/drm_auth.c +++ b/sys/dev/pci/drm/drm_auth.c @@ -382,6 +382,31 @@ struct drm_master *drm_master_get(struct drm_master *master) } EXPORT_SYMBOL(drm_master_get); +/** + * drm_file_get_master - reference &drm_file.master of @file_priv + * @file_priv: DRM file private + * + * Increments the reference count of @file_priv's &drm_file.master and returns + * the &drm_file.master. If @file_priv has no &drm_file.master, returns NULL. + * + * Master pointers returned from this function should be unreferenced using + * drm_master_put(). + */ +struct drm_master *drm_file_get_master(struct drm_file *file_priv) +{ + struct drm_master *master = NULL; + + spin_lock(&file_priv->master_lookup_lock); + if (!file_priv->master) + goto unlock; + master = drm_master_get(file_priv->master); + +unlock: + spin_unlock(&file_priv->master_lookup_lock); + return master; +} +EXPORT_SYMBOL(drm_file_get_master); + static void drm_master_destroy(struct kref *kref) { struct drm_master *master = container_of(kref, struct drm_master, refcount); diff --git a/sys/dev/pci/drm/include/drm/drm_auth.h b/sys/dev/pci/drm/include/drm/drm_auth.h index 6bf8b2b7899..f99d3417f30 100644 --- a/sys/dev/pci/drm/include/drm/drm_auth.h +++ b/sys/dev/pci/drm/include/drm/drm_auth.h @@ -107,6 +107,7 @@ struct drm_master { }; struct drm_master *drm_master_get(struct drm_master *master); +struct drm_master *drm_file_get_master(struct drm_file *file_priv); void drm_master_put(struct drm_master **master); bool drm_is_current_master(struct drm_file *fpriv); diff --git a/sys/dev/pci/drm/include/drm/drm_file.h b/sys/dev/pci/drm/include/drm/drm_file.h index 9decb43c711..ac50dd66602 100644 --- a/sys/dev/pci/drm/include/drm/drm_file.h +++ b/sys/dev/pci/drm/include/drm/drm_file.h @@ -237,6 +237,12 @@ struct drm_file { * this only matches &drm_device.master if the master is the currently * active one. * + * When dereferencing this pointer, either hold struct + * &drm_device.master_mutex for the duration of the pointer's use, or + * use drm_file_get_master() if struct &drm_device.master_mutex is not + * currently held and there is no other need to hold it. This prevents + * @master from being freed during use. + * * See also @authentication and @is_master and the :ref:`section on * primary nodes and authentication <drm_primary_node>`. */ |