Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WX mappings in the linear mapping after module unloading #386

Closed
wants to merge 2 commits into from

Conversation

bjoto
Copy link

@bjoto bjoto commented Dec 13, 2023

Pull request for series with
subject: riscv: Fix module_alloc() that did not reset the linear mapping permissions
version: 1
url: https://patchwork.kernel.org/project/linux-riscv/list/?series=809679

@bjoto
Copy link
Author

bjoto commented Dec 13, 2023

Upstream branch: f352a28
series: https://patchwork.kernel.org/project/linux-riscv/list/?series=809679
version: 1

Alexandre Ghiti added 2 commits December 19, 2023 15:06
…ssions

After unloading a module, we must reset the linear mapping permissions,
see the example below:

Before unloading a module:

0xffffaf809d65d000-0xffffaf809d6dc000    0x000000011d65d000       508K PTE .   ..     ..   D A G . . W R V
0xffffaf809d6dc000-0xffffaf809d6dd000    0x000000011d6dc000         4K PTE .   ..     ..   D A G . . . R V
0xffffaf809d6dd000-0xffffaf809d6e1000    0x000000011d6dd000        16K PTE .   ..     ..   D A G . . W R V
0xffffaf809d6e1000-0xffffaf809d6e7000    0x000000011d6e1000        24K PTE .   ..     ..   D A G . X . R V

After unloading a module:

0xffffaf809d65d000-0xffffaf809d6e1000    0x000000011d65d000       528K PTE .   ..     ..   D A G . . W R V
0xffffaf809d6e1000-0xffffaf809d6e7000    0x000000011d6e1000        24K PTE .   ..     ..   D A G . X W R V

The last mapping is not reset and we end up with WX mappings in the linear
mapping.

So add VM_FLUSH_RESET_PERMS to our module_alloc() definition.

Fixes: 0cff8bf ("riscv: avoid the PIC offset of static percpu data in module beyond 2G limits")
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
When resetting the linear mapping permissions, we must make sure that we
clear the X bit so that do not end up with WX mappings (since we set
PAGE_KERNEL).

Fixes: 395a21f ("riscv: add ARCH_HAS_SET_DIRECT_MAP support")
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
@bjoto bjoto reopened this Dec 19, 2023
@bjoto
Copy link
Author

bjoto commented Dec 19, 2023

Upstream branch: f352a28
series: https://patchwork.kernel.org/project/linux-riscv/list/?series=809679
version: 1

@bjoto bjoto changed the title riscv: Fix module_alloc() that did not reset the linear mapping permissions Fix WX mappings in the linear mapping after module unloading Dec 19, 2023
@bjoto
Copy link
Author

bjoto commented Dec 21, 2023

At least one diff in series https://patchwork.kernel.org/project/linux-riscv/list/?series=809679 irrelevant now. Closing PR.

@bjoto bjoto added accepted and removed new labels Dec 21, 2023
@bjoto bjoto closed this Dec 21, 2023
@bjoto bjoto deleted the series/809679=>for-next branch December 21, 2023 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant