aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hellstrom <thellstrom@vmware.com>2012-01-24 12:54:21 -0500
committerDave Airlie <airlied@redhat.com>2012-01-25 04:27:45 -0500
commit598781d71119827b454fd75d46f84755bca6f0c6 (patch)
tree51ccb65b8e26b3347099af3f466ad0fedc6e1cb6
parent15b63d35261ba3351d07e7937252f18bb6cbf814 (diff)
drm: Fix authentication kernel crash
If the master tries to authenticate a client using drm_authmagic and that client has already closed its drm file descriptor, either wilfully or because it was terminated, the call to drm_authmagic will dereference a stale pointer into kmalloc'ed memory and corrupt it. Typically this results in a hard system hang. This patch fixes that problem by removing any authentication tokens (struct drm_magic_entry) open for a file descriptor when that file descriptor is closed. Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Cc: stable@vger.kernel.org Signed-off-by: Dave Airlie <airlied@redhat.com>
-rw-r--r--drivers/gpu/drm/drm_auth.c6
-rw-r--r--drivers/gpu/drm/drm_fops.c5
-rw-r--r--include/drm/drmP.h1
3 files changed, 11 insertions, 1 deletions
diff --git a/drivers/gpu/drm/drm_auth.c b/drivers/gpu/drm/drm_auth.c
index 3f46772f0cb..ba23790450e 100644
--- a/drivers/gpu/drm/drm_auth.c
+++ b/drivers/gpu/drm/drm_auth.c
@@ -101,7 +101,7 @@ static int drm_add_magic(struct drm_master *master, struct drm_file *priv,
101 * Searches and unlinks the entry in drm_device::magiclist with the magic 101 * Searches and unlinks the entry in drm_device::magiclist with the magic
102 * number hash key, while holding the drm_device::struct_mutex lock. 102 * number hash key, while holding the drm_device::struct_mutex lock.
103 */ 103 */
104static int drm_remove_magic(struct drm_master *master, drm_magic_t magic) 104int drm_remove_magic(struct drm_master *master, drm_magic_t magic)
105{ 105{
106 struct drm_magic_entry *pt; 106 struct drm_magic_entry *pt;
107 struct drm_hash_item *hash; 107 struct drm_hash_item *hash;
@@ -136,6 +136,8 @@ static int drm_remove_magic(struct drm_master *master, drm_magic_t magic)
136 * If there is a magic number in drm_file::magic then use it, otherwise 136 * If there is a magic number in drm_file::magic then use it, otherwise
137 * searches an unique non-zero magic number and add it associating it with \p 137 * searches an unique non-zero magic number and add it associating it with \p
138 * file_priv. 138 * file_priv.
139 * This ioctl needs protection by the drm_global_mutex, which protects
140 * struct drm_file::magic and struct drm_magic_entry::priv.
139 */ 141 */
140int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv) 142int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
141{ 143{
@@ -173,6 +175,8 @@ int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
173 * \return zero if authentication successed, or a negative number otherwise. 175 * \return zero if authentication successed, or a negative number otherwise.
174 * 176 *
175 * Checks if \p file_priv is associated with the magic number passed in \arg. 177 * Checks if \p file_priv is associated with the magic number passed in \arg.
178 * This ioctl needs protection by the drm_global_mutex, which protects
179 * struct drm_file::magic and struct drm_magic_entry::priv.
176 */ 180 */
177int drm_authmagic(struct drm_device *dev, void *data, 181int drm_authmagic(struct drm_device *dev, void *data,
178 struct drm_file *file_priv) 182 struct drm_file *file_priv)
diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
index c00cf154cc0..6263b014759 100644
--- a/drivers/gpu/drm/drm_fops.c
+++ b/drivers/gpu/drm/drm_fops.c
@@ -487,6 +487,11 @@ int drm_release(struct inode *inode, struct file *filp)
487 (long)old_encode_dev(file_priv->minor->device), 487 (long)old_encode_dev(file_priv->minor->device),
488 dev->open_count); 488 dev->open_count);
489 489
490 /* Release any auth tokens that might point to this file_priv,
491 (do that under the drm_global_mutex) */
492 if (file_priv->magic)
493 (void) drm_remove_magic(file_priv->master, file_priv->magic);
494
490 /* if the master has gone away we can't do anything with the lock */ 495 /* if the master has gone away we can't do anything with the lock */
491 if (file_priv->minor->master) 496 if (file_priv->minor->master)
492 drm_master_release(dev, filp); 497 drm_master_release(dev, filp);
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 76caa67c22e..92f0981b5fb 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -1328,6 +1328,7 @@ extern int drm_getmagic(struct drm_device *dev, void *data,
1328 struct drm_file *file_priv); 1328 struct drm_file *file_priv);
1329extern int drm_authmagic(struct drm_device *dev, void *data, 1329extern int drm_authmagic(struct drm_device *dev, void *data,
1330 struct drm_file *file_priv); 1330 struct drm_file *file_priv);
1331extern int drm_remove_magic(struct drm_master *master, drm_magic_t magic);
1331 1332
1332/* Cache management (drm_cache.c) */ 1333/* Cache management (drm_cache.c) */
1333void drm_clflush_pages(struct page *pages[], unsigned long num_pages); 1334void drm_clflush_pages(struct page *pages[], unsigned long num_pages);