aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Dobriyan <adobriyan@gmail.com>2018-04-10 19:34:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-04-11 13:28:36 -0400
commit0965232035cfa59a64d197cf8a8ee0bc407bb3e4 (patch)
treef6c65bb356de0d962666185d7d4435b9afe76861
parent9ad553abe66f8be3f4755e9fa0a6ba137ce76341 (diff)
seq_file: allocate seq_file from kmem_cache
For fine-grained debugging and usercopy protection. Link: http://lkml.kernel.org/r/20180310085027.GA17121@avx2 Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Glauber Costa <glommer@gmail.com> Cc: Vladimir Davydov <vdavydov.dev@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--fs/seq_file.c12
-rw-r--r--include/linux/seq_file.h1
-rw-r--r--init/main.c1
3 files changed, 12 insertions, 2 deletions
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 0677e89f3c6f..3cb340583074 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -6,6 +6,7 @@
6 * initial implementation -- AV, Oct 2001. 6 * initial implementation -- AV, Oct 2001.
7 */ 7 */
8 8
9#include <linux/cache.h>
9#include <linux/fs.h> 10#include <linux/fs.h>
10#include <linux/export.h> 11#include <linux/export.h>
11#include <linux/seq_file.h> 12#include <linux/seq_file.h>
@@ -19,6 +20,8 @@
19#include <linux/uaccess.h> 20#include <linux/uaccess.h>
20#include <asm/page.h> 21#include <asm/page.h>
21 22
23static struct kmem_cache *seq_file_cache __ro_after_init;
24
22static void seq_set_overflow(struct seq_file *m) 25static void seq_set_overflow(struct seq_file *m)
23{ 26{
24 m->count = m->size; 27 m->count = m->size;
@@ -51,7 +54,7 @@ int seq_open(struct file *file, const struct seq_operations *op)
51 54
52 WARN_ON(file->private_data); 55 WARN_ON(file->private_data);
53 56
54 p = kzalloc(sizeof(*p), GFP_KERNEL); 57 p = kmem_cache_zalloc(seq_file_cache, GFP_KERNEL);
55 if (!p) 58 if (!p)
56 return -ENOMEM; 59 return -ENOMEM;
57 60
@@ -366,7 +369,7 @@ int seq_release(struct inode *inode, struct file *file)
366{ 369{
367 struct seq_file *m = file->private_data; 370 struct seq_file *m = file->private_data;
368 kvfree(m->buf); 371 kvfree(m->buf);
369 kfree(m); 372 kmem_cache_free(seq_file_cache, m);
370 return 0; 373 return 0;
371} 374}
372EXPORT_SYMBOL(seq_release); 375EXPORT_SYMBOL(seq_release);
@@ -1106,3 +1109,8 @@ seq_hlist_next_percpu(void *v, struct hlist_head __percpu *head,
1106 return NULL; 1109 return NULL;
1107} 1110}
1108EXPORT_SYMBOL(seq_hlist_next_percpu); 1111EXPORT_SYMBOL(seq_hlist_next_percpu);
1112
1113void __init seq_file_init(void)
1114{
1115 seq_file_cache = KMEM_CACHE(seq_file, SLAB_PANIC);
1116}
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 23d6a92cea9f..a121982af0f5 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -240,4 +240,5 @@ extern struct hlist_node *seq_hlist_start_percpu(struct hlist_head __percpu *hea
240 240
241extern struct hlist_node *seq_hlist_next_percpu(void *v, struct hlist_head __percpu *head, int *cpu, loff_t *pos); 241extern struct hlist_node *seq_hlist_next_percpu(void *v, struct hlist_head __percpu *head, int *cpu, loff_t *pos);
242 242
243void seq_file_init(void);
243#endif 244#endif
diff --git a/init/main.c b/init/main.c
index 50359a3162d0..b795aa341a3a 100644
--- a/init/main.c
+++ b/init/main.c
@@ -715,6 +715,7 @@ asmlinkage __visible void __init start_kernel(void)
715 vfs_caches_init(); 715 vfs_caches_init();
716 pagecache_init(); 716 pagecache_init();
717 signals_init(); 717 signals_init();
718 seq_file_init();
718 proc_root_init(); 719 proc_root_init();
719 nsfs_init(); 720 nsfs_init();
720 cpuset_init(); 721 cpuset_init();