|
59 | 59 | #include <linux/taskstats_kern.h> |
60 | 60 | #include <linux/random.h> |
61 | 61 | #include <linux/tty.h> |
62 | | -#include <linux/proc_fs.h> |
63 | 62 | #include <linux/blkdev.h> |
64 | 63 | #include <linux/fs_struct.h> |
65 | 64 | #include <linux/magic.h> |
@@ -597,6 +596,57 @@ void mmput(struct mm_struct *mm) |
597 | 596 | } |
598 | 597 | EXPORT_SYMBOL_GPL(mmput); |
599 | 598 |
|
| 599 | +/* |
| 600 | + * We added or removed a vma mapping the executable. The vmas are only mapped |
| 601 | + * during exec and are not mapped with the mmap system call. |
| 602 | + * Callers must hold down_write() on the mm's mmap_sem for these |
| 603 | + */ |
| 604 | +void added_exe_file_vma(struct mm_struct *mm) |
| 605 | +{ |
| 606 | + mm->num_exe_file_vmas++; |
| 607 | +} |
| 608 | + |
| 609 | +void removed_exe_file_vma(struct mm_struct *mm) |
| 610 | +{ |
| 611 | + mm->num_exe_file_vmas--; |
| 612 | + if ((mm->num_exe_file_vmas == 0) && mm->exe_file){ |
| 613 | + fput(mm->exe_file); |
| 614 | + mm->exe_file = NULL; |
| 615 | + } |
| 616 | + |
| 617 | +} |
| 618 | + |
| 619 | +void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file) |
| 620 | +{ |
| 621 | + if (new_exe_file) |
| 622 | + get_file(new_exe_file); |
| 623 | + if (mm->exe_file) |
| 624 | + fput(mm->exe_file); |
| 625 | + mm->exe_file = new_exe_file; |
| 626 | + mm->num_exe_file_vmas = 0; |
| 627 | +} |
| 628 | + |
| 629 | +struct file *get_mm_exe_file(struct mm_struct *mm) |
| 630 | +{ |
| 631 | + struct file *exe_file; |
| 632 | + |
| 633 | + /* We need mmap_sem to protect against races with removal of |
| 634 | + * VM_EXECUTABLE vmas */ |
| 635 | + down_read(&mm->mmap_sem); |
| 636 | + exe_file = mm->exe_file; |
| 637 | + if (exe_file) |
| 638 | + get_file(exe_file); |
| 639 | + up_read(&mm->mmap_sem); |
| 640 | + return exe_file; |
| 641 | +} |
| 642 | + |
| 643 | +static void dup_mm_exe_file(struct mm_struct *oldmm, struct mm_struct *newmm) |
| 644 | +{ |
| 645 | + /* It's safe to write the exe_file pointer without exe_file_lock because |
| 646 | + * this is called during fork when the task is not yet in /proc */ |
| 647 | + newmm->exe_file = get_mm_exe_file(oldmm); |
| 648 | +} |
| 649 | + |
600 | 650 | /** |
601 | 651 | * get_task_mm - acquire a reference to the task's mm |
602 | 652 | * |
|
0 commit comments