linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] KVM: arm64: Fix possible null-ptr-deref in idregs_debug_show
@ 2024-10-24  8:33 Gaosheng Cui
  2024-10-24  9:29 ` Marc Zyngier
  0 siblings, 1 reply; 3+ messages in thread
From: Gaosheng Cui @ 2024-10-24  8:33 UTC (permalink / raw)
  To: maz, oliver.upton, joey.gouly, suzuki.poulose, yuzenghui,
	catalin.marinas, will, sebott, cuigaosheng1, wangweiyang2
  Cc: linux-arm-kernel, kvmarm

The idregs_debug_show() maybe return nullptr, we need to check desc
before dereference it to avoid possible null pointer dereferences.

Fixes: 410db103f6eb ("KVM: arm64: Make idregs debugfs iterator search sysreg table directly")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
---
 arch/arm64/kvm/sys_regs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index ff8c4e1b847e..b1c59773b9c0 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -4135,7 +4135,7 @@ static int idregs_debug_show(struct seq_file *s, void *v)
 
 	desc = idregs_debug_find(kvm, kvm->arch.idreg_debugfs_iter);
 
-	if (!desc->name)
+	if (!desc || !desc->name)
 		return 0;
 
 	seq_printf(s, "%20s:\t%016llx\n",
-- 
2.25.1



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

* Re: [PATCH -next] KVM: arm64: Fix possible null-ptr-deref in idregs_debug_show
  2024-10-24  8:33 [PATCH -next] KVM: arm64: Fix possible null-ptr-deref in idregs_debug_show Gaosheng Cui
@ 2024-10-24  9:29 ` Marc Zyngier
  2024-10-29  3:58   ` cuigaosheng
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Zyngier @ 2024-10-24  9:29 UTC (permalink / raw)
  To: Gaosheng Cui
  Cc: oliver.upton, joey.gouly, suzuki.poulose, yuzenghui,
	catalin.marinas, will, sebott, wangweiyang2, linux-arm-kernel,
	kvmarm

On Thu, 24 Oct 2024 09:33:50 +0100,
Gaosheng Cui <cuigaosheng1@huawei.com> wrote:
> 
> The idregs_debug_show() maybe return nullptr, we need to check desc
> before dereference it to avoid possible null pointer dereferences.
> 
> Fixes: 410db103f6eb ("KVM: arm64: Make idregs debugfs iterator search sysreg table directly")
> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
> ---
>  arch/arm64/kvm/sys_regs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index ff8c4e1b847e..b1c59773b9c0 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -4135,7 +4135,7 @@ static int idregs_debug_show(struct seq_file *s, void *v)
>  
>  	desc = idregs_debug_find(kvm, kvm->arch.idreg_debugfs_iter);
>  
> -	if (!desc->name)
> +	if (!desc || !desc->name)
>  		return 0;
>  
>  	seq_printf(s, "%20s:\t%016llx\n",

Can you show a case where this happens in practice?

The check for NULL is already in idregs_debug_next(), and I don't see
how this can actually be triggered.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.


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

* Re: [PATCH -next] KVM: arm64: Fix possible null-ptr-deref in idregs_debug_show
  2024-10-24  9:29 ` Marc Zyngier
@ 2024-10-29  3:58   ` cuigaosheng
  0 siblings, 0 replies; 3+ messages in thread
From: cuigaosheng @ 2024-10-29  3:58 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: oliver.upton, joey.gouly, suzuki.poulose, yuzenghui,
	catalin.marinas, will, sebott, wangweiyang2, linux-arm-kernel,
	kvmarm

On 2024/10/24 17:29, Marc Zyngier wrote:
> On Thu, 24 Oct 2024 09:33:50 +0100,
> Gaosheng Cui <cuigaosheng1@huawei.com> wrote:
>> The idregs_debug_show() maybe return nullptr, we need to check desc
>> before dereference it to avoid possible null pointer dereferences.
>>
>> Fixes: 410db103f6eb ("KVM: arm64: Make idregs debugfs iterator search sysreg table directly")
>> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
>> ---
>>   arch/arm64/kvm/sys_regs.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
>> index ff8c4e1b847e..b1c59773b9c0 100644
>> --- a/arch/arm64/kvm/sys_regs.c
>> +++ b/arch/arm64/kvm/sys_regs.c
>> @@ -4135,7 +4135,7 @@ static int idregs_debug_show(struct seq_file *s, void *v)
>>   
>>   	desc = idregs_debug_find(kvm, kvm->arch.idreg_debugfs_iter);
>>   
>> -	if (!desc->name)
>> +	if (!desc || !desc->name)
>>   		return 0;
>>   
>>   	seq_printf(s, "%20s:\t%016llx\n",
> Can you show a case where this happens in practice?
>
> The check for NULL is already in idregs_debug_next(), and I don't see
> how this can actually be triggered.

I haven't found a scenario that can trigger this problem,this patch was
discovered during code review,I will try to prove it.

Thanks for your work.

>
> Thanks,
>
> 	M.
>


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

end of thread, other threads:[~2024-10-29  4:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-24  8:33 [PATCH -next] KVM: arm64: Fix possible null-ptr-deref in idregs_debug_show Gaosheng Cui
2024-10-24  9:29 ` Marc Zyngier
2024-10-29  3:58   ` cuigaosheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).