driver:dma bug_fix : access freed memory
Subsystems (3)
PATCH 1/1 driver:dma bug_fix : access freed memory
From 8f6aeb362d9e44f29d46ae7694cdfee4408406ce Mon Sep 17 00:00:00 2001
From: "KIM JUGNBAE" <[email protected]>
Date: Thu, 26 Nov 2015 16:28:47 +0900
Subject: [PATCH] bug_fix : access freed memory
sync_fenc_free & fence_check_cb_func would be executed at other cpu. fence_check_cb_func access freed fence memory after kfree(fence) at sync_fence_free.
To escaped this issue, atomic_read(&fence->status) need to be protected by child_list_lock.
--- drivers/dma-buf/fence.c | 13 +++++++++++++ drivers/staging/android/sync.c | 10 +++++++--- drivers/staging/android/sync_debug.c | 2 ++ include/linux/fence.h | 1 + 4 files changed, 23 insertions(+), 3 deletions(-)
drivers/dma-buf/fence.c +13 -0
@@ -310,6 +310,19 @@ fence_remove_callback(struct fence *fence, struct fence_cb *cb) }EXPORT_SYMBOL (fence_remove_callback); +bool +fence_remove_callback_locked (struct fence *fence,struct fence_cb *cb) +{ +bool ret; + + ret = !list_empty (&cb->node); +if (ret) +list_del_init (&cb->node); + +return ret; +} +EXPORT_SYMBOL (fence_remove_callback_locked); +struct default_wait_cb {struct fence_cb base;struct task_struct *task;
drivers/staging/android/sync.c +7 -3
@@ -518,12 +518,16 @@ static const struct fence_ops android_fence_ops = {static void sync_fence_free (struct kref *kref) { struct sync_fence *fence = container_of(kref, struct sync_fence, kref); -int i, status =atomic_read (&fence->status); +int i; +unsigned long flags;for (i =0 ; i < fence->num_fences; ++i) { -if (status) -fence_remove_callback (fence->cbs[i].sync_pt, +spin_lock_irqsave (fence->cbs[i].sync_pt->lock, flags); +if (atomic_read (&fence->status)) +fence_remove_callback_locked (fence->cbs[i].sync_pt, &fence->cbs[i].cb); +spin_unlock_irqrestore (fence->cbs[i].sync_pt->lock, flags); +fence_put (fence->cbs[i].sync_pt); }
drivers/staging/android/sync_debug.c +2 -0
@@ -155,7 +155,9 @@ static void sync_print_fence(struct seq_file *s, struct sync_fence *fence)container_of (fence->cbs[i].sync_pt, struct sync_pt, base); +spin_lock_irqsave (pt->base.lock, flags);sync_print_pt (s, pt, true); +spin_unlock_irqrestore (pt->base.lock, flags); }spin_lock_irqsave (&fence->wq.lock, flags);
include/linux/fence.h +1 -0
@@ -224,6 +224,7 @@ signed long fence_default_wait(struct fence *fence, bool intr, signed long timeoint fence_add_callback (struct fence *fence,struct fence_cb *cb,fence_func_t func);bool fence_remove_callback (struct fence *fence,struct fence_cb *cb); +bool fence_remove_callback_locked (struct fence *fence,struct fence_cb *cb);void fence_enable_sw_signaling (struct fence *fence);/**
Signature · 1 line
1.7.9.5
Quoted 4 lines · 김정배
From
8f6aeb362d9e44f29d46ae7694cdfee4408406ceMon Sep 17 00:00:00 2001
From: "KIM JUGNBAE" <[email protected]>
Date: Thu, 26 Nov 2015 16:28:47 +0900
Subject: [PATCH]bug_fix: access freed memory
This part should not be present in the patch.
Quoted 8 lines
sync_fenc_free&fence_check_cb_funcwould be executed at other cpu.fence_check_cb_funcaccess freed fence memory after kfree(fence) atsync_fence_free.
To escaped this issue,atomic_read(&fence->status)need to be protected bychild_list_lock.Signed-off-by "kimjungbae\" " <[email protected]>"
The From name and the Signed-off-by name shouls be same. Mayvbe you can consider having Kim Jugnbae (or Jungbae) as both.
Quoted 6 lines
--- drivers/dma-buf/fence.c | 13 +++++++++++++ drivers/staging/android/sync.c | 10 +++++++--- drivers/staging/android/sync_debug.c | 2 ++ include/linux/fence.h | 1 + 4 files changed, 23 insertions(+), 3 deletions(-)
Usually staging patches can not touch anything outside staging.
regards
sudip
_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel