2023-03-08 19:06:40

by Joey Gouly

[permalink] [raw]
Subject: [PATCH v1 0/4] Fixes for MDWE prctl

Hi all,

These are four small fixes for the recent memory-write-deny-execute prctl patches [1].
Two reported by Alexey about error handling and two tooling fixes by Peter.

Thanks,
Joey

[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/

Joey Gouly (2):
mm: deduplicate error handling for map_deny_write_exec
mm: fix error handling for map_deny_write_exec

Peter Xu (2):
kselftest: vm: fix unused variable warning
tools headers UAPI: Sync linux/prctl.h with the kernel sources

mm/mmap.c | 7 +------
mm/mprotect.c | 2 +-
tools/include/uapi/linux/prctl.h | 6 ++++++
tools/testing/selftests/mm/mdwe_test.c | 3 +--
4 files changed, 9 insertions(+), 9 deletions(-)

--
2.17.1



2023-03-08 19:06:48

by Joey Gouly

[permalink] [raw]
Subject: [PATCH v1 1/4] mm: deduplicate error handling for map_deny_write_exec

Commit cc8d1b097de7 ("mmap: clean up mmap_region() unrolling") deduplicated
the error handling, do the same for the return value of `map_deny_write_exec`.

Fixes: b507808ebce2 ("mm: implement memory-deny-write-execute as a prctl")
Reported-by: Alexey Izbyshev <[email protected]>
Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/
Signed-off-by: Joey Gouly <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Andrew Morton <[email protected]>
---
mm/mmap.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 740b54be3ed4..ad499f7b767f 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2621,12 +2621,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,

if (map_deny_write_exec(vma, vma->vm_flags)) {
error = -EACCES;
- if (file)
- goto close_and_free_vma;
- else if (vma->vm_file)
- goto unmap_and_free_vma;
- else
- goto free_vma;
+ goto close_and_free_vma;
}

/* Allow architectures to sanity-check the vm_flags */
--
2.17.1


2023-03-08 19:07:09

by Joey Gouly

[permalink] [raw]
Subject: [PATCH v1 3/4] kselftest: vm: fix unused variable warning

From: Peter Xu <[email protected]>

Remove unused variable from the MDWE test.

Fixes: 4cf1fe34fd18 ("kselftest: vm: add tests for memory-deny-write-execute")
Signed-off-by: Peter Xu <[email protected]>
[joey: added commit message]
Signed-off-by: Joey Gouly <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Andrew Morton <[email protected]>
---
tools/testing/selftests/mm/mdwe_test.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/testing/selftests/mm/mdwe_test.c b/tools/testing/selftests/mm/mdwe_test.c
index f466a099f1bf..bc91bef5d254 100644
--- a/tools/testing/selftests/mm/mdwe_test.c
+++ b/tools/testing/selftests/mm/mdwe_test.c
@@ -163,9 +163,8 @@ TEST_F(mdwe, mprotect_WRITE_EXEC)

TEST_F(mdwe, mmap_FIXED)
{
- void *p, *p2;
+ void *p;

- p2 = mmap(NULL, self->size, PROT_READ | PROT_EXEC, self->flags, 0, 0);
self->p = mmap(NULL, self->size, PROT_READ, self->flags, 0, 0);
ASSERT_NE(self->p, MAP_FAILED);

--
2.17.1


2023-03-08 19:07:20

by Joey Gouly

[permalink] [raw]
Subject: [PATCH v1 2/4] mm: fix error handling for map_deny_write_exec

Commit 4a18419f71cd ("mm/mprotect: use mmu_gather") changed 'goto out;'
to 'break' in the loop.
This wasn't noticed while rebasing the MDWE patches, so fix it now.

Fixes: b507808ebce2 ("mm: implement memory-deny-write-execute as a prctl")
Reported-by: Alexey Izbyshev <[email protected]>
Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/
Signed-off-by: Joey Gouly <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Andrew Morton <[email protected]>
---
mm/mprotect.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/mprotect.c b/mm/mprotect.c
index 231929f119d9..13e84d8c0797 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -805,7 +805,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len,

if (map_deny_write_exec(vma, newflags)) {
error = -EACCES;
- goto out;
+ break;
}

/* Allow architectures to sanity-check the new flags */
--
2.17.1


2023-03-13 14:14:07

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH v1 3/4] kselftest: vm: fix unused variable warning

On Wed, Mar 08, 2023 at 07:04:22PM +0000, Joey Gouly wrote:
> From: Peter Xu <[email protected]>
>
> Remove unused variable from the MDWE test.
>
> Fixes: 4cf1fe34fd18 ("kselftest: vm: add tests for memory-deny-write-execute")
> Signed-off-by: Peter Xu <[email protected]>
> [joey: added commit message]
> Signed-off-by: Joey Gouly <[email protected]>
> Cc: Catalin Marinas <[email protected]>
> Cc: Andrew Morton <[email protected]>

Acked-by: Catalin Marinas <[email protected]>

2023-03-13 14:16:36

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH v1 1/4] mm: deduplicate error handling for map_deny_write_exec

On Wed, Mar 08, 2023 at 07:04:20PM +0000, Joey Gouly wrote:
> Commit cc8d1b097de7 ("mmap: clean up mmap_region() unrolling") deduplicated
> the error handling, do the same for the return value of `map_deny_write_exec`.
>
> Fixes: b507808ebce2 ("mm: implement memory-deny-write-execute as a prctl")
> Reported-by: Alexey Izbyshev <[email protected]>
> Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/
> Signed-off-by: Joey Gouly <[email protected]>
> Cc: Catalin Marinas <[email protected]>
> Cc: Andrew Morton <[email protected]>

Reviewed-by: Catalin Marinas <[email protected]>

2023-03-13 14:16:54

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH v1 2/4] mm: fix error handling for map_deny_write_exec

On Wed, Mar 08, 2023 at 07:04:21PM +0000, Joey Gouly wrote:
> Commit 4a18419f71cd ("mm/mprotect: use mmu_gather") changed 'goto out;'
> to 'break' in the loop.
> This wasn't noticed while rebasing the MDWE patches, so fix it now.
>
> Fixes: b507808ebce2 ("mm: implement memory-deny-write-execute as a prctl")
> Reported-by: Alexey Izbyshev <[email protected]>
> Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/
> Signed-off-by: Joey Gouly <[email protected]>
> Cc: Catalin Marinas <[email protected]>
> Cc: Andrew Morton <[email protected]>

Reviewed-by: Catalin Marinas <[email protected]>