[PATCH v1] vt_ioctl: fix potential spectre v1 in VT_DISALLOCATE

Xiaomeng Tong posted 1 patch 4 years, 4 months ago
There is a newer version of this series
drivers/tty/vt/vt_ioctl.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
[PATCH v1] vt_ioctl: fix potential spectre v1 in VT_DISALLOCATE
Posted by Xiaomeng Tong 4 years, 4 months ago
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. Also, the code style is adjusted as suggested by Jiri.

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

diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index 580136986..8c685b501 100644
--- a/drivers/tty/vt/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
@@ -898,11 +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);
-		break;
+			break;
+		}
+
+		arg = array_index_nospec(arg - 1, MAX_NR_CONSOLES);
+		return vt_disallocate(arg);
 
 	case VT_RESIZE:
 	{
-- 
2.17.1

Re: [PATCH v1] vt_ioctl: fix potential spectre v1 in VT_DISALLOCATE
Posted by Jiri Slaby 4 years, 4 months ago
On 22. 02. 22, 8:39, 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. Also, the code style is adjusted as suggested by Jiri.
> 
> Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>

Reviewed-by: Jiri Slaby <jirislaby@kernel.org>

> ---
>   drivers/tty/vt/vt_ioctl.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
> index 580136986..8c685b501 100644
> --- a/drivers/tty/vt/vt_ioctl.c
> +++ b/drivers/tty/vt/vt_ioctl.c
> @@ -898,11 +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);
> -		break;
> +			break;
> +		}
> +
> +		arg = array_index_nospec(arg - 1, MAX_NR_CONSOLES);
> +		return vt_disallocate(arg);
>   
>   	case VT_RESIZE:
>   	{


-- 
js
suse labs
Re: [PATCH v1] vt_ioctl: fix potential spectre v1 in VT_DISALLOCATE
Posted by Xiaomeng Tong 4 years, 4 months ago
On Tue, 22 Feb 2022 09:00:08 +0100, Jiri Slaby wrote:
> Reviewed-by: Jiri Slaby <jirislaby@kernel.org>

Already added in Patch v2, thanks!

Best regards,
--
Xiaomeng Tong