[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <202202281915.3479AB42@keescook>
Date: Mon, 28 Feb 2022 19:17:08 -0800
From: Kees Cook <keescook@...omium.org>
To: Daniel Latypov <dlatypov@...gle.com>
Cc: Steven Rostedt <rostedt@...dmis.org>,
Eric Biederman <ebiederm@...ssion.com>,
David Gow <davidgow@...gle.com>,
Alexey Dobriyan <adobriyan@...il.com>,
Magnus Groß <magnus.gross@...h-aachen.de>,
kunit-dev@...glegroups.com, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-mm@...ck.org,
linux-hardening@...r.kernel.org
Subject: Re: [PATCH] binfmt_elf: Introduce KUnit test
On Mon, Feb 28, 2022 at 05:48:27PM -0800, Daniel Latypov wrote:
> On Thu, Feb 24, 2022 at 6:15 AM Steven Rostedt <rostedt@...dmis.org> wrote:
> >
> > On Wed, 23 Feb 2022 22:13:25 -0800
> > Kees Cook <keescook@...omium.org> wrote:
> >
> > > Steven, I want to do fancy live-patch kind or things to replace functions,
> > > but it doesn't need to be particularly fancy because KUnit tests (usually)
> > > run single-threaded, etc. It looks like kprobes could almost do it, but
> > > I don't see a way to have it _avoid_ making a function call.
> >
> >
> > // This is called just before the hijacked function is called
> > static void notrace my_tramp(unsigned long ip, unsigned long parent_ip,
> > struct ftrace_ops *ops,
> > struct ftrace_regs *fregs)
> > {
> > int bit;
> >
> > bit = ftrace_test_recursion_trylock(ip, parent_ip);
> > if (WARN_ON_ONCE(bit < 0))
> > return;
> >
> > /*
> > * This uses the live kernel patching arch code to now return
> > * to new_function() instead of the one that was called.
> > * If you want to do a lookup, you can look at the "ip"
> > * which will give you the function you are about to replace.
> > * Note, it may not be equal to the function address,
> > * but for that, you can have this:
> > * ip = ftrace_location(function_ip);
> > * which will give the ip that is passed here.
> > */
> > klp_arch_set_pc(fregs, new_function);
>
> Ahah!
> This was the missing bit.
>
> David and I both got so excited by this we prototyped experimental
> APIs around this over the weekend.
> He also prototyped a more intrusive alternative to using ftrace and
> kernel livepatch since they don't work on all arches, like UML.
Yay! That's excellent. I didn't have time to try this myself, so I'm
delighted to see y'all got it working. Nice!
> We're splitting up responsibility and will each submit RFCs to the
> list in the coming days.
> I'll send the ftrace one based on this.
> He'll send his alternative one as well.
> I think we'll end up having both approaches as they both have their usecases.
>
> It'll take some iteration to bikeshed stuff like names and make them
> more consistent with each other.
> I've posted my working copy on Gerrit for now, if people want to take
> a look: https://kunit-review.googlesource.com/c/linux/+/5109
Great! I'll go comment on it there.
--
Kees Cook
Powered by blists - more mailing lists