aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/proc/base.c40
-rw-r--r--fs/proc/internal.h6
-rw-r--r--fs/proc/task_mmu.c44
3 files changed, 37 insertions, 53 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 33537487f5ab..1bd646d3fe9a 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -88,10 +88,6 @@
88 * in /proc for a task before it execs a suid executable. 88 * in /proc for a task before it execs a suid executable.
89 */ 89 */
90 90
91
92/* Worst case buffer size needed for holding an integer. */
93#define PROC_NUMBUF 13
94
95struct pid_entry { 91struct pid_entry {
96 char *name; 92 char *name;
97 int len; 93 int len;
@@ -935,42 +931,6 @@ static const struct file_operations proc_oom_adjust_operations = {
935 .write = oom_adjust_write, 931 .write = oom_adjust_write,
936}; 932};
937 933
938#ifdef CONFIG_MMU
939static ssize_t clear_refs_write(struct file *file, const char __user *buf,
940 size_t count, loff_t *ppos)
941{
942 struct task_struct *task;
943 char buffer[PROC_NUMBUF], *end;
944 struct mm_struct *mm;
945
946 memset(buffer, 0, sizeof(buffer));
947 if (count > sizeof(buffer) - 1)
948 count = sizeof(buffer) - 1;
949 if (copy_from_user(buffer, buf, count))
950 return -EFAULT;
951 if (!simple_strtol(buffer, &end, 0))
952 return -EINVAL;
953 if (*end == '\n')
954 end++;
955 task = get_proc_task(file->f_path.dentry->d_inode);
956 if (!task)
957 return -ESRCH;
958 mm = get_task_mm(task);
959 if (mm) {
960 clear_refs_smap(mm);
961 mmput(mm);
962 }
963 put_task_struct(task);
964 if (end - buffer == 0)
965 return -EIO;
966 return end - buffer;
967}
968
969static struct file_operations proc_clear_refs_operations = {
970 .write = clear_refs_write,
971};
972#endif
973
974#ifdef CONFIG_AUDITSYSCALL 934#ifdef CONFIG_AUDITSYSCALL
975#define TMPBUFLEN 21 935#define TMPBUFLEN 21
976static ssize_t proc_loginuid_read(struct file * file, char __user * buf, 936static ssize_t proc_loginuid_read(struct file * file, char __user * buf,
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 05b3e9006262..ddfaeec37492 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -56,11 +56,7 @@ extern int proc_pid_statm(struct task_struct *, char *);
56extern const struct file_operations proc_maps_operations; 56extern const struct file_operations proc_maps_operations;
57extern const struct file_operations proc_numa_maps_operations; 57extern const struct file_operations proc_numa_maps_operations;
58extern const struct file_operations proc_smaps_operations; 58extern const struct file_operations proc_smaps_operations;
59 59extern const struct file_operations proc_clear_refs_operations;
60extern const struct file_operations proc_maps_operations;
61extern const struct file_operations proc_numa_maps_operations;
62extern const struct file_operations proc_smaps_operations;
63
64 60
65void free_proc_entry(struct proc_dir_entry *de); 61void free_proc_entry(struct proc_dir_entry *de);
66 62
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index abc44f39f1d6..fcdbd233f252 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -323,19 +323,47 @@ static int show_smap(struct seq_file *m, void *v)
323 323
324static struct mm_walk clear_refs_walk = { .pmd_entry = clear_refs_pte_range }; 324static struct mm_walk clear_refs_walk = { .pmd_entry = clear_refs_pte_range };
325 325
326void clear_refs_smap(struct mm_struct *mm) 326static ssize_t clear_refs_write(struct file *file, const char __user *buf,
327 size_t count, loff_t *ppos)
327{ 328{
329 struct task_struct *task;
330 char buffer[PROC_NUMBUF], *end;
331 struct mm_struct *mm;
328 struct vm_area_struct *vma; 332 struct vm_area_struct *vma;
329 333
330 down_read(&mm->mmap_sem); 334 memset(buffer, 0, sizeof(buffer));
331 for (vma = mm->mmap; vma; vma = vma->vm_next) 335 if (count > sizeof(buffer) - 1)
332 if (vma->vm_mm && !is_vm_hugetlb_page(vma)) 336 count = sizeof(buffer) - 1;
333 walk_page_range(vma->vm_mm, vma->vm_start, vma->vm_end, 337 if (copy_from_user(buffer, buf, count))
334 &clear_refs_walk, vma); 338 return -EFAULT;
335 flush_tlb_mm(mm); 339 if (!simple_strtol(buffer, &end, 0))
336 up_read(&mm->mmap_sem); 340 return -EINVAL;
341 if (*end == '\n')
342 end++;
343 task = get_proc_task(file->f_path.dentry->d_inode);
344 if (!task)
345 return -ESRCH;
346 mm = get_task_mm(task);
347 if (mm) {
348 down_read(&mm->mmap_sem);
349 for (vma = mm->mmap; vma; vma = vma->vm_next)
350 if (!is_vm_hugetlb_page(vma))
351 walk_page_range(mm, vma->vm_start, vma->vm_end,
352 &clear_refs_walk, vma);
353 flush_tlb_mm(mm);
354 up_read(&mm->mmap_sem);
355 mmput(mm);
356 }
357 put_task_struct(task);
358 if (end - buffer == 0)
359 return -EIO;
360 return end - buffer;
337} 361}
338 362
363const struct file_operations proc_clear_refs_operations = {
364 .write = clear_refs_write,
365};
366
339static void *m_start(struct seq_file *m, loff_t *pos) 367static void *m_start(struct seq_file *m, loff_t *pos)
340{ 368{
341 struct proc_maps_private *priv = m->private; 369 struct proc_maps_private *priv = m->private;