summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArchana Sriram <apsrir@codeaurora.org>2020-12-14 16:55:35 +0530
committerTiwari, Shubham <shubtiwa@codeaurora.org>2021-03-15 22:42:34 -0700
commit8b5ba278ed4b370ce85cda5f997d1027db168ac1 (patch)
tree44335c8f7e8788b5d701e11dcc8918915866fb95
parent4150552fac96e162e1c8607a94b2ad30b45d3620 (diff)
msm: kgsl: Correct the refcount on current process PID.
In kgsl_process_private_new() function there is inconsistency in the refcount of current process PID. Fix this to avoid overflowing of reference counter leading to use after free of this struct. Change-Id: I6291b9a05e139337e7f8471d0f9409fc839969a3 Signed-off-by: Archana Sriram <apsrir@codeaurora.org>
-rw-r--r--drivers/gpu/msm/kgsl.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/drivers/gpu/msm/kgsl.c b/drivers/gpu/msm/kgsl.c
index 8c8a51021e21..43ec8d8ff88b 100644
--- a/drivers/gpu/msm/kgsl.c
+++ b/drivers/gpu/msm/kgsl.c
@@ -917,17 +917,24 @@ static struct kgsl_process_private *kgsl_process_private_new(
list_for_each_entry(private, &kgsl_driver.process_list, list) {
if (private->pid == cur_pid) {
if (!kgsl_process_private_get(private)) {
- put_pid(cur_pid);
private = ERR_PTR(-EINVAL);
}
+ /*
+ * We need to hold only one reference to the PID for
+ * each process struct to avoid overflowing the
+ * reference counter which can lead to use-after-free.
+ */
+ put_pid(cur_pid);
return private;
}
}
/* Create a new object */
private = kzalloc(sizeof(struct kgsl_process_private), GFP_KERNEL);
- if (private == NULL)
+ if (private == NULL) {
+ put_pid(cur_pid);
return ERR_PTR(-ENOMEM);
+ }
kref_init(&private->refcount);