Skip to contentSkip to conversation

kprobes: Sanitize struct kretprobe_instance allocations

PATCH In review Ananth N Mavinakayanahalli 2 participants 3 messages Oct 30, 2009 – Nov 2, 2009 kprobes

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kprobes: Sanitize struct kretprobe_instance allocations

From: Ananth N Mavinakayanahalli <[email protected]>

For as long as kretprobes have existed, we've allocated NR_CPUS instances of kretprobe_instance structures. With the default value of CONFIG_NR_CPUS increasing on certain architectures, we are potentially wasting kernel memory.

See http://sourceware.org/bugzilla/show_bug.cgi?id=10839#c3 for more details.

Use a saner num_possible_cpus() instead of NR_CPUS for allocation.

---
 kernel/kprobes.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kprobes.c +2 -2
Index: linux-2.6.32-rc5/kernel/kprobes.c
===================================================================
@@ -1014,9 +1014,9 @@ int __kprobes register_kretprobe(struct 
 	/* Pre-allocate memory for max kretprobe instances */
 	if (rp->maxactive <= 0) {
 #ifdef CONFIG_PREEMPT
-		rp->maxactive = max(10, 2 * NR_CPUS);
+		rp->maxactive = max(10, 2 * num_possible_cpus());
 #else
-		rp->maxactive = NR_CPUS;
+		rp->maxactive = num_possible_cpus();
 #endif
 	}
 	spin_lock_init(&rp->lock);
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Ananth N Mavinakayanahalli

From: Ananth N Mavinakayanahalli<[email protected]>

For as long as kretprobes have existed, we've allocated NR_CPUS instances of kretprobe_instance structures. With the default value of CONFIG_NR_CPUS increasing on certain architectures, we are potentially wasting kernel memory.

Quoted 6 lines

See http://sourceware.org/bugzilla/show_bug.cgi?id=10839#c3 for more details.

Use a saner num_possible_cpus() instead of NR_CPUS for allocation.

Thanks!

Quoted 20 lines
---
  kernel/kprobes.c |    4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

Index: linux-2.6.32-rc5/kernel/kprobes.c
===================================================================

kernel/kprobes.c +2 -2
@@ -1014,9 +1014,9 @@ int __kprobes register_kretprobe(struct
  	/* Pre-allocate memory for max kretprobe instances */
  	if (rp->maxactive<= 0) {
  #ifdef CONFIG_PREEMPT
-		rp->maxactive = max(10, 2 * NR_CPUS);
+		rp->maxactive = max(10, 2 * num_possible_cpus());
  #else
-		rp->maxactive = NR_CPUS;
+		rp->maxactive = num_possible_cpus();
  #endif
  	}
  	spin_lock_init(&rp->lock);
Signature · 7 lines
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: [email protected]
#2 lore raw
In reply to Ananth N Mavinakayanahalli
Commit-ID:  4dae560f97fa438f373b53e14b30149c9e44a600
Gitweb:     http://git.kernel.org/tip/4dae560f97fa438f373b53e14b30149c9e44a600
Author:     Ananth N Mavinakayanahalli <[email protected]>
AuthorDate: Fri, 30 Oct 2009 19:23:10 +0530
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 2 Nov 2009 17:00:18 +0100

kprobes: Sanitize struct kretprobe_instance allocations

For as long as kretprobes have existed, we've allocated NR_CPUS instances of kretprobe_instance structures. With the default value of CONFIG_NR_CPUS increasing on certain architectures, we are potentially wasting kernel memory.

See http://sourceware.org/bugzilla/show_bug.cgi?id=10839#c3 for more details.

Use a saner num_possible_cpus() instead of NR_CPUS for allocation.

LKML-Reference: <[email protected]>

---
 kernel/kprobes.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
kernel/kprobes.c +2 -2
index 5240d75..1494e85 100644
@@ -1014,9 +1014,9 @@ int __kprobes register_kretprobe(struct kretprobe *rp)
 	/* Pre-allocate memory for max kretprobe instances */
 	if (rp->maxactive <= 0) {
 #ifdef CONFIG_PREEMPT
-		rp->maxactive = max(10, 2 * NR_CPUS);
+		rp->maxactive = max(10, 2 * num_possible_cpus());
 #else
-		rp->maxactive = NR_CPUS;
+		rp->maxactive = num_possible_cpus();
 #endif
 	}
 	spin_lock_init(&rp->lock);