public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -fixes v2] riscv: Fix out-of-bounds when accessing Andes per hart vendor extension array
@ 2024-08-14 19:26 Alexandre Ghiti
  2024-08-14 20:21 ` Charlie Jenkins
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Alexandre Ghiti @ 2024-08-14 19:26 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Charlie Jenkins,
	Andy Chiu, Alexandre Ghiti, linux-riscv, linux-kernel

The out-of-bounds access is reported by UBSAN:

[    0.000000] UBSAN: array-index-out-of-bounds in ../arch/riscv/kernel/vendor_extensions.c:41:66
[    0.000000] index -1 is out of range for type 'riscv_isavendorinfo [32]'
[    0.000000] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.11.0-rc2ubuntu-defconfig #2
[    0.000000] Hardware name: riscv-virtio,qemu (DT)
[    0.000000] Call Trace:
[    0.000000] [<ffffffff94e078ba>] dump_backtrace+0x32/0x40
[    0.000000] [<ffffffff95c83c1a>] show_stack+0x38/0x44
[    0.000000] [<ffffffff95c94614>] dump_stack_lvl+0x70/0x9c
[    0.000000] [<ffffffff95c94658>] dump_stack+0x18/0x20
[    0.000000] [<ffffffff95c8bbb2>] ubsan_epilogue+0x10/0x46
[    0.000000] [<ffffffff95485a82>] __ubsan_handle_out_of_bounds+0x94/0x9c
[    0.000000] [<ffffffff94e09442>] __riscv_isa_vendor_extension_available+0x90/0x92
[    0.000000] [<ffffffff94e043b6>] riscv_cpufeature_patch_func+0xc4/0x148
[    0.000000] [<ffffffff94e035f8>] _apply_alternatives+0x42/0x50
[    0.000000] [<ffffffff95e04196>] apply_boot_alternatives+0x3c/0x100
[    0.000000] [<ffffffff95e05b52>] setup_arch+0x85a/0x8bc
[    0.000000] [<ffffffff95e00ca0>] start_kernel+0xa4/0xfb6

The dereferencing using cpu should actually not happen, so remove it.

Fixes: 23c996fc2bc1 ("riscv: Extend cpufeature.c to detect vendor extensions")
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
---
 arch/riscv/kernel/vendor_extensions.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/vendor_extensions.c b/arch/riscv/kernel/vendor_extensions.c
index b6c1e7b5d34b..a8126d118341 100644
--- a/arch/riscv/kernel/vendor_extensions.c
+++ b/arch/riscv/kernel/vendor_extensions.c
@@ -38,7 +38,7 @@ bool __riscv_isa_vendor_extension_available(int cpu, unsigned long vendor, unsig
 	#ifdef CONFIG_RISCV_ISA_VENDOR_EXT_ANDES
 	case ANDES_VENDOR_ID:
 		bmap = &riscv_isa_vendor_ext_list_andes.all_harts_isa_bitmap;
-		cpu_bmap = &riscv_isa_vendor_ext_list_andes.per_hart_isa_bitmap[cpu];
+		cpu_bmap = riscv_isa_vendor_ext_list_andes.per_hart_isa_bitmap;
 		break;
 	#endif
 	default:
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH -fixes v2] riscv: Fix out-of-bounds when accessing Andes per hart vendor extension array
  2024-08-14 19:26 [PATCH -fixes v2] riscv: Fix out-of-bounds when accessing Andes per hart vendor extension array Alexandre Ghiti
@ 2024-08-14 20:21 ` Charlie Jenkins
  2024-08-14 22:26 ` Conor Dooley
  2024-08-15 17:50 ` patchwork-bot+linux-riscv
  2 siblings, 0 replies; 5+ messages in thread
From: Charlie Jenkins @ 2024-08-14 20:21 UTC (permalink / raw)
  To: Alexandre Ghiti
  Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Andy Chiu, linux-riscv,
	linux-kernel

