The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] sync: Fix memory corruption in sync_timeline_signal().
@ 2015-03-24 20:55 Alistair Strachan
  2015-03-24 21:46 ` Greg Kroah-Hartman
  2015-03-24 21:51 ` Alistair Strachan
  0 siblings, 2 replies; 3+ messages in thread
From: Alistair Strachan @ 2015-03-24 20:55 UTC (permalink / raw)
  To: linux-kernel
  Cc: Alistair Strachan, Maarten Lankhorst, Greg Kroah-Hartman,
	Colin Cross

The android_fence_release() function checks for active sync points
by calling list_empty() on the list head embedded on the sync
point. However, it is only valid to use list_empty() on nodes that
have been initialized with INIT_LIST_HEAD() or list_del_init().

Because the list entry has likely been removed from the active list
by sync_timeline_signal(), there is a good chance that this
WARN_ON_ONCE() will be hit due to dangling pointers pointing at
freed memory (even though the sync drivers did nothing wrong)
and memory corruption will ensue as the list entry is removed for
a second time, corrupting the active list.

This problem can be reproduced quite easily with CONFIG_DEBUG_LIST=y
and fences with more than one sync point.

Change-Id: Ie2a6bc1480bbcfdc14f9b385fca5a2b833effc05

Signed-off-by: Alistair Strachan <alistair.strachan@imgtec.com>
Cc: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Colin Cross <ccross@google.com>
---
 drivers/staging/android/sync.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 7bdb62b..f83e00c 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -114,7 +114,7 @@ void sync_timeline_signal(struct sync_timeline *obj)
 	list_for_each_entry_safe(pt, next, &obj->active_list_head,
 				 active_list) {
 		if (fence_is_signaled_locked(&pt->base))
-			list_del(&pt->active_list);
+			list_del_init(&pt->active_list);
 	}
 
 	spin_unlock_irqrestore(&obj->child_list_lock, flags);
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] sync: Fix memory corruption in sync_timeline_signal().
  2015-03-24 20:55 [PATCH] sync: Fix memory corruption in sync_timeline_signal() Alistair Strachan
@ 2015-03-24 21:46 ` Greg Kroah-Hartman
  2015-03-24 21:51 ` Alistair Strachan
  1 sibling, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2015-03-24 21:46 UTC (permalink / raw)
  To: Alistair Strachan; +Cc: linux-kernel, Maarten Lankhorst, Colin Cross

On Tue, Mar 24, 2015 at 01:55:04PM -0700, Alistair Strachan wrote:
> The android_fence_release() function checks for active sync points
> by calling list_empty() on the list head embedded on the sync
> point. However, it is only valid to use list_empty() on nodes that
> have been initialized with INIT_LIST_HEAD() or list_del_init().
> 
> Because the list entry has likely been removed from the active list
> by sync_timeline_signal(), there is a good chance that this
> WARN_ON_ONCE() will be hit due to dangling pointers pointing at
> freed memory (even though the sync drivers did nothing wrong)
> and memory corruption will ensue as the list entry is removed for
> a second time, corrupting the active list.
> 
> This problem can be reproduced quite easily with CONFIG_DEBUG_LIST=y
> and fences with more than one sync point.
> 
> Change-Id: Ie2a6bc1480bbcfdc14f9b385fca5a2b833effc05

This line doesn't belong in a kernel changelog, can you please remove
and resend?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] sync: Fix memory corruption in sync_timeline_signal().
  2015-03-24 20:55 [PATCH] sync: Fix memory corruption in sync_timeline_signal() Alistair Strachan
  2015-03-24 21:46 ` Greg Kroah-Hartman
@ 2015-03-24 21:51 ` Alistair Strachan
  1 sibling, 0 replies; 3+ messages in thread
From: Alistair Strachan @ 2015-03-24 21:51 UTC (permalink / raw)
  To: linux-kernel
  Cc: Alistair Strachan, Maarten Lankhorst, Greg Kroah-Hartman,
	Colin Cross

The android_fence_release() function checks for active sync points
by calling list_empty() on the list head embedded on the sync
point. However, it is only valid to use list_empty() on nodes that
have been initialized with INIT_LIST_HEAD() or list_del_init().

Because the list entry has likely been removed from the active list
by sync_timeline_signal(), there is a good chance that this
WARN_ON_ONCE() will be hit due to dangling pointers pointing at
freed memory (even though the sync drivers did nothing wrong)
and memory corruption will ensue as the list entry is removed for
a second time, corrupting the active list.

This problem can be reproduced quite easily with CONFIG_DEBUG_LIST=y
and fences with more than one sync point.

Signed-off-by: Alistair Strachan <alistair.strachan@imgtec.com>
Cc: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Colin Cross <ccross@google.com>
---
 drivers/staging/android/sync.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 7bdb62b..f83e00c 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -114,7 +114,7 @@ void sync_timeline_signal(struct sync_timeline *obj)
 	list_for_each_entry_safe(pt, next, &obj->active_list_head,
 				 active_list) {
 		if (fence_is_signaled_locked(&pt->base))
-			list_del(&pt->active_list);
+			list_del_init(&pt->active_list);
 	}
 
 	spin_unlock_irqrestore(&obj->child_list_lock, flags);
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-24 21:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-24 20:55 [PATCH] sync: Fix memory corruption in sync_timeline_signal() Alistair Strachan
2015-03-24 21:46 ` Greg Kroah-Hartman
2015-03-24 21:51 ` Alistair Strachan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox