Skip to contentSkip to conversation

android: task_get_unused_fd_flags: fix the wrong usage of tsk->signal

PATCH In review Oleg Nesterov 2 participants 2 messages Jan 18, 2009 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 android: task_get_unused_fd_flags: fix the wrong usage of tsk->signal

Compile tested.

task_struct->signal is not protected by RCU, the code is bogus. Change the code to take ->siglock to pin ->signal.

drivers/staging/android/binder.c renamed from drivers/staging/android/binder.c~ANDROID +5 -5
@@ -319,6 +319,7 @@ int task_get_unused_fd_flags(struct task
 	int fd, error;
 	struct fdtable *fdt;
 	unsigned long rlim_cur;
+	unsigned long irqs;
 
 	if (files == NULL)
 		return -ESRCH;
@@ -335,12 +336,11 @@ repeat:
 	 * N.B. For clone tasks sharing a files structure, this test
 	 * will limit the total number of files that can be opened.
 	 */
-	rcu_read_lock();
-	if (tsk->signal)
+	rlim_cur = 0;
+	if (lock_task_sighand(tsk, &irqs)) {
 		rlim_cur = tsk->signal->rlim[RLIMIT_NOFILE].rlim_cur;
-	else
-		rlim_cur = 0;
-	rcu_read_unlock();
+		unlock_task_sighand(tsk, &irqs);
+	}
 	if (fd >= rlim_cur)
 		goto out;
 
#1 lore raw
Quoted 6 lines · Oleg Nesterov

Compile tested.

task_struct->signal is not protected by RCU, the code is bogus. Change the code to take ->siglock to pin ->signal.

Thanks for the fix, I'll queue it up next week.

greg k-h