> > - cputable.c, prom_init.c: the original comments said "use memcpy() so
> >    GCC emits __memcpy() under KASAN". The real reason is that these run
> >    pre-relocation: the destination pointer is PTRRELOC-adjusted to its
> >    current physical address, and the kernel is loaded at a different
> >    address than it was linked at. A struct assignment (*t = *s) may cause
> >    the compiler to emit an implicit memcpy() call that resolves through
> >    the unrelocated virtual symbol address -- before the MMU mapping is set
> >    up -- jumping to garbage. An explicit memcpy(t, ...) uses the already-
> >    corrected pointer and is safe. Update the comments accordingly.
> 
> Nope, see my other email.
> 
Got it. I'll remove this.
> > diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c
> > index 6f6801da9dc1..233b5c650d1e 100644
> > --- a/arch/powerpc/kernel/cputable.c
> > +++ b/arch/powerpc/kernel/cputable.c
> > @@ -36,8 +36,12 @@ void __init set_cur_cpu_spec(struct cpu_spec *s)
> >     t = PTRRELOC(t);
> >     /*
> > -    * use memcpy() instead of *t = *s so that GCC replaces it
> > -    * by __memcpy() when KASAN is active
> > +    * Use memcpy() instead of *t = *s because t is a PTRRELOC-adjusted
> > +    * pointer and this code runs before the MMU mapping is established.
> > +    * A struct assignment is a compiler-generated aggregate copy whose
> > +    * implementation is not under our control in relocation-sensitive code;
> > +    * memcpy() ensures the adjusted pointer is explicitly passed to the
> > +    * copy routine.
> 
> This comment is wrong, see my response to your explanation. I think the
> comment should be removed completely, now it is possible to use *t = *s
> without any issue again.
> 
> 
yeah i'll fix this.
> >      */
> >     memcpy(t, s, sizeof(*t));
> > @@ -55,7 +59,11 @@ static struct cpu_spec * __init setup_cpu_spec(unsigned 
> > long offset,
> >     /*
> >      * Copy everything, then do fixups. Use memcpy() instead of *t = *s
> > -    * so that GCC replaces it by __memcpy() when KASAN is active
> > +    * because t is a PTRRELOC-adjusted pointer and this code runs before
> > +    * the MMU mapping is established. A struct assignment is a
> > +    * compiler-generated aggregate copy whose implementation is not under
> > +    * our control in relocation-sensitive code; memcpy() ensures the
> > +    * adjusted pointer is explicitly passed to the copy routine.
> 
> Same
> 
Sure.
> >      */
> >     memcpy(t, s, sizeof(*t));
> > diff --git a/arch/powerpc/kernel/prom_init.c 
> > b/arch/powerpc/kernel/prom_init.c
> > index eb9f556b0937..d6d7f1ede319 100644
> > --- a/arch/powerpc/kernel/prom_init.c
> > +++ b/arch/powerpc/kernel/prom_init.c
> > @@ -1363,10 +1363,12 @@ static void __init prom_check_platform_support(void)
> >                                    "ibm,arch-vec-5-platform-support");
> >     /*
> > -    * First copy the architecture vec template
> > -    *
> > -    * use memcpy() instead of *vec = *vec_template so that GCC replaces it
> > -    * by __memcpy() when KASAN is active
> > +    * First copy the architecture vec template. Use memcpy() instead of
> > +    * a struct assignment because this code runs before the MMU mapping
> > +    * is established. A struct assignment is a compiler-generated
> > +    * aggregate copy whose implementation is not under our control in
> > +    * relocation-sensitive code; memcpy() ensures the adjusted pointer
> > +    * is explicitly passed to the copy routine.
> 
> Same.
> 
Sure.
> >      */
> >     memcpy(&ibm_architecture_vec, &ibm_architecture_vec_template,
> >            sizeof(ibm_architecture_vec));
> 

Reply via email to