Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1192587

[PATCH] perf: Avoid double-free of AUX buffer

From Ben Hutchings <ben@decadent.org.uk>
Newsgroups linux.kernel
Subject [PATCH] perf: Avoid double-free of AUX buffer
Date 2015-07-27 01:40 +0200
Message-ID <pQDGq-YK-7@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

If rb->aux_refcount is decremented to zero before rb->refcount,
__rb_free_aux() may be called twice resulting in a double free of
rb->aux_pages.  Fix this by adding a check to __rb_free_aux().

Fixes: 57ffc5ca679f ("perf: Fix AUX buffer refcounting")
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
Found by inspection, and the fix is compile-tested only.

I think both commit 57ffc5ca679f and this should go to stable, but
that's up to you.

Ben.

 kernel/events/ring_buffer.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index b2be01b..c8aa3f7 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -559,11 +559,13 @@ static void __rb_free_aux(struct ring_buffer *rb)
 		rb->aux_priv = NULL;
 	}
 
-	for (pg = 0; pg < rb->aux_nr_pages; pg++)
-		rb_free_aux_page(rb, pg);
+	if (rb->aux_nr_pages) {
+		for (pg = 0; pg < rb->aux_nr_pages; pg++)
+			rb_free_aux_page(rb, pg);
 
-	kfree(rb->aux_pages);
-	rb->aux_nr_pages = 0;
+		kfree(rb->aux_pages);
+		rb->aux_nr_pages = 0;
+	}
 }
 
 void rb_free_aux(struct ring_buffer *rb)
-- 
Ben Hutchings
Any sufficiently advanced bug is indistinguishable from a feature.

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[PATCH] perf: Avoid double-free of AUX buffer Ben Hutchings <ben@decadent.org.uk> - 2015-07-27 01:40 +0200

csiph-web