diff options
Diffstat (limited to 'kernel/fork.c')
-rw-r--r-- | kernel/fork.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index ecc694debb50..8149f3602881 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/syscalls.h> | 35 | #include <linux/syscalls.h> |
36 | #include <linux/jiffies.h> | 36 | #include <linux/jiffies.h> |
37 | #include <linux/futex.h> | 37 | #include <linux/futex.h> |
38 | #include <linux/rcupdate.h> | ||
38 | #include <linux/ptrace.h> | 39 | #include <linux/ptrace.h> |
39 | #include <linux/mount.h> | 40 | #include <linux/mount.h> |
40 | #include <linux/audit.h> | 41 | #include <linux/audit.h> |
@@ -565,13 +566,12 @@ static inline int copy_fs(unsigned long clone_flags, struct task_struct * tsk) | |||
565 | return 0; | 566 | return 0; |
566 | } | 567 | } |
567 | 568 | ||
568 | static int count_open_files(struct files_struct *files, int size) | 569 | static int count_open_files(struct fdtable *fdt) |
569 | { | 570 | { |
571 | int size = fdt->max_fdset; | ||
570 | int i; | 572 | int i; |
571 | struct fdtable *fdt; | ||
572 | 573 | ||
573 | /* Find the last open fd */ | 574 | /* Find the last open fd */ |
574 | fdt = files_fdtable(files); | ||
575 | for (i = size/(8*sizeof(long)); i > 0; ) { | 575 | for (i = size/(8*sizeof(long)); i > 0; ) { |
576 | if (fdt->open_fds->fds_bits[--i]) | 576 | if (fdt->open_fds->fds_bits[--i]) |
577 | break; | 577 | break; |
@@ -592,13 +592,17 @@ static struct files_struct *alloc_files(void) | |||
592 | atomic_set(&newf->count, 1); | 592 | atomic_set(&newf->count, 1); |
593 | 593 | ||
594 | spin_lock_init(&newf->file_lock); | 594 | spin_lock_init(&newf->file_lock); |
595 | fdt = files_fdtable(newf); | 595 | fdt = &newf->fdtab; |
596 | fdt->next_fd = 0; | 596 | fdt->next_fd = 0; |
597 | fdt->max_fds = NR_OPEN_DEFAULT; | 597 | fdt->max_fds = NR_OPEN_DEFAULT; |
598 | fdt->max_fdset = __FD_SETSIZE; | 598 | fdt->max_fdset = __FD_SETSIZE; |
599 | fdt->close_on_exec = &newf->close_on_exec_init; | 599 | fdt->close_on_exec = &newf->close_on_exec_init; |
600 | fdt->open_fds = &newf->open_fds_init; | 600 | fdt->open_fds = &newf->open_fds_init; |
601 | fdt->fd = &newf->fd_array[0]; | 601 | fdt->fd = &newf->fd_array[0]; |
602 | INIT_RCU_HEAD(&fdt->rcu); | ||
603 | fdt->free_files = NULL; | ||
604 | fdt->next = NULL; | ||
605 | rcu_assign_pointer(newf->fdt, fdt); | ||
602 | out: | 606 | out: |
603 | return newf; | 607 | return newf; |
604 | } | 608 | } |
@@ -637,7 +641,7 @@ static int copy_files(unsigned long clone_flags, struct task_struct * tsk) | |||
637 | old_fdt = files_fdtable(oldf); | 641 | old_fdt = files_fdtable(oldf); |
638 | new_fdt = files_fdtable(newf); | 642 | new_fdt = files_fdtable(newf); |
639 | size = old_fdt->max_fdset; | 643 | size = old_fdt->max_fdset; |
640 | open_files = count_open_files(oldf, old_fdt->max_fdset); | 644 | open_files = count_open_files(old_fdt); |
641 | expand = 0; | 645 | expand = 0; |
642 | 646 | ||
643 | /* | 647 | /* |
@@ -661,7 +665,14 @@ static int copy_files(unsigned long clone_flags, struct task_struct * tsk) | |||
661 | spin_unlock(&newf->file_lock); | 665 | spin_unlock(&newf->file_lock); |
662 | if (error < 0) | 666 | if (error < 0) |
663 | goto out_release; | 667 | goto out_release; |
668 | new_fdt = files_fdtable(newf); | ||
669 | /* | ||
670 | * Reacquire the oldf lock and a pointer to its fd table | ||
671 | * who knows it may have a new bigger fd table. We need | ||
672 | * the latest pointer. | ||
673 | */ | ||
664 | spin_lock(&oldf->file_lock); | 674 | spin_lock(&oldf->file_lock); |
675 | old_fdt = files_fdtable(oldf); | ||
665 | } | 676 | } |
666 | 677 | ||
667 | old_fds = old_fdt->fd; | 678 | old_fds = old_fdt->fd; |
@@ -683,7 +694,7 @@ static int copy_files(unsigned long clone_flags, struct task_struct * tsk) | |||
683 | */ | 694 | */ |
684 | FD_CLR(open_files - i, new_fdt->open_fds); | 695 | FD_CLR(open_files - i, new_fdt->open_fds); |
685 | } | 696 | } |
686 | *new_fds++ = f; | 697 | rcu_assign_pointer(*new_fds++, f); |
687 | } | 698 | } |
688 | spin_unlock(&oldf->file_lock); | 699 | spin_unlock(&oldf->file_lock); |
689 | 700 | ||