fix console change race exposed by CFS

The new behaviour of CFS exposes a race which occurs if a switch is
requested when vt_mode.mode is VT_PROCESS.

The process with vc->vt_pid is signaled before vc->vt_newvt is set.
This causes the switch to fail when triggered by the monitoing process
because the target is still -1.

[ If the signal sending fails, the subsequent "reset_vc(vc)" will then
reset vt_newvt to -1, so this works for that case too. - Linus ]

Signed-off-by: Jan Lübbe <jluebbe@lasnet.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Jan Lübbe and committed by Linus Torvalds a64314e6 ed7fdff5

+5 -2
+5 -2
drivers/char/vt_ioctl.c
··· 1208 /* 1209 * Send the signal as privileged - kill_pid() will 1210 * tell us if the process has gone or something else 1211 - * is awry 1212 */ 1213 if (kill_pid(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) { 1214 /* 1215 * It worked. Mark the vt to switch to and 1216 * return. The process needs to send us a 1217 * VT_RELDISP ioctl to complete the switch. 1218 */ 1219 - vc->vt_newvt = new_vc->vc_num; 1220 return; 1221 } 1222
··· 1208 /* 1209 * Send the signal as privileged - kill_pid() will 1210 * tell us if the process has gone or something else 1211 + * is awry. 1212 + * 1213 + * We need to set vt_newvt *before* sending the signal or we 1214 + * have a race. 1215 */ 1216 + vc->vt_newvt = new_vc->vc_num; 1217 if (kill_pid(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) { 1218 /* 1219 * It worked. Mark the vt to switch to and 1220 * return. The process needs to send us a 1221 * VT_RELDISP ioctl to complete the switch. 1222 */ 1223 return; 1224 } 1225