From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6854C433EF for ; Tue, 1 Mar 2022 03:17:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 337D68D0002; Mon, 28 Feb 2022 22:17:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2BD7D8D0001; Mon, 28 Feb 2022 22:17:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15F868D0002; Mon, 28 Feb 2022 22:17:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 015398D0001 for ; Mon, 28 Feb 2022 22:17:10 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D3A18608E4 for ; Tue, 1 Mar 2022 03:17:10 +0000 (UTC) X-FDA: 79194356220.11.F3A668F Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf09.hostedemail.com (Postfix) with ESMTP id 6A05C140002 for ; Tue, 1 Mar 2022 03:17:10 +0000 (UTC) Received: by mail-pl1-f171.google.com with SMTP id n15so10139187plf.4 for ; Mon, 28 Feb 2022 19:17:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=D9x16hpYQdFpeB624xXKo/5BvFgV4Od1VIdDfB4dqJQ=; b=ly9WvSk6zUpjZVEFos11qbu1AHRjIws7KxqN6MNQ24+lQp4PAD94zNW9mUHv0byc9Z h2rOcqDlSnHTmBxtDIUgoesRu+anF0AmmCArmrOZIPizxDYoz58hdvnKpC0xGzO9CSlE U47YviJOVqkJ/pZyezz5dr6rNIkTdtWBo3+MU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=D9x16hpYQdFpeB624xXKo/5BvFgV4Od1VIdDfB4dqJQ=; b=id5dVdO9H9S6jpqTcT4Plmg+HqP8nRhVyK/fJxU0O5gGks4Y6/wuwXZ2t4aSEEgsr3 xpQ5v60UrkEKTniIl9jEzxE7w7CrWux967A0oAsfHtvrH59ICn5GL9ClrjkYDtzPhFXu Rb56nzDbuSLIs7MMAiilUtCOKUUvj8nExiJAwGHLuHDeKtFF5TigK6kzch/3eK3dHNWn u/iNkBO3/YP7K0sLoqMCXICMDyG7aJZ+/NhSRMXUy9tz5cqQwvZ6c2pwCeMQ74IQsDlH VCWDvIZrozduLstPoktNN4Bs+RRfsOYRByupCGWmo8q5t01usI76E0hoe1VdneFTBcEG EMTQ== X-Gm-Message-State: AOAM533R/pLPcvbk6H2V7jciBcVTgKupvCTlwhAApMGj48Pb/VXxnU3F QZRx2SWCZRfweu/aJDeGHUTF7g== X-Google-Smtp-Source: ABdhPJyb0hp0sFIkfnr3V26CkkYMbl8AVw0UqnZQpd+BwVdHpRBFAEALSMG8jVi8fZskBxpwyHv6Iw== X-Received: by 2002:a17:90a:6001:b0:1bb:83e8:1694 with SMTP id y1-20020a17090a600100b001bb83e81694mr19893304pji.127.1646104629348; Mon, 28 Feb 2022 19:17:09 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u25-20020a62ed19000000b004f140515d56sm14527808pfh.46.2022.02.28.19.17.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 19:17:09 -0800 (PST) Date: Mon, 28 Feb 2022 19:17:08 -0800 From: Kees Cook To: Daniel Latypov Cc: Steven Rostedt , Eric Biederman , David Gow , Alexey Dobriyan , Magnus =?iso-8859-1?Q?Gro=DF?= , kunit-dev@googlegroups.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] binfmt_elf: Introduce KUnit test Message-ID: <202202281915.3479AB42@keescook> References: <20220224054332.1852813-1-keescook@chromium.org> <202202232208.B416701@keescook> <20220224091550.2b7e8784@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6A05C140002 X-Stat-Signature: yq9gpm13kijtft64kqfeeczh43cr6gmx Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=ly9WvSk6; spf=pass (imf09.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.171 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspam-User: X-HE-Tag: 1646104630-313558 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Feb 28, 2022 at 05:48:27PM -0800, Daniel Latypov wrote: > On Thu, Feb 24, 2022 at 6:15 AM Steven Rostedt wrote: > > > > On Wed, 23 Feb 2022 22:13:25 -0800 > > Kees Cook 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