On Wed, Aug 14, 2024 at 09:26:19PM +0200, Alexandre Ghiti wrote:
> The out-of-bounds access is reported by UBSAN:
> 
> [    0.000000] UBSAN: array-index-out-of-bounds in ../arch/riscv/kernel/vendor_extensions.c:41:66
> [    0.000000] index -1 is out of range for type 'riscv_isavendorinfo [32]'
> [    0.000000] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.11.0-rc2ubuntu-defconfig #2
> [    0.000000] Hardware name: riscv-virtio,qemu (DT)
> [    0.000000] Call Trace:
> [    0.000000] [<ffffffff94e078ba>] dump_backtrace+0x32/0x40
> [    0.000000] [<ffffffff95c83c1a>] show_stack+0x38/0x44
> [    0.000000] [<ffffffff95c94614>] dump_stack_lvl+0x70/0x9c
> [    0.000000] [<ffffffff95c94658>] dump_stack+0x18/0x20
> [    0.000000] [<ffffffff95c8bbb2>] ubsan_epilogue+0x10/0x46
> [    0.000000] [<ffffffff95485a82>] __ubsan_handle_out_of_bounds+0x94/0x9c
> [    0.000000] [<ffffffff94e09442>] __riscv_isa_vendor_extension_available+0x90/0x92
> [    0.000000] [<ffffffff94e043b6>] riscv_cpufeature_patch_func+0xc4/0x148
> [    0.000000] [<ffffffff94e035f8>] _apply_alternatives+0x42/0x50
> [    0.000000] [<ffffffff95e04196>] apply_boot_alternatives+0x3c/0x100
> [    0.000000] [<ffffffff95e05b52>] setup_arch+0x85a/0x8bc
> [    0.000000] [<ffffffff95e00ca0>] start_kernel+0xa4/0xfb6
> 
> The dereferencing using cpu should actually not happen, so remove it.
> 
> Fixes: 23c996fc2bc1 ("riscv: Extend cpufeature.c to detect vendor extensions")
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> ---
>  arch/riscv/kernel/vendor_extensions.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/kernel/vendor_extensions.c b/arch/riscv/kernel/vendor_extensions.c
> index b6c1e7b5d34b..a8126d118341 100644
> --- a/arch/riscv/kernel/vendor_extensions.c
> +++ b/arch/riscv/kernel/vendor_extensions.c
> @@ -38,7 +38,7 @@ bool __riscv_isa_vendor_extension_available(int cpu, unsigned long vendor, unsig
>  	#ifdef CONFIG_RISCV_ISA_VENDOR_EXT_ANDES
>  	case ANDES_VENDOR_ID:
>  		bmap = &riscv_isa_vendor_ext_list_andes.all_harts_isa_bitmap;
> -		cpu_bmap = &riscv_isa_vendor_ext_list_andes.per_hart_isa_bitmap[cpu];
> +		cpu_bmap = riscv_isa_vendor_ext_list_andes.per_hart_isa_bitmap;
>  		break;
>  	#endif
>  	default:
> -- 
> 2.39.2
> 

Thanks!

Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
Tested-by: Charlie Jenkins <charlie@rivosinc.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -fixes v2] riscv: Fix out-of-bounds when accessing Andes per hart vendor extension array
  2024-08-14 19:26 [PATCH -fixes v2] riscv: Fix out-of-bounds when accessing Andes per hart vendor extension array Alexandre Ghiti
  2024-08-14 20:21 ` Charlie Jenkins
@ 2024-08-14 22:26 ` Conor Dooley
  2024-08-15  5:23   ` Alexandre Ghiti
  2024-08-15 17:50 ` patchwork-bot+linux-riscv
  2 siblings, 1 reply; 5+ messages in thread
From: Conor Dooley @ 2024-08-14 22:26 UTC (permalink / raw)
  To: Alexandre Ghiti
  Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Charlie Jenkins,
	Andy Chiu, linux-riscv, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2444 bytes --]

On Wed, Aug 14, 2024 at 09:26:19PM +0200, Alexandre Ghiti wrote:
> The out-of-bounds access is reported by UBSAN:
> 
> [    0.000000] UBSAN: array-index-out-of-bounds in ../arch/riscv/kernel/vendor_extensions.c:41:66
> [    0.000000] index -1 is out of range for type 'riscv_isavendorinfo [32]'
> [    0.000000] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.11.0-rc2ubuntu-defconfig #2
> [    0.000000] Hardware name: riscv-virtio,qemu (DT)
> [    0.000000] Call Trace:
> [    0.000000] [<ffffffff94e078ba>] dump_backtrace+0x32/0x40
> [    0.000000] [<ffffffff95c83c1a>] show_stack+0x38/0x44
> [    0.000000] [<ffffffff95c94614>] dump_stack_lvl+0x70/0x9c
> [    0.000000] [<ffffffff95c94658>] dump_stack+0x18/0x20
> [    0.000000] [<ffffffff95c8bbb2>] ubsan_epilogue+0x10/0x46
> [    0.000000] [<ffffffff95485a82>] __ubsan_handle_out_of_bounds+0x94/0x9c
> [    0.000000] [<ffffffff94e09442>] __riscv_isa_vendor_extension_available+0x90/0x92
> [    0.000000] [<ffffffff94e043b6>] riscv_cpufeature_patch_func+0xc4/0x148
> [    0.000000] [<ffffffff94e035f8>] _apply_alternatives+0x42/0x50
> [    0.000000] [<ffffffff95e04196>] apply_boot_alternatives+0x3c/0x100
> [    0.000000] [<ffffffff95e05b52>] setup_arch+0x85a/0x8bc
> [    0.000000] [<ffffffff95e00ca0>] start_kernel+0xa4/0xfb6
> 
> The dereferencing using cpu should actually not happen, so remove it.
> 
> Fixes: 23c996fc2bc1 ("riscv: Extend cpufeature.c to detect vendor extensions")
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> ---

