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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <3805269.R56niFO833@phil>
Date:   Fri, 23 Sep 2022 12:18:37 +0200
From:   Heiko Stuebner <heiko@...ech.de>
To:     Samuel Holland <samuel@...lland.org>,
        Palmer Dabbelt <palmer@...belt.com>,
        linux-riscv@...ts.infradead.org, Alexandre Ghiti <alex@...ti.fr>
Cc:     Albert Ou <aou@...s.berkeley.edu>, Guo Ren <guoren@...nel.org>,
        Paul Walmsley <paul.walmsley@...ive.com>,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] riscv: Fix crash during early errata patching

Hi,

Am Donnerstag, 22. September 2022, 09:31:56 CEST schrieb Alexandre Ghiti:
> Hi Samuel,
> 
> On 9/22/22 07:47, Samuel Holland wrote:
> > The patch function for the T-Head PBMT errata calls __pa_symbol() before
> > relocation. This crashes when CONFIG_DEBUG_VIRTUAL is enabled, because
> > __pa_symbol() forwards to __phys_addr_symbol(), and __phys_addr_symbol()
> > checks against the absolute kernel start/end address.
> >
> > Fix this by directly using the underlying kernel_mapping_va_to_pa().
> 
> 
> I'd rather fix __phys_addr_symbol so that we can use __pa_symbol and 
> then take advantage of the address range check. Instead of using _end in 
> phys_addr_symbol, we have access to the size of the kernel mapping, so 
> we could do something like that:
> 
> diff --git a/arch/riscv/mm/physaddr.c b/arch/riscv/mm/physaddr.c
> index f981b1f95fa0..150691aef058 100644
> --- a/arch/riscv/mm/physaddr.c
> +++ b/arch/riscv/mm/physaddr.c
> @@ -22,7 +22,7 @@ EXPORT_SYMBOL(__virt_to_phys);
>   phys_addr_t __phys_addr_symbol(unsigned long x)
>   {
>          unsigned long kernel_start = kernel_map.virt_addr;
> -       unsigned long kernel_end = (unsigned long)_end;
> +       unsigned long kernel_end = kernel_map.virt_addr + kernel_map.size;
> 
>          /*
>           * Boundary checking aginst the kernel image mapping.
> 

so I did the whole set of original code
- works without DEBUG_VIRTUAL
- breaks with DEBUG_VIRTUAL

and then applied you suggested change to __phys_addr_symbol,
which fixes the breakage. And I guess making this usable at all
times also makes a lot of sense, so

Tested-by: Heiko Stuebner <heiko@...ech.de>
Reviewed-by: Heiko Stuebner <heiko@...ech.de>


> > Fixes: a35707c3d850 ("riscv: add memory-type errata for T-Head")
> > Signed-off-by: Samuel Holland <samuel@...lland.org>
> > ---
> >
> >   arch/riscv/errata/thead/errata.c | 5 +++--
> >   1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/riscv/errata/thead/errata.c b/arch/riscv/errata/thead/errata.c
> > index 202c83f677b2..83174f13783e 100644
> > --- a/arch/riscv/errata/thead/errata.c
> > +++ b/arch/riscv/errata/thead/errata.c
> > @@ -76,8 +76,9 @@ void __init_or_module thead_errata_patch_func(struct alt_entry *begin, struct al
> >   		if (cpu_req_errata & tmp) {
> >   			/* On vm-alternatives, the mmu isn't running yet */
> >   			if (stage == RISCV_ALTERNATIVES_EARLY_BOOT)
> > -				memcpy((void *)__pa_symbol(alt->old_ptr),
> > -				       (void *)__pa_symbol(alt->alt_ptr), alt->alt_len);
> > +				memcpy((void *)kernel_mapping_va_to_pa((unsigned long)alt->old_ptr),
> > +				       (void *)kernel_mapping_va_to_pa((unsigned long)alt->alt_ptr),
> > +				       alt->alt_len);
> >   			else
> >   				patch_text_nosync(alt->old_ptr, alt->alt_ptr, alt->alt_len);
> >   		}
> 




Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