[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGS_qxoXXkp2rVGrwa4h7bem-sgHikpMufrPXQaSzOW2N==tQw@mail.gmail.com>
Date: Mon, 28 Feb 2022 17:48:27 -0800
From: Daniel Latypov <dlatypov@...gle.com>
To: Steven Rostedt <rostedt@...dmis.org>
Cc: Kees Cook <keescook@...omium.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 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.
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
It should be visible publicly, but it will prompt you to sign in if
you try to post comments ;(
If anyone has comments before we send out the RFCs, feel free to email
me directly and CC kunit-dev@.
Thanks,
Daniel
Powered by blists - more mailing lists