2024-04-23 07:43:26

by Huacai Chen

[permalink] [raw]
Subject: [PATCH] LoongArch: Fix access error when read fault on a write-only VMA

From: Jiantao Shan <[email protected]>

As with most architectures, allow handling of read faults in VMAs that
have VM_WRITE but without VM_READ (WRITE implies READ).

Otherwise, reading before writing a write-only memory will error while
reading after writing everything is fine.

BTW, move the VM_EXEC judgement before VM_READ/VM_WRITE to make logic a
little clearer.

Signed-off-by: Jiantao Shan <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
---
arch/loongarch/mm/fault.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/loongarch/mm/fault.c b/arch/loongarch/mm/fault.c
index 1fc2f6813ea0..97b40defde06 100644
--- a/arch/loongarch/mm/fault.c
+++ b/arch/loongarch/mm/fault.c
@@ -202,10 +202,10 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
if (!(vma->vm_flags & VM_WRITE))
goto bad_area;
} else {
- if (!(vma->vm_flags & VM_READ) && address != exception_era(regs))
- goto bad_area;
if (!(vma->vm_flags & VM_EXEC) && address == exception_era(regs))
goto bad_area;
+ if (!(vma->vm_flags & (VM_READ | VM_WRITE)) && address != exception_era(regs))
+ goto bad_area;
}

/*
--
2.43.0



2024-04-23 09:45:52

by Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH] LoongArch: Fix access error when read fault on a write-only VMA

> As with most architectures, allow handling of read faults in VMAs that
> have VM_WRITE but without VM_READ (WRITE implies READ).


Will the tag “Fixes” become relevant here?

Regards,
Markus

2024-04-24 03:12:03

by Huacai Chen

[permalink] [raw]
Subject: Re: [PATCH] LoongArch: Fix access error when read fault on a write-only VMA

Hi, Markus,

On Tue, Apr 23, 2024 at 5:45 PM Markus Elfring <[email protected]> wrote:
>
> > As with most architectures, allow handling of read faults in VMAs that
> > have VM_WRITE but without VM_READ (WRITE implies READ).
> …
>
> Will the tag “Fixes” become relevant here?
Yes, you are right, thank you.

Huacai
>
> Regards,
> Markus