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

tty: vt: push console lock from tioclinux() down to 2 functions

Avoid costly user copies under the console lock. So push the lock down
from tioclinux() to sel_loadlut() and set_vesa_blanking().

It is now obvious what is actually protected.

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Tested-by: Helge Deller <deller@gmx.de> # parisc STI console
Link: https://lore.kernel.org/r/20240122110401.7289-7-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
d321cd13 a0b8a168

+14 -10
+9 -2
drivers/tty/vt/selection.c
··· 113 113 * sel_loadlut() - load the LUT table 114 114 * @lut: user table 115 115 * 116 - * Load the LUT table from user space. The caller must hold the console 117 - * lock. Make a temporary copy so a partial update doesn't make a mess. 116 + * Load the LUT table from user space. Make a temporary copy so a partial 117 + * update doesn't make a mess. 118 + * 119 + * Locking: The console lock is acquired. 118 120 */ 119 121 int sel_loadlut(u32 __user *lut) 120 122 { 121 123 u32 tmplut[ARRAY_SIZE(inwordLut)]; 124 + 122 125 if (copy_from_user(tmplut, lut, sizeof(inwordLut))) 123 126 return -EFAULT; 127 + 128 + console_lock(); 124 129 memcpy(inwordLut, tmplut, sizeof(inwordLut)); 130 + console_unlock(); 131 + 125 132 return 0; 126 133 } 127 134
+5 -8
drivers/tty/vt/vt.c
··· 3162 3162 case TIOCL_SELLOADLUT: 3163 3163 if (!capable(CAP_SYS_ADMIN)) 3164 3164 return -EPERM; 3165 - console_lock(); 3166 - ret = sel_loadlut(param_aligned32); 3167 - console_unlock(); 3168 - break; 3165 + return sel_loadlut(param_aligned32); 3169 3166 case TIOCL_GETSHIFTSTATE: 3170 3167 /* 3171 3168 * Make it possible to react to Shift+Mousebutton. Note that ··· 3178 3181 console_unlock(); 3179 3182 return put_user(data, p); 3180 3183 case TIOCL_SETVESABLANK: 3181 - console_lock(); 3182 - ret = set_vesa_blanking(param); 3183 - console_unlock(); 3184 - break; 3184 + return set_vesa_blanking(param); 3185 3185 case TIOCL_GETKMSGREDIRECT: 3186 3186 data = vt_get_kmsg_redirect(); 3187 3187 return put_user(data, p); ··· 4264 4270 if (get_user(mode, mode_user)) 4265 4271 return -EFAULT; 4266 4272 4273 + console_lock(); 4267 4274 vesa_blank_mode = (mode < 4) ? mode : 0; 4275 + console_unlock(); 4276 + 4268 4277 return 0; 4269 4278 } 4270 4279