Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[PATCH] vt: fix potential race in VT_WAITACTIVE handler

On a multiprocessor machine the VT_WAITACTIVE ioctl call may return 0 if
fg_console has already been updated in redraw_screen() but the console
switch itself hasn't been completed. Fix this by checking fg_console in
vt_waitactive() with the console sem held.

Signed-off-by: Michal Januszewski <spock@gentoo.org>
Acked-by: Antonino Daplas <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Michal Januszewski and committed by
Linus Torvalds
f991519c 1d64b9cb

+14 -2
+14 -2
drivers/char/vt_ioctl.c
··· 1039 1039 1040 1040 add_wait_queue(&vt_activate_queue, &wait); 1041 1041 for (;;) { 1042 - set_current_state(TASK_INTERRUPTIBLE); 1043 1042 retval = 0; 1044 - if (vt == fg_console) 1043 + 1044 + /* 1045 + * Synchronize with redraw_screen(). By acquiring the console 1046 + * semaphore we make sure that the console switch is completed 1047 + * before we return. If we didn't wait for the semaphore, we 1048 + * could return at a point where fg_console has already been 1049 + * updated, but the console switch hasn't been completed. 1050 + */ 1051 + acquire_console_sem(); 1052 + set_current_state(TASK_INTERRUPTIBLE); 1053 + if (vt == fg_console) { 1054 + release_console_sem(); 1045 1055 break; 1056 + } 1057 + release_console_sem(); 1046 1058 retval = -EINTR; 1047 1059 if (signal_pending(current)) 1048 1060 break;