|
Message-ID: <2a9988ec-c115-8fe8-4c68-82eb2fa43d6b@c-s.fr> Date: Wed, 26 Feb 2020 08:19:19 +0100 From: Christophe Leroy <christophe.leroy@....fr> To: Russell Currey <ruscur@...sell.cc>, linuxppc-dev@...ts.ozlabs.org Cc: joel@....id.au, mpe@...erman.id.au, ajd@...ux.ibm.com, dja@...ens.net, npiggin@...il.com, kernel-hardening@...ts.openwall.com, Jordan Niethe <jniethe5@...il.com> Subject: Re: [PATCH v4 8/8] powerpc/mm: Disable set_memory() routines when strict RWX isn't enabled Le 26/02/2020 à 07:24, Russell Currey a écrit : > There are a couple of reasons that the set_memory() functions are > problematic when STRICT_KERNEL_RWX isn't enabled: > > - The linear mapping is a different size and apply_to_page_range() > may modify a giant section, breaking everything I don't understand. > - patch_instruction() doesn't know to work around a page being marked > RO, and will subsequently crash Is patch_instruction() involved at all ? > > The latter can be replicated by building a kernel with the set_memory() > patches but with STRICT_KERNEL_RWX off and running ftracetest. > > Reported-by: Jordan Niethe <jniethe5@...il.com> > Signed-off-by: Russell Currey <ruscur@...sell.cc> > --- > v4: new > > arch/powerpc/mm/pageattr.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/arch/powerpc/mm/pageattr.c b/arch/powerpc/mm/pageattr.c > index ee6b5e3b7604..ff111930cf5e 100644 > --- a/arch/powerpc/mm/pageattr.c > +++ b/arch/powerpc/mm/pageattr.c > @@ -96,12 +96,17 @@ static int set_page_attr(pte_t *ptep, unsigned long addr, void *data) > > int set_memory_attr(unsigned long addr, int numpages, pgprot_t prot) Isn't it change_memory_attr() that is a problem for you ? > { > - unsigned long start = ALIGN_DOWN(addr, PAGE_SIZE); > - unsigned long sz = numpages * PAGE_SIZE; > + unsigned long start, size; > + > + if (!IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)) > + return 0; Doing this you break patch 7: mark_initmem_nx() is called regardless of CONFIG_STRICT_KERNEL_RWX __kernel_map_pages() depends on CONFIG_DEBUG_PAGEALLOC which doesn't depend on CONFIG_STRICT_KERNEL_RWX > > if (!numpages) > return 0; > > - return apply_to_page_range(&init_mm, start, sz, set_page_attr, > + start = ALIGN_DOWN(addr, PAGE_SIZE); > + size = numpages * PAGE_SIZE; > + > + return apply_to_page_range(&init_mm, start, size, set_page_attr, You don't need to move start and size calculation and change the above. > (void *)pgprot_val(prot)); > } > Christophe
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.