* [PATCH] vt_ioctl: fix potential spectre v1 in VT_DISALLOCATE
@ 2022-02-22 3:56 Xiaomeng Tong
2022-02-22 6:56 ` Jiri Slaby
0 siblings, 1 reply; 3+ messages in thread
From: Xiaomeng Tong @ 2022-02-22 3:56 UTC (permalink / raw)
To: gregkh, jirislaby; +Cc: linux-kernel, Xiaomeng Tong
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@gmail.com>
---
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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] vt_ioctl: fix potential spectre v1 in VT_DISALLOCATE
2022-02-22 3:56 [PATCH] vt_ioctl: fix potential spectre v1 in VT_DISALLOCATE Xiaomeng Tong
@ 2022-02-22 6:56 ` Jiri Slaby
2022-02-23 6:47 ` Xiaomeng Tong
0 siblings, 1 reply; 3+ messages in thread
From: Jiri Slaby @ 2022-02-22 6:56 UTC (permalink / raw)
To: Xiaomeng Tong, gregkh; +Cc: linux-kernel
On 22. 02. 22, 4:56, Xiaomeng Tong wrote:
> 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@gmail.com>
> ---
> 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();
Could you add a break; here and remove the else branching completely?
> - else
> - return vt_disallocate(--arg);
> + } else {
> + --arg;
> + arg = array_index_nospec(arg, MAX_NR_CONSOLES);
You could simply do:
arg = array_index_nospec(arg - 1, MAX_NR_CONSOLES);
and remove
--arg;
completely.
> + return vt_disallocate(arg);
> + }
> break;
When you do the above, this break is superfluous.
thanks,
--
js
suse labs
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] vt_ioctl: fix potential spectre v1 in VT_DISALLOCATE
2022-02-22 6:56 ` Jiri Slaby
@ 2022-02-23 6:47 ` Xiaomeng Tong
0 siblings, 0 replies; 3+ messages in thread
From: Xiaomeng Tong @ 2022-02-23 6:47 UTC (permalink / raw)
To: jirislaby; +Cc: xiam0nd.tong, gregkh, linux-kernel
On Tue, 22 Feb 2022 07:56:13 +0100, Jiri Slaby wrote:
> Could you add a break; here and remove the else branching completely?
> ...
> You could simply do:
> arg = array_index_nospec(arg - 1, MAX_NR_CONSOLES);
> and remove
> --arg;
> completely.
Already adjusted as suggested in Patch v2, thanks!
Best regards,
--
Xiaomeng Tong
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-23 6:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-22 3:56 [PATCH] vt_ioctl: fix potential spectre v1 in VT_DISALLOCATE Xiaomeng Tong
2022-02-22 6:56 ` Jiri Slaby
2022-02-23 6:47 ` Xiaomeng Tong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®