Last active
December 15, 2015 21:59
-
-
Save masami256/5329343 to your computer and use it in GitHub Desktop.
fork時のaudit_alloc_context()でkmalloc()じゃなくてkmem_cache_alloc()を使うpatch。for 3.10-rc1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/include/linux/audit.h b/include/linux/audit.h | |
index b20b038..2eb4be2 100644 | |
--- a/include/linux/audit.h | |
+++ b/include/linux/audit.h | |
@@ -94,6 +94,7 @@ extern void audit_log_session_info(struct audit_buffer *ab); | |
#ifdef CONFIG_AUDITSYSCALL | |
/* These are defined in auditsc.c */ | |
/* Public API */ | |
+extern int __init audit_cache_init(void); | |
extern int audit_alloc(struct task_struct *task); | |
extern void __audit_free(struct task_struct *task); | |
extern void __audit_syscall_entry(int arch, | |
@@ -285,6 +286,10 @@ static inline void audit_mmap_fd(int fd, int flags) | |
extern int audit_n_rules; | |
extern int audit_signals; | |
#else /* CONFIG_AUDITSYSCALL */ | |
+static inline int __init audit_cache_init(void) | |
+{ | |
+ return 0; | |
+} | |
static inline int audit_alloc(struct task_struct *task) | |
{ | |
return 0; | |
diff --git a/kernel/auditsc.c b/kernel/auditsc.c | |
index 3c8a601..bc6c2e3 100644 | |
--- a/kernel/auditsc.c | |
+++ b/kernel/auditsc.c | |
@@ -132,6 +132,8 @@ struct audit_tree_refs { | |
struct audit_chunk *c[31]; | |
}; | |
+static struct kmem_cache *audit_cachep; | |
+ | |
static inline int open_arg(int flags, int mask) | |
{ | |
int n = ACC_MODE(flags); | |
@@ -914,9 +916,10 @@ static inline struct audit_context *audit_alloc_context(enum audit_state state) | |
{ | |
struct audit_context *context; | |
- context = kzalloc(sizeof(*context), GFP_KERNEL); | |
+ context = kmem_cache_alloc(audit_cachep, GFP_KERNEL); | |
if (!context) | |
return NULL; | |
+ memset(context, 0, sizeof(*context)); | |
context->state = state; | |
context->prio = state == AUDIT_RECORD_CONTEXT ? ~0ULL : 0; | |
INIT_LIST_HEAD(&context->killed_trees); | |
@@ -966,7 +969,7 @@ static inline void audit_free_context(struct audit_context *context) | |
audit_free_aux(context); | |
kfree(context->filterkey); | |
kfree(context->sockaddr); | |
- kfree(context); | |
+ kmem_cache_free(audit_cachep, context); | |
} | |
static int audit_log_pid_context(struct audit_context *context, pid_t pid, | |
@@ -2416,3 +2419,11 @@ struct list_head *audit_killed_trees(void) | |
return NULL; | |
return &ctx->killed_trees; | |
} | |
+ | |
+int __init audit_cache_init(void) | |
+{ | |
+ printk(KERN_INFO"use slab cache instead of kmalloc in audit_alloc_context()\n"); | |
+ audit_cachep = KMEM_CACHE(audit_context, SLAB_PANIC); | |
+ return 0; | |
+} | |
+ | |
diff --git a/kernel/fork.c b/kernel/fork.c | |
index 987b28a..2b8e2e1 100644 | |
--- a/kernel/fork.c | |
+++ b/kernel/fork.c | |
@@ -1726,6 +1726,7 @@ void __init proc_caches_init(void) | |
vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC); | |
mmap_init(); | |
nsproxy_cache_init(); | |
+ audit_cache_init(); | |
} | |
/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment