lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 9 Feb 2022 13:16:49 -0800
From:   Dave Hansen <dave.hansen@...el.com>
To:     Rick Edgecombe <rick.p.edgecombe@...el.com>, x86@...nel.org,
        "H . Peter Anvin" <hpa@...or.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, linux-kernel@...r.kernel.org,
        linux-doc@...r.kernel.org, linux-mm@...ck.org,
        linux-arch@...r.kernel.org, linux-api@...r.kernel.org,
        Arnd Bergmann <arnd@...db.de>,
        Andy Lutomirski <luto@...nel.org>,
        Balbir Singh <bsingharora@...il.com>,
        Borislav Petkov <bp@...en8.de>,
        Cyrill Gorcunov <gorcunov@...il.com>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        Eugene Syromiatnikov <esyr@...hat.com>,
        Florian Weimer <fweimer@...hat.com>,
        "H . J . Lu" <hjl.tools@...il.com>, Jann Horn <jannh@...gle.com>,
        Jonathan Corbet <corbet@....net>,
        Kees Cook <keescook@...omium.org>,
        Mike Kravetz <mike.kravetz@...cle.com>,
        Nadav Amit <nadav.amit@...il.com>,
        Oleg Nesterov <oleg@...hat.com>, Pavel Machek <pavel@....cz>,
        Peter Zijlstra <peterz@...radead.org>,
        Randy Dunlap <rdunlap@...radead.org>,
        "Ravi V . Shankar" <ravi.v.shankar@...el.com>,
        Dave Martin <Dave.Martin@....com>,
        Weijiang Yang <weijiang.yang@...el.com>,
        "Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>,
        joao.moreira@...el.com, John Allen <john.allen@....com>,
        kcc@...gle.com, eranian@...gle.com
Cc:     Yu-cheng Yu <yu-cheng.yu@...el.com>
Subject: Re: [PATCH 16/35] x86/mm: Update maybe_mkwrite() for shadow stack

First of all, that changelog doesn't really explain the problem.  It's
all background and no "why".

*Why* does maybe_mkwrite() take a VMA?  What's the point?


>  #endif /* _ASM_X86_PGTABLE_H */
> diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
> index 3481b35cb4ec..c22c8e9c37e8 100644
> --- a/arch/x86/mm/pgtable.c
> +++ b/arch/x86/mm/pgtable.c
> @@ -610,6 +610,26 @@ int pmdp_clear_flush_young(struct vm_area_struct *vma,
>  }
>  #endif
>  
> +pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)
> +{
> +	if (vma->vm_flags & VM_WRITE)
> +		pte = pte_mkwrite(pte);
> +	else if (vma->vm_flags & VM_SHADOW_STACK)
> +		pte = pte_mkwrite_shstk(pte);
> +	return pte;
> +}

First, this makes me wonder why we need pte_mkwrite() *AND*
pte_mkwrite_shstk().  Is there a difference in their behavior that matters?

Second, I don't like the copy-and-paste to make an arch-specific "hook"
for a function.  This is a very good way to ensure that arch code and
generic code fork and accumulate separate bugs.

I'd much rather have this do (in generic code):

 pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)
 {
	if (vma->vm_flags & VM_WRITE)
		pte = pte_mkwrite(pte);

	pte = arch_maybe_mkwrite(pte, vma);

	return pte;
+}

Actually, is there a reason the generic code could not even just add:

	if (vma->vm_flags & VM_ARCH_MAYBE_MKWRITE_MASK)
		pte = arch_maybe_mkwrite(pte, vma);

or heck even just the x86-specific code itself:

	if (vma->vm_flags & VM_SHADOW_STACK)
		pte = pte_mkwrite_shstk(pte);

with a stub defined for pte_mkwrite_shstk()?

In the end, it's just a question of whether the generic code wants
something to say "arch" or "shstk".  But, I don't think we need a forked
x86 copy of these functions.

> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 311c6018d503..b3cb3a17037b 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -955,12 +955,14 @@ void free_compound_page(struct page *page);
>   * pte_mkwrite.  But get_user_pages can cause write faults for mappings
>   * that do not have writing enabled, when used by access_process_vm.
>   */
> +#ifndef maybe_mkwrite

maybe_mkwrite is defined in asm/pgtable.h.  Where is the #include?

>  static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)
>  {
>  	if (likely(vma->vm_flags & VM_WRITE))
>  		pte = pte_mkwrite(pte);
>  	return pte;
>  }
> +#endif
>  
>  vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page);
>  void do_set_pte(struct vm_fault *vmf, struct page *page, unsigned long addr);
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 406a3c28c026..2adedcfca00b 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -491,12 +491,14 @@ static int __init setup_transparent_hugepage(char *str)
>  }
>  __setup("transparent_hugepage=", setup_transparent_hugepage);
>  
> +#ifndef maybe_pmd_mkwrite
>  pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma)
>  {
>  	if (likely(vma->vm_flags & VM_WRITE))
>  		pmd = pmd_mkwrite(pmd);
>  	return pmd;
>  }
> +#endif
>  
>  #ifdef CONFIG_MEMCG
>  static inline struct deferred_split *get_deferred_split_queue(struct page *page)

Powered by blists - more mailing lists