Commit a8ec3a66 authored by Ilija Hadzic's avatar Ilija Hadzic Committed by Dave Airlie

drm: correctly restore mappings if drm_open fails

If first drm_open fails, the error-handling path will
incorrectly restore inode's mapping to NULL. This can
cause the crash later on. Fix by separately storing
away mapping pointers that drm_open can touch and
restore each from its own respective variable if the
call fails.

Fixes: https://bugzilla.novell.com/show_bug.cgi?id=807850
(thanks to Michal Hocko for investigating investigating and
finding the root cause of the bug)

Reference:
http://lists.freedesktop.org/archives/dri-devel/2013-March/036564.html

v2: Use one variable to store file and inode mapping
    since they are the same at the function entry.
    Fix spelling mistakes in commit message.

v3: Add reference to the original bug report.
Reported-by: default avatarMarco Munderloh <munderl@tnt.uni-hannover.de>
Tested-by: default avatarMarco Munderloh <munderl@tnt.uni-hannover.de>
Signed-off-by: default avatarIlija Hadzic <ihadzic@research.bell-labs.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent 7cebefe6
...@@ -123,6 +123,7 @@ int drm_open(struct inode *inode, struct file *filp) ...@@ -123,6 +123,7 @@ int drm_open(struct inode *inode, struct file *filp)
int retcode = 0; int retcode = 0;
int need_setup = 0; int need_setup = 0;
struct address_space *old_mapping; struct address_space *old_mapping;
struct address_space *old_imapping;
minor = idr_find(&drm_minors_idr, minor_id); minor = idr_find(&drm_minors_idr, minor_id);
if (!minor) if (!minor)
...@@ -137,6 +138,7 @@ int drm_open(struct inode *inode, struct file *filp) ...@@ -137,6 +138,7 @@ int drm_open(struct inode *inode, struct file *filp)
if (!dev->open_count++) if (!dev->open_count++)
need_setup = 1; need_setup = 1;
mutex_lock(&dev->struct_mutex); mutex_lock(&dev->struct_mutex);
old_imapping = inode->i_mapping;
old_mapping = dev->dev_mapping; old_mapping = dev->dev_mapping;
if (old_mapping == NULL) if (old_mapping == NULL)
dev->dev_mapping = &inode->i_data; dev->dev_mapping = &inode->i_data;
...@@ -159,8 +161,8 @@ int drm_open(struct inode *inode, struct file *filp) ...@@ -159,8 +161,8 @@ int drm_open(struct inode *inode, struct file *filp)
err_undo: err_undo:
mutex_lock(&dev->struct_mutex); mutex_lock(&dev->struct_mutex);
filp->f_mapping = old_mapping; filp->f_mapping = old_imapping;
inode->i_mapping = old_mapping; inode->i_mapping = old_imapping;
iput(container_of(dev->dev_mapping, struct inode, i_data)); iput(container_of(dev->dev_mapping, struct inode, i_data));
dev->dev_mapping = old_mapping; dev->dev_mapping = old_mapping;
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment