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, 23 Feb 2022 11:21:33 +0100 (CET)
From:   Miroslav Benes <mbenes@...e.cz>
To:     Peter Zijlstra <peterz@...radead.org>
cc:     Josh Poimboeuf <jpoimboe@...hat.com>, x86@...nel.org,
        joao@...rdrivepizza.com, hjl.tools@...il.com,
        andrew.cooper3@...rix.com, linux-kernel@...r.kernel.org,
        ndesaulniers@...gle.com, keescook@...omium.org,
        samitolvanen@...gle.com, mark.rutland@....com,
        alyssa.milburn@...el.com, Steven Rostedt <rostedt@...dmis.org>
Subject: Re: [PATCH 04/29] x86/livepatch: Validate __fentry__ location

On Wed, 23 Feb 2022, Peter Zijlstra wrote:

> On Fri, Feb 18, 2022 at 01:08:31PM -0800, Josh Poimboeuf wrote:
> > On Fri, Feb 18, 2022 at 05:49:06PM +0100, Peter Zijlstra wrote:
> > > Currently livepatch assumes __fentry__ lives at func+0, which is most
> > > likely untrue with IBT on. Override the weak klp_get_ftrace_location()
> > > function with an arch specific version that's IBT aware.
> > > 
> > > Also make the weak fallback verify the location is an actual ftrace
> > > location as a sanity check.
> > > 
> > > Suggested-by: Miroslav Benes <mbenes@...e.cz>
> > > Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
> > > ---
> > >  arch/x86/include/asm/livepatch.h |    9 +++++++++
> > >  kernel/livepatch/patch.c         |    2 +-
> > >  2 files changed, 10 insertions(+), 1 deletion(-)
> > > 
> > > --- a/arch/x86/include/asm/livepatch.h
> > > +++ b/arch/x86/include/asm/livepatch.h
> > > @@ -17,4 +17,13 @@ static inline void klp_arch_set_pc(struc
> > >  	ftrace_instruction_pointer_set(fregs, ip);
> > >  }
> > >  
> > > +#define klp_get_ftrace_location klp_get_ftrace_location
> > > +static inline unsigned long klp_get_ftrace_location(unsigned long faddr)
> > > +{
> > > +	unsigned long addr = ftrace_location(faddr);
> > > +	if (!addr && IS_ENABLED(CONFIG_X86_IBT))
> > > +		addr = ftrace_location(faddr + 4);
> > > +	return addr;
> > 
> > I'm kind of surprised this logic doesn't exist in ftrace itself.  Is
> > livepatch really the only user that needs to find the fentry for a given
> > function?
> > 
> > I had to do a double take for the ftrace_location() semantics, as I
> > originally assumed that's what it did, based on its name and signature.
> > 
> > Instead it apparently functions like a bool but returns its argument on
> > success.
> > 
> > Though the function comment tells a different story:
> > 
> > /**
> >  * ftrace_location - return true if the ip giving is a traced location
> > 
> > So it's all kinds of confusing...
> 
> Yes.. so yesterday, when making function-graph tracing not explode, I
> ran into a similar issue. Steve suggested something along the lines of
> .... this.
> 
> (modified from his actual suggestion to also cover this case)
> 
> Let me go try this...

Yes, this looks good.
 
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -1578,7 +1578,23 @@ unsigned long ftrace_location_range(unsi
>   */
>  unsigned long ftrace_location(unsigned long ip)
>  {
> -	return ftrace_location_range(ip, ip);
> +	struct dyn_ftrace *rec;
> +	unsigned long offset;
> +	unsigned long size;
> +
> +	rec = lookup_rec(ip, ip);
> +	if (!rec) {
> +		if (!kallsyms_lookup(ip, &size, &offset, NULL, NULL))

Since we do not care about a symbol name, kallsyms_lookup_size_offset() 
would be better I think.

Miroslav

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