]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/3.18.114/drm-msm-fix-possible-null-dereference-on-failure-of-get_pages.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.18.114 / drm-msm-fix-possible-null-dereference-on-failure-of-get_pages.patch
CommitLineData
0bfe1e00
GKH
1From foo@baz Sun Jun 17 13:19:44 CEST 2018
2From: Ben Hutchings <ben.hutchings@codethink.co.uk>
3Date: Tue, 3 Apr 2018 23:38:45 +0100
4Subject: drm/msm: Fix possible null dereference on failure of get_pages()
5
6From: Ben Hutchings <ben.hutchings@codethink.co.uk>
7
8[ Upstream commit 3976626ea3d2011f8fd3f3a47070a8b792018253 ]
9
10Commit 62e3a3e342af changed get_pages() to initialise
11msm_gem_object::pages before trying to initialise msm_gem_object::sgt,
12so that put_pages() would properly clean up pages in the failure
13case.
14
15However, this means that put_pages() now needs to check that
16msm_gem_object::sgt is not null before trying to clean it up, and
17this check was only applied to part of the cleanup code. Move
18it all into the conditional block. (Strictly speaking we don't
19need to make the kfree() conditional, but since we can't avoid
20checking for null ourselves we may as well do so.)
21
22Fixes: 62e3a3e342af ("drm/msm: fix leak in failed get_pages")
23Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
24Reviewed-by: Jordan Crouse <jcrouse@codeaurora.org>
25Signed-off-by: Rob Clark <robdclark@gmail.com>
26Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
27Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28---
29 drivers/gpu/drm/msm/msm_gem.c | 20 +++++++++++---------
30 1 file changed, 11 insertions(+), 9 deletions(-)
31
32--- a/drivers/gpu/drm/msm/msm_gem.c
33+++ b/drivers/gpu/drm/msm/msm_gem.c
34@@ -110,17 +110,19 @@ static void put_pages(struct drm_gem_obj
35 struct msm_gem_object *msm_obj = to_msm_bo(obj);
36
37 if (msm_obj->pages) {
38- /* For non-cached buffers, ensure the new pages are clean
39- * because display controller, GPU, etc. are not coherent:
40- */
41- if (msm_obj->flags & (MSM_BO_WC|MSM_BO_UNCACHED))
42- dma_unmap_sg(obj->dev->dev, msm_obj->sgt->sgl,
43- msm_obj->sgt->nents, DMA_BIDIRECTIONAL);
44+ if (msm_obj->sgt) {
45+ /* For non-cached buffers, ensure the new
46+ * pages are clean because display controller,
47+ * GPU, etc. are not coherent:
48+ */
49+ if (msm_obj->flags & (MSM_BO_WC|MSM_BO_UNCACHED))
50+ dma_unmap_sg(obj->dev->dev, msm_obj->sgt->sgl,
51+ msm_obj->sgt->nents,
52+ DMA_BIDIRECTIONAL);
53
54- if (msm_obj->sgt)
55 sg_free_table(msm_obj->sgt);
56-
57- kfree(msm_obj->sgt);
58+ kfree(msm_obj->sgt);
59+ }
60
61 if (iommu_present(&platform_bus_type))
62 drm_gem_put_pages(obj, msm_obj->pages, true, false);