You're missing a changelog here, which is doubly important when you drop
tags provided to you on an earlier version.

>  arch/riscv/kernel/vendor_extensions.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/kernel/vendor_extensions.c b/arch/riscv/kernel/vendor_extensions.c
> index b6c1e7b5d34b..a8126d118341 100644
> --- a/arch/riscv/kernel/vendor_extensions.c
> +++ b/arch/riscv/kernel/vendor_extensions.c
> @@ -38,7 +38,7 @@ bool __riscv_isa_vendor_extension_available(int cpu, unsigned long vendor, unsig
>  	#ifdef CONFIG_RISCV_ISA_VENDOR_EXT_ANDES
>  	case ANDES_VENDOR_ID:
>  		bmap = &riscv_isa_vendor_ext_list_andes.all_harts_isa_bitmap;
> -		cpu_bmap = &riscv_isa_vendor_ext_list_andes.per_hart_isa_bitmap[cpu];
> +		cpu_bmap = riscv_isa_vendor_ext_list_andes.per_hart_isa_bitmap;
>  		break;
>  	#endif
>  	default:
> -- 
> 2.39.2
> 
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -fixes v2] riscv: Fix out-of-bounds when accessing Andes per hart vendor extension array
  2024-08-14 22:26 ` Conor Dooley
@ 2024-08-15  5:23   ` Alexandre Ghiti
  0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Ghiti @ 2024-08-15  5:23 UTC (permalink / raw)
  To: Conor Dooley
  Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Charlie Jenkins,
	Andy Chiu, linux-riscv, linux-kernel

On Thu, Aug 15, 2024 at 12:26 AM Conor Dooley <conor@kernel.org> wrote:
>
> On Wed, Aug 14, 2024 at 09:26:19PM +0200, Alexandre Ghiti wrote:
> > The out-of-bounds access is reported by UBSAN:
> >
> > [    0.000000] UBSAN: array-index-out-of-bounds in ../arch/riscv/kernel/vendor_extensions.c:41:66
> > [    0.000000] index -1 is out of range for type 'riscv_isavendorinfo [32]'
> > [    0.000000] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.11.0-rc2ubuntu-defconfig #2
> > [    0.000000] Hardware name: riscv-virtio,qemu (DT)
> > [    0.000000] Call Trace:
> > [    0.000000] [<ffffffff94e078ba>] dump_backtrace+0x32/0x40
> > [    0.000000] [<ffffffff95c83c1a>] show_stack+0x38/0x44
> > [    0.000000] [<ffffffff95c94614>] dump_stack_lvl+0x70/0x9c
> > [    0.000000] [<ffffffff95c94658>] dump_stack+0x18/0x20
> > [    0.000000] [<ffffffff95c8bbb2>] ubsan_epilogue+0x10/0x46
> > [    0.000000] [<ffffffff95485a82>] __ubsan_handle_out_of_bounds+0x94/0x9c
> > [    0.000000] [<ffffffff94e09442>] __riscv_isa_vendor_extension_available+0x90/0x92
> > [    0.000000] [<ffffffff94e043b6>] riscv_cpufeature_patch_func+0xc4/0x148
> > [    0.000000] [<ffffffff94e035f8>] _apply_alternatives+0x42/0x50
> > [    0.000000] [<ffffffff95e04196>] apply_boot_alternatives+0x3c/0x100
> > [    0.000000] [<ffffffff95e05b52>] setup_arch+0x85a/0x8bc
> > [    0.000000] [<ffffffff95e00ca0>] start_kernel+0xa4/0xfb6
> >
> > The dereferencing using cpu should actually not happen, so remove it.
> >
> > Fixes: 23c996fc2bc1 ("riscv: Extend cpufeature.c to detect vendor extensions")
> > Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> > ---
>
> You're missing a changelog here, which is doubly important when you drop
> tags provided to you on an earlier version.

Yes, you're right.

>
> >  arch/riscv/kernel/vendor_extensions.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/riscv/kernel/vendor_extensions.c b/arch/riscv/kernel/vendor_extensions.c
> > index b6c1e7b5d34b..a8126d118341 100644
> > --- a/arch/riscv/kernel/vendor_extensions.c
> > +++ b/arch/riscv/kernel/vendor_extensions.c
> > @@ -38,7 +38,7 @@ bool __riscv_isa_vendor_extension_available(int cpu, unsigned long vendor, unsig
> >       #ifdef CONFIG_RISCV_ISA_VENDOR_EXT_ANDES
> >       case ANDES_VENDOR_ID:
> >               bmap = &riscv_isa_vendor_ext_list_andes.all_harts_isa_bitmap;
> > -             cpu_bmap = &riscv_isa_vendor_ext_list_andes.per_hart_isa_bitmap[cpu];
> > +             cpu_bmap = riscv_isa_vendor_ext_list_andes.per_hart_isa_bitmap;
> >               break;
> >       #endif
> >       default:
> > --
> > 2.39.2
> >
> >

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -fixes v2] riscv: Fix out-of-bounds when accessing Andes per hart vendor extension array
  2024-08-14 19:26 [PATCH -fixes v2] riscv: Fix out-of-bounds when accessing Andes per hart vendor extension array Alexandre Ghiti
  2024-08-14 20:21 ` Charlie Jenkins
  2024-08-14 22:26 ` Conor Dooley
@ 2024-08-15 17:50 ` patchwork-bot+linux-riscv
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+linux-riscv @ 2024-08-15 17:50 UTC (permalink / raw)
  To: Alexandre Ghiti
  Cc: linux-riscv, paul.walmsley, palmer, aou, charlie, andy.chiu,
	linux-kernel

Hello:

This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:

On Wed, 14 Aug 2024 21:26:19 +0200 you wrote:
> The out-of-bounds access is reported by UBSAN:
> 
> [    0.000000] UBSAN: array-index-out-of-bounds in ../arch/riscv/kernel/vendor_extensions.c:41:66
> [    0.000000] index -1 is out of range for type 'riscv_isavendorinfo [32]'
> [    0.000000] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.11.0-rc2ubuntu-defconfig #2
> [    0.000000] Hardware name: riscv-virtio,qemu (DT)
> [    0.000000] Call Trace:
> [    0.000000] [<ffffffff94e078ba>] dump_backtrace+0x32/0x40
> [    0.000000] [<ffffffff95c83c1a>] show_stack+0x38/0x44
> [    0.000000] [<ffffffff95c94614>] dump_stack_lvl+0x70/0x9c
> [    0.000000] [<ffffffff95c94658>] dump_stack+0x18/0x20
> [    0.000000] [<ffffffff95c8bbb2>] ubsan_epilogue+0x10/0x46
> [    0.000000] [<ffffffff95485a82>] __ubsan_handle_out_of_bounds+0x94/0x9c
> [    0.000000] [<ffffffff94e09442>] __riscv_isa_vendor_extension_available+0x90/0x92
> [    0.000000] [<ffffffff94e043b6>] riscv_cpufeature_patch_func+0xc4/0x148
> [    0.000000] [<ffffffff94e035f8>] _apply_alternatives+0x42/0x50
> [    0.000000] [<ffffffff95e04196>] apply_boot_alternatives+0x3c/0x100
> [    0.000000] [<ffffffff95e05b52>] setup_arch+0x85a/0x8bc
> [    0.000000] [<ffffffff95e00ca0>] start_kernel+0xa4/0xfb6
> 
> [...]

Here is the summary with links:
  - [-fixes,v2] riscv: Fix out-of-bounds when accessing Andes per hart vendor extension array
    https://git.kernel.org/riscv/c/b3f10d9b81e5

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-08-15 17:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-14 19:26 [PATCH -fixes v2] riscv: Fix out-of-bounds when accessing Andes per hart vendor extension array Alexandre Ghiti
2024-08-14 20:21 ` Charlie Jenkins
2024-08-14 22:26 ` Conor Dooley
2024-08-15  5:23   ` Alexandre Ghiti
2024-08-15 17:50 ` patchwork-bot+linux-riscv

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox