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 AF9C7C433EF for ; Tue, 1 Mar 2022 01:48:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19A6F8D0002; Mon, 28 Feb 2022 20:48:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1242C8D0001; Mon, 28 Feb 2022 20:48:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2D558D0002; Mon, 28 Feb 2022 20:48:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0130.hostedemail.com [216.40.44.130]) by kanga.kvack.org (Postfix) with ESMTP id E0EF18D0001 for ; Mon, 28 Feb 2022 20:48:40 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A29968249980 for ; Tue, 1 Mar 2022 01:48:40 +0000 (UTC) X-FDA: 79194133200.19.470A9EF Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by imf31.hostedemail.com (Postfix) with ESMTP id 47C9A2000B for ; Tue, 1 Mar 2022 01:48:40 +0000 (UTC) Received: by mail-ej1-f44.google.com with SMTP id qk11so28529560ejb.2 for ; Mon, 28 Feb 2022 17:48:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qdaEKJNXyehKmI6OZeRutyAexvnsM0OhIQCRJEZlx28=; b=hk62M/2R3BtupGl5Pb4JIGG6SEHCrWhREvCKfHTYpMBQ4qyhyY+4bK5b+KJJU+prb9 jw2/VkjB829+5rxjhC8YKv2FW83z6j482i2qwn1Sq0qRLTW3HOGlTLaPuCIa64sdQ81F 6HHA+4u8A39L+cEhNKhWdNpr6HcBlGxPaSH4+wuVJU/yiAvPZT1x+P19RzP0NJiTSqqd HTvyvR1g9rOPUbgaKmcGVAAIMAxR6leD35by1icaadxC09XUfXdMOykTBR0JUJDXqzKP V6NnInEOsPCBEJBhms88PsDL+DOV7tlECL4waxonwf7rH2nwCSmbrvFe6JU9fiKYefHu I4BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qdaEKJNXyehKmI6OZeRutyAexvnsM0OhIQCRJEZlx28=; b=gQ+8idqrtS6ADo6FGhgwyLTQFECA58+retvBlbTsI+U7z99PbPVj0rD3BioaNdSx0U RpfcHz557raDDBX3yNLhQr9M0qUyhJETw09ACguIY95y7IVPhg1PBzmKFj4cZlc/tTvV QFF662itqqzIc++k0MxYgdsHDi6KQbsAVmTLns/FEMYDYIm4IAkHUHY5EHCgmgTBsxbj AXgf1DHm57rBQb0XAa8qkiRWr/KYwahyVsT+pywvywblEzxYQCiQFkT+UE+NKodJdDnL EXjpZtrHRunGG5NA1Wcc6bU+grKW0ujKOHzKRXXzQh3488DibNZeAy2g+BxmmEfHnVyU LO8A== X-Gm-Message-State: AOAM5323VHf/Oq0MT8ii5gTI0EmUaIROkc9d24fh/wQKs9NKn4wDZHM+ /Q6YHO4us9qxsMrywWprt3cZJZMGVfBLYCjU6JqTSw== X-Google-Smtp-Source: ABdhPJyJnxStim8LcjtJqPLQfafGeXLVGaK+Vyh2JMgcZlT8OZOQfzz8aTwShCHtjtoXEwTHtyCJSy/5UpDO1v71xzI= X-Received: by 2002:a17:906:6d0b:b0:6d1:d64e:3142 with SMTP id m11-20020a1709066d0b00b006d1d64e3142mr17304749ejr.631.1646099318663; Mon, 28 Feb 2022 17:48:38 -0800 (PST) MIME-Version: 1.0 References: <20220224054332.1852813-1-keescook@chromium.org> <202202232208.B416701@keescook> <20220224091550.2b7e8784@gandalf.local.home> In-Reply-To: <20220224091550.2b7e8784@gandalf.local.home> From: Daniel Latypov Date: Mon, 28 Feb 2022 17:48:27 -0800 Message-ID: Subject: Re: [PATCH] binfmt_elf: Introduce KUnit test To: Steven Rostedt Cc: Kees Cook , Eric Biederman , David Gow , Alexey Dobriyan , =?UTF-8?B?TWFnbnVzIEdyb8Of?= , kunit-dev@googlegroups.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 47C9A2000B X-Stat-Signature: zajahsyhokm6ibzmre4ny585norusi3e X-Rspam-User: Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="hk62M/2R"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf31.hostedemail.com: domain of dlatypov@google.com designates 209.85.218.44 as permitted sender) smtp.mailfrom=dlatypov@google.com X-Rspamd-Server: rspam03 X-HE-Tag: 1646099320-88385 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 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. 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