aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2012-08-15 21:06:33 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2012-09-26 21:08:55 -0400
commitf869e8a7f753e3fd43d6483e796774776f645edb (patch)
tree3b215f30a040812eb7488bd4596a5c3ae0b50e51
parent56007cae94f349387c088e738c7dcb6bc513063b (diff)
expose a low-level variant of fd_install() for binder
Similar situation to that of __alloc_fd(); do not use unless you really have to. You should not touch any descriptor table other than your own; it's a sure sign of a really bad API design. As with __alloc_fd(), you *must* use a first-class reference to struct files_struct; something obtained by get_files_struct(some task) (let alone direct task->files) will not do. It must be either current->files, or obtained by get_files_struct(current) by the owner of that sucker and given to you. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--drivers/staging/android/binder.c13
-rw-r--r--fs/file.c16
-rw-r--r--include/linux/fdtable.h2
3 files changed, 18 insertions, 13 deletions
diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c
index 4946d282a35c..9e1a98a360d4 100644
--- a/drivers/staging/android/binder.c
+++ b/drivers/staging/android/binder.c
@@ -386,17 +386,8 @@ int task_get_unused_fd_flags(struct binder_proc *proc, int flags)
386static void task_fd_install( 386static void task_fd_install(
387 struct binder_proc *proc, unsigned int fd, struct file *file) 387 struct binder_proc *proc, unsigned int fd, struct file *file)
388{ 388{
389 struct files_struct *files = proc->files; 389 if (proc->files)
390 struct fdtable *fdt; 390 __fd_install(proc->files, fd, file);
391
392 if (files == NULL)
393 return;
394
395 spin_lock(&files->file_lock);
396 fdt = files_fdtable(files);
397 BUG_ON(fdt->fd[fd] != NULL);
398 rcu_assign_pointer(fdt->fd[fd], file);
399 spin_unlock(&files->file_lock);
400} 391}
401 392
402/* 393/*
diff --git a/fs/file.c b/fs/file.c
index 78cf88f2a0e8..0d1bf0515111 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -599,11 +599,18 @@ EXPORT_SYMBOL(put_unused_fd);
599 * 599 *
600 * It should never happen - if we allow dup2() do it, _really_ bad things 600 * It should never happen - if we allow dup2() do it, _really_ bad things
601 * will follow. 601 * will follow.
602 *
603 * NOTE: __fd_install() variant is really, really low-level; don't
604 * use it unless you are forced to by truly lousy API shoved down
605 * your throat. 'files' *MUST* be either current->files or obtained
606 * by get_files_struct(current) done by whoever had given it to you,
607 * or really bad things will happen. Normally you want to use
608 * fd_install() instead.
602 */ 609 */
603 610
604void fd_install(unsigned int fd, struct file *file) 611void __fd_install(struct files_struct *files, unsigned int fd,
612 struct file *file)
605{ 613{
606 struct files_struct *files = current->files;
607 struct fdtable *fdt; 614 struct fdtable *fdt;
608 spin_lock(&files->file_lock); 615 spin_lock(&files->file_lock);
609 fdt = files_fdtable(files); 616 fdt = files_fdtable(files);
@@ -612,4 +619,9 @@ void fd_install(unsigned int fd, struct file *file)
612 spin_unlock(&files->file_lock); 619 spin_unlock(&files->file_lock);
613} 620}
614 621
622void fd_install(unsigned int fd, struct file *file)
623{
624 __fd_install(current->files, fd, file);
625}
626
615EXPORT_SYMBOL(fd_install); 627EXPORT_SYMBOL(fd_install);
diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
index 3855f4febe70..59d4fc7f10c8 100644
--- a/include/linux/fdtable.h
+++ b/include/linux/fdtable.h
@@ -121,6 +121,8 @@ struct files_struct *dup_fd(struct files_struct *, int *);
121 121
122extern int __alloc_fd(struct files_struct *files, 122extern int __alloc_fd(struct files_struct *files,
123 unsigned start, unsigned end, unsigned flags); 123 unsigned start, unsigned end, unsigned flags);
124extern void __fd_install(struct files_struct *files,
125 unsigned int fd, struct file *file);
124 126
125extern struct kmem_cache *files_cachep; 127extern struct kmem_cache *files_cachep;
126 128