diff options
author | Ilija Hadzic <ihadzic@research.bell-labs.com> | 2013-04-02 09:56:10 -0400 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2013-04-02 16:44:38 -0400 |
commit | a8ec3a662921220fc058ed6f7f3674697876d218 (patch) | |
tree | e7c35670e35d4e5ace87b01c83652dfee006fdc4 /drivers/gpu | |
parent | 7cebefe6cca5e8ff6ec9ba13ff9edb03d3c19fc7 (diff) |
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: Marco Munderloh <munderl@tnt.uni-hannover.de>
Tested-by: Marco Munderloh <munderl@tnt.uni-hannover.de>
Signed-off-by: Ilija Hadzic <ihadzic@research.bell-labs.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: stable@vger.kernel.org
Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/gpu')
-rw-r--r-- | drivers/gpu/drm/drm_fops.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c index 13fdcd10a605..429e07d0b0f1 100644 --- a/drivers/gpu/drm/drm_fops.c +++ b/drivers/gpu/drm/drm_fops.c | |||
@@ -123,6 +123,7 @@ int drm_open(struct inode *inode, struct file *filp) | |||
123 | int retcode = 0; | 123 | int retcode = 0; |
124 | int need_setup = 0; | 124 | int need_setup = 0; |
125 | struct address_space *old_mapping; | 125 | struct address_space *old_mapping; |
126 | struct address_space *old_imapping; | ||
126 | 127 | ||
127 | minor = idr_find(&drm_minors_idr, minor_id); | 128 | minor = idr_find(&drm_minors_idr, minor_id); |
128 | if (!minor) | 129 | if (!minor) |
@@ -137,6 +138,7 @@ int drm_open(struct inode *inode, struct file *filp) | |||
137 | if (!dev->open_count++) | 138 | if (!dev->open_count++) |
138 | need_setup = 1; | 139 | need_setup = 1; |
139 | mutex_lock(&dev->struct_mutex); | 140 | mutex_lock(&dev->struct_mutex); |
141 | old_imapping = inode->i_mapping; | ||
140 | old_mapping = dev->dev_mapping; | 142 | old_mapping = dev->dev_mapping; |
141 | if (old_mapping == NULL) | 143 | if (old_mapping == NULL) |
142 | dev->dev_mapping = &inode->i_data; | 144 | dev->dev_mapping = &inode->i_data; |
@@ -159,8 +161,8 @@ int drm_open(struct inode *inode, struct file *filp) | |||
159 | 161 | ||
160 | err_undo: | 162 | err_undo: |
161 | mutex_lock(&dev->struct_mutex); | 163 | mutex_lock(&dev->struct_mutex); |
162 | filp->f_mapping = old_mapping; | 164 | filp->f_mapping = old_imapping; |
163 | inode->i_mapping = old_mapping; | 165 | inode->i_mapping = old_imapping; |
164 | iput(container_of(dev->dev_mapping, struct inode, i_data)); | 166 | iput(container_of(dev->dev_mapping, struct inode, i_data)); |
165 | dev->dev_mapping = old_mapping; | 167 | dev->dev_mapping = old_mapping; |
166 | mutex_unlock(&dev->struct_mutex); | 168 | mutex_unlock(&dev->struct_mutex); |