Skip to content

Commit

Permalink
CHROMIUM: android: binder: Fix potential scheduling-while-atomic
Browse files Browse the repository at this point in the history
Commit f1e7f0a ("android: binder: Disable preemption while holding
the global binder lock.") re-enabled preemption around most of the sites
where calls to potentially sleeping functions were made, but missed
__alloc_fd(), which can sleep if the fdtable needs to be resized.
Re-enable preemption around __alloc_fd() as well as __fd_install() which
can now sleep in upstream kernels as of commit 8a81252 ("fs/file.c:
don't acquire files->file_lock in fd_install()").

BUG=chrome-os-partner:44012
TEST=Build and boot on Smaug.

Change-Id: I9819c4b95876f697e75b1b84810b6c520d9c33ec
Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/308582
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Riley Andrews <riandrews@google.com>
  • Loading branch information
Andrew Bresticker authored and chrome-bot committed Oct 27, 2015
1 parent 5b84f5f commit 166b45a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions drivers/staging/android/binder.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ static int task_get_unused_fd_flags(struct binder_proc *proc, int flags)
struct files_struct *files = proc->files;
unsigned long rlim_cur;
unsigned long irqs;
int ret;

if (files == NULL)
return -ESRCH;
Expand All @@ -385,7 +386,11 @@ static int task_get_unused_fd_flags(struct binder_proc *proc, int flags)
rlim_cur = task_rlimit(proc->tsk, RLIMIT_NOFILE);
unlock_task_sighand(proc->tsk, &irqs);

return __alloc_fd(files, 0, rlim_cur, flags);
preempt_enable_no_resched();
ret = __alloc_fd(files, 0, rlim_cur, flags);
preempt_disable();

return ret;
}

/*
Expand All @@ -394,8 +399,11 @@ static int task_get_unused_fd_flags(struct binder_proc *proc, int flags)
static void task_fd_install(
struct binder_proc *proc, unsigned int fd, struct file *file)
{
if (proc->files)
if (proc->files) {
preempt_enable_no_resched();
__fd_install(proc->files, fd, file);
preempt_disable();
}
}

/*
Expand Down

0 comments on commit 166b45a

Please sign in to comment.