[PATCH] vt_ioctl: fix potential spectre v1 in VT_DISALLOCATE

From: Xiaomeng Tong
Date: Mon Feb 21 2022 - 22:57:27 EST


In VT_ACTIVATE an almost identical code path has been patched
with array_index_nospec. In the VT_DISALLOCATE path, the arg is
the user input from a system call argument and lately used as a index
for vc_cons[index].d access, which can be reached through path like
vt_disallocate->vc_busy or vt_disallocate->vc_deallocate.
For consistency both code paths should have the same mitigations
applied.

Signed-off-by: Xiaomeng Tong <xiam0nd.tong@xxxxxxxxx>
---
drivers/tty/vt/vt_ioctl.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index 580136986..acd53c1c9 100644
--- a/drivers/tty/vt/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
@@ -898,10 +898,13 @@ int vt_ioctl(struct tty_struct *tty,
if (arg > MAX_NR_CONSOLES)
return -ENXIO;

- if (arg == 0)
+ if (arg == 0) {
vt_disallocate_all();
- else
- return vt_disallocate(--arg);
+ } else {
+ --arg;
+ arg = array_index_nospec(arg, MAX_NR_CONSOLES);
+ return vt_disallocate(arg);
+ }
break;

case VT_RESIZE:
--
2.17.1