Commit 56007cae94f349387c088e738c7dcb6bc513063b
1 parent
1983e781da
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
move put_unused_fd() and fd_install() to fs/file.c
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Showing 2 changed files with 44 additions and 44 deletions Side-by-side Diff
fs/file.c
... | ... | @@ -569,4 +569,48 @@ |
569 | 569 | return __alloc_fd(current->files, 0, rlimit(RLIMIT_NOFILE), flags); |
570 | 570 | } |
571 | 571 | EXPORT_SYMBOL(get_unused_fd_flags); |
572 | + | |
573 | +static void __put_unused_fd(struct files_struct *files, unsigned int fd) | |
574 | +{ | |
575 | + struct fdtable *fdt = files_fdtable(files); | |
576 | + __clear_open_fd(fd, fdt); | |
577 | + if (fd < files->next_fd) | |
578 | + files->next_fd = fd; | |
579 | +} | |
580 | + | |
581 | +void put_unused_fd(unsigned int fd) | |
582 | +{ | |
583 | + struct files_struct *files = current->files; | |
584 | + spin_lock(&files->file_lock); | |
585 | + __put_unused_fd(files, fd); | |
586 | + spin_unlock(&files->file_lock); | |
587 | +} | |
588 | + | |
589 | +EXPORT_SYMBOL(put_unused_fd); | |
590 | + | |
591 | +/* | |
592 | + * Install a file pointer in the fd array. | |
593 | + * | |
594 | + * The VFS is full of places where we drop the files lock between | |
595 | + * setting the open_fds bitmap and installing the file in the file | |
596 | + * array. At any such point, we are vulnerable to a dup2() race | |
597 | + * installing a file in the array before us. We need to detect this and | |
598 | + * fput() the struct file we are about to overwrite in this case. | |
599 | + * | |
600 | + * It should never happen - if we allow dup2() do it, _really_ bad things | |
601 | + * will follow. | |
602 | + */ | |
603 | + | |
604 | +void fd_install(unsigned int fd, struct file *file) | |
605 | +{ | |
606 | + struct files_struct *files = current->files; | |
607 | + struct fdtable *fdt; | |
608 | + spin_lock(&files->file_lock); | |
609 | + fdt = files_fdtable(files); | |
610 | + BUG_ON(fdt->fd[fd] != NULL); | |
611 | + rcu_assign_pointer(fdt->fd[fd], file); | |
612 | + spin_unlock(&files->file_lock); | |
613 | +} | |
614 | + | |
615 | +EXPORT_SYMBOL(fd_install); |
fs/open.c
... | ... | @@ -803,50 +803,6 @@ |
803 | 803 | } |
804 | 804 | EXPORT_SYMBOL(dentry_open); |
805 | 805 | |
806 | -static void __put_unused_fd(struct files_struct *files, unsigned int fd) | |
807 | -{ | |
808 | - struct fdtable *fdt = files_fdtable(files); | |
809 | - __clear_open_fd(fd, fdt); | |
810 | - if (fd < files->next_fd) | |
811 | - files->next_fd = fd; | |
812 | -} | |
813 | - | |
814 | -void put_unused_fd(unsigned int fd) | |
815 | -{ | |
816 | - struct files_struct *files = current->files; | |
817 | - spin_lock(&files->file_lock); | |
818 | - __put_unused_fd(files, fd); | |
819 | - spin_unlock(&files->file_lock); | |
820 | -} | |
821 | - | |
822 | -EXPORT_SYMBOL(put_unused_fd); | |
823 | - | |
824 | -/* | |
825 | - * Install a file pointer in the fd array. | |
826 | - * | |
827 | - * The VFS is full of places where we drop the files lock between | |
828 | - * setting the open_fds bitmap and installing the file in the file | |
829 | - * array. At any such point, we are vulnerable to a dup2() race | |
830 | - * installing a file in the array before us. We need to detect this and | |
831 | - * fput() the struct file we are about to overwrite in this case. | |
832 | - * | |
833 | - * It should never happen - if we allow dup2() do it, _really_ bad things | |
834 | - * will follow. | |
835 | - */ | |
836 | - | |
837 | -void fd_install(unsigned int fd, struct file *file) | |
838 | -{ | |
839 | - struct files_struct *files = current->files; | |
840 | - struct fdtable *fdt; | |
841 | - spin_lock(&files->file_lock); | |
842 | - fdt = files_fdtable(files); | |
843 | - BUG_ON(fdt->fd[fd] != NULL); | |
844 | - rcu_assign_pointer(fdt->fd[fd], file); | |
845 | - spin_unlock(&files->file_lock); | |
846 | -} | |
847 | - | |
848 | -EXPORT_SYMBOL(fd_install); | |
849 | - | |
850 | 806 | static inline int build_open_flags(int flags, umode_t mode, struct open_flags *op) |
851 | 807 | { |
852 | 808 | int lookup_flags = 0; |