* set_memory_rw on the kernel text
@ 2015-08-11 14:18 Michal Hocko
2015-08-11 14:20 ` Michal Hocko
0 siblings, 1 reply; 4+ messages in thread
From: Michal Hocko @ 2015-08-11 14:18 UTC (permalink / raw)
To: Suresh Siddha; +Cc: LKML, Jiri Kosina
Hi Subject,
I was debugging an issue that the kernel text didn't get remapped RW
after set_memory_rw and generated a #PF even though set_memory_rw
returned with success (0). I am completely unfamiliar with the code
but it become clear from the code inspection that static_protections()
will drop _PAGE_RW from the protection flags with CONFIG_DEBUG_RODATA
for the large mappings. try_preserve_large_page will then interpret this
as no change is needed and return with 0 all the way up to the caller.
I can see the point that set_memory_rw doesn't allow remapping after
certain moment (kernel_set_to_readonly is non-zero) but the current
semantic with returning success even though the operation was ignored is
strange.
Shouldn't the function return -EPERM instead? So that the caller doesn't
try to write to the address and #PF? Something like a completely
untested.
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index 89af288ec674..c1fcb02f9662 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -540,6 +540,10 @@ try_preserve_large_page(pte_t *kpte, unsigned long address,
cpa->pfn = pfn;
new_prot = static_protections(req_prot, address, pfn);
+ if (pgprot_val(new_prot) ^ pgprot_val(req_prot)) {
+ do_split = -EPERM;
+ goto out_unlock;
+ }
/*
* We need to check the full range, whether
I am also trying to understand why the semantic is different for 4k
pages. I can see that pmd prot change might influence different sections
in the same pmd range or something like that but why don't we simply
split the pmd then and make the 4k page RW?
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: set_memory_rw on the kernel text
2015-08-11 14:18 set_memory_rw on the kernel text Michal Hocko
@ 2015-08-11 14:20 ` Michal Hocko
0 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2015-08-11 14:20 UTC (permalink / raw)
To: Suresh Siddha; +Cc: LKML, Jiri Kosina
On Tue 11-08-15 16:18:45, Michal Hocko wrote:
> Hi Subject,
Dang, Ctrl+p in vim. Sorry about that...
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: set_memory_rw on the kernel text
2015-08-11 14:23 Michal Hocko
@ 2015-09-04 13:09 ` Jiri Kosina
0 siblings, 0 replies; 4+ messages in thread
From: Jiri Kosina @ 2015-09-04 13:09 UTC (permalink / raw)
To: Michal Hocko; +Cc: Suresh Siddha, LKML
On Tue, 11 Aug 2015, Michal Hocko wrote:
> [reposted with the correct address and name]
>
> Hi Suresh,
> I was debugging an issue that the kernel text didn't get remapped RW
> after set_memory_rw and generated a #PF even though set_memory_rw
> returned with success (0). I am completely unfamiliar with the code
> but it become clear from the code inspection that static_protections()
> will drop _PAGE_RW from the protection flags with CONFIG_DEBUG_RODATA
> for the large mappings. try_preserve_large_page will then interpret this
> as no change is needed and return with 0 all the way up to the caller.
>
> I can see the point that set_memory_rw doesn't allow remapping after
> certain moment (kernel_set_to_readonly is non-zero) but the current
> semantic with returning success even though the operation was ignored is
> strange.
>
> Shouldn't the function return -EPERM instead? So that the caller doesn't
> try to write to the address and #PF? Something like a completely
> untested.
I think this would be a nice to have fix. Suresh ... ?
>
> diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
> index 89af288ec674..c1fcb02f9662 100644
> --- a/arch/x86/mm/pageattr.c
> +++ b/arch/x86/mm/pageattr.c
> @@ -540,6 +540,10 @@ try_preserve_large_page(pte_t *kpte, unsigned long address,
> cpa->pfn = pfn;
>
> new_prot = static_protections(req_prot, address, pfn);
> + if (pgprot_val(new_prot) ^ pgprot_val(req_prot)) {
> + do_split = -EPERM;
> + goto out_unlock;
> + }
>
> /*
> * We need to check the full range, whether
>
> I am also trying to understand why the semantic is different for 4k
> pages. I can see that pmd prot change might influence different sections
> in the same pmd range or something like that but why don't we simply
> split the pmd then and make the 4k page RW?
--
Jiri Kosina
SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread
* set_memory_rw on the kernel text
@ 2015-08-11 14:23 Michal Hocko
2015-09-04 13:09 ` Jiri Kosina
0 siblings, 1 reply; 4+ messages in thread
From: Michal Hocko @ 2015-08-11 14:23 UTC (permalink / raw)
To: Suresh Siddha; +Cc: LKML, Jiri Kosina
[reposted with the correct address and name]
Hi Suresh,
I was debugging an issue that the kernel text didn't get remapped RW
after set_memory_rw and generated a #PF even though set_memory_rw
returned with success (0). I am completely unfamiliar with the code
but it become clear from the code inspection that static_protections()
will drop _PAGE_RW from the protection flags with CONFIG_DEBUG_RODATA
for the large mappings. try_preserve_large_page will then interpret this
as no change is needed and return with 0 all the way up to the caller.
I can see the point that set_memory_rw doesn't allow remapping after
certain moment (kernel_set_to_readonly is non-zero) but the current
semantic with returning success even though the operation was ignored is
strange.
Shouldn't the function return -EPERM instead? So that the caller doesn't
try to write to the address and #PF? Something like a completely
untested.
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index 89af288ec674..c1fcb02f9662 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -540,6 +540,10 @@ try_preserve_large_page(pte_t *kpte, unsigned long address,
cpa->pfn = pfn;
new_prot = static_protections(req_prot, address, pfn);
+ if (pgprot_val(new_prot) ^ pgprot_val(req_prot)) {
+ do_split = -EPERM;
+ goto out_unlock;
+ }
/*
* We need to check the full range, whether
I am also trying to understand why the semantic is different for 4k
pages. I can see that pmd prot change might influence different sections
in the same pmd range or something like that but why don't we simply
split the pmd then and make the 4k page RW?
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-09-04 13:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-11 14:18 set_memory_rw on the kernel text Michal Hocko
2015-08-11 14:20 ` Michal Hocko
2015-08-11 14:23 Michal Hocko
2015-09-04 13:09 ` Jiri Kosina
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®