public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Moore <dcm@MIT.EDU>
To: linux1394-devel <linux1394-devel@lists.sourceforge.net>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] lib/idr.c: Zero memory properly in idr_remove_all
Date: Fri, 09 Jan 2009 23:04:20 -0800	[thread overview]
Message-ID: <1231571060.3538.18.camel@localhost.localdomain> (raw)

From: David Moore <dcm@acm.org>

The idr_remove_all() function returns unused slabs to the kmem cache,
but needs to zero them first or else they will be uninitialized upon
next use.  This fixes crashes which have been observed in the firewire
subsystem.

Signed-off-by: David Moore <dcm@acm.org>
---
 lib/idr.c |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/lib/idr.c b/lib/idr.c
index 1c4f928..69c3455 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -65,6 +65,20 @@ static inline void free_layer(struct idr_layer *p)
 	call_rcu(&p->rcu_head, idr_layer_rcu_free);
 }
 
+static void idr_layer_rcu_free_zero(struct rcu_head *head)
+{
+	struct idr_layer *layer;
+
+	layer = container_of(head, struct idr_layer, rcu_head);
+	memset(layer, 0, sizeof(struct idr_layer));
+	kmem_cache_free(idr_layer_cache, layer);
+}
+
+static inline void free_layer_zero(struct idr_layer *p)
+{
+	call_rcu(&p->rcu_head, idr_layer_rcu_free_zero);
+}
+
 /* only called when idp->lock is held */
 static void __move_to_free_list(struct idr *idp, struct idr_layer *p)
 {
@@ -462,7 +476,7 @@ void idr_remove_all(struct idr *idp)
 		id += 1 << n;
 		while (n < fls(id)) {
 			if (p)
-				free_layer(p);
+				free_layer_zero(p);
 			n += IDR_BITS;
 			p = *--paa;
 		}
-- 
1.6.0.6




             reply	other threads:[~2009-01-10  7:04 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-10  7:04 David Moore [this message]
2009-01-10  9:03 ` [PATCH] lib/idr.c: Zero memory properly in idr_remove_all Stefan Richter
2009-01-10  9:15   ` Andrew Morton
2009-01-10 10:05     ` Stefan Richter
2009-01-12 15:20       ` Kristian Høgsberg
2009-01-12 19:53         ` Manfred Spraul
2009-01-12 20:38           ` Kristian Høgsberg
2009-01-12 20:50             ` Manfred Spraul
2009-01-13 22:48               ` Andrew Morton
2009-01-14  2:51                 ` David Moore
2009-01-14  7:19                 ` Pekka Enberg
2009-01-14  8:17                   ` Andrew Morton
2009-01-14  8:59                     ` Stefan Richter
2009-01-14  9:22                       ` Andrew Morton
2009-01-14  9:48                         ` Stefan Richter
2009-01-14  9:52                           ` Stefan Richter
2009-01-14  9:02                     ` Pekka Enberg
2009-01-14 14:23                 ` Kristian Høgsberg
2009-01-14 16:21                   ` Stefan Richter
2009-01-14 16:33                     ` Kristian Høgsberg
2009-01-14 18:05                       ` Stefan Richter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1231571060.3538.18.camel@localhost.localdomain \
    --to=dcm@mit.edu \
    --cc=dcm@acm.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux1394-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox