summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAshish Mhetre <amhetre@nvidia.com>2022-01-10 06:31:01 -0500
committermobile promotions <svcmobile_promotions@nvidia.com>2022-01-11 06:39:22 -0500
commit06d8f135d0ec9d291ffb8a3049308a853edb4000 (patch)
treefbd5a4da7770a2c42cb018d58729f8bfc1145c76
parent565de56422d5dee321d1ad81ac053f9991654653 (diff)
video: tegra: nvmap: Fix race between write and free
When NvRmMemWrite() and NvRmMemFree() are called simultaneously on same handle then it could lead to race where dmabuf freed from NvRmMemFree() call could get used by nvmap_get_cachebility() and cause kernel crash. When dmabuf is freed, its exported functions such as get_drvdata() won't be valid anymore and will give error value or NULL. Fix this by checking if get_drvdata() returns error value or NULL and act accordingly. Bug 3457360 Change-Id: Ibcd238bfde8775347a9f8c6266ed3ab3825d945d Signed-off-by: Ashish Mhetre <amhetre@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2651952 Reviewed-by: Ketan Patil <ketanp@nvidia.com> Reviewed-by: Puneet Saxena <puneets@nvidia.com> Reviewed-by: Sachin Nikam <snikam@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> GVS: Gerrit_Virtual_Submit Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
-rw-r--r--drivers/video/tegra/nvmap/nvmap_cache_t19x.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/video/tegra/nvmap/nvmap_cache_t19x.c b/drivers/video/tegra/nvmap/nvmap_cache_t19x.c
index 09a56c38d..975327752 100644
--- a/drivers/video/tegra/nvmap/nvmap_cache_t19x.c
+++ b/drivers/video/tegra/nvmap/nvmap_cache_t19x.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * drivers/video/tegra/nvmap/nvmap_cache_t19x.c 2 * drivers/video/tegra/nvmap/nvmap_cache_t19x.c
3 * 3 *
4 * Copyright (c) 2016-2021, NVIDIA CORPORATION. All rights reserved. 4 * Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify it 6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License, 7 * under the terms and conditions of the GNU General Public License,
@@ -25,11 +25,11 @@ struct static_key nvmap_updated_cache_config;
25static void nvmap_handle_get_cacheability(struct nvmap_handle *h, 25static void nvmap_handle_get_cacheability(struct nvmap_handle *h,
26 bool *inner, bool *outer) 26 bool *inner, bool *outer)
27{ 27{
28 struct nvmap_handle_t19x *handle_t19x; 28 struct nvmap_handle_t19x *handle_t19x = NULL;
29 struct device *dev = nvmap_dev->dev_user.parent; 29 struct device *dev = nvmap_dev->dev_user.parent;
30 30
31 handle_t19x = dma_buf_get_drvdata(h->dmabuf, dev); 31 handle_t19x = dma_buf_get_drvdata(h->dmabuf, dev);
32 if (handle_t19x && atomic_read(&handle_t19x->nc_pin)) { 32 if (!IS_ERR_OR_NULL(handle_t19x) && atomic_read(&handle_t19x->nc_pin)) {
33 *inner = *outer = false; 33 *inner = *outer = false;
34 return; 34 return;
35 } 35 }