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 X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E038C388F7 for ; Thu, 5 Nov 2020 11:16:27 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 21D0E20759 for ; Thu, 5 Nov 2020 11:16:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JcKCr8hN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 21D0E20759 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Myhlx0xSKVya9eAW9RKncOnAh3IOhxJ12wnzw5fktEE=; b=JcKCr8hNoZ2ec1+zCDSwIB4Nl FM5RS3pHUMF5unYQPL9nmgxNpl4s8YyXLklAZI87qDtfNKIGcwp4GyJTfZWbrju8wfk7J1DV5SAs2 vGAEPrMQpnpXGat0yMt765GPO76e5FFc+ud0TV89TTxdqa1vMYc2Uykxpedn/N/A5v0FJ5nbor8Du eq1jwnG7gvaaNYKqzpUzPp10Tu6OkAn9wRJEEZ2+O/GFmsI57WtHdlKnanFIbQiV26IiXmF5w64aP dgj0A/MIo0ml68hvNT6M0iD37FrSJGeTlFXo0Avrz9rKjiUB+0F88jLqSuX7laPfWHDJQQTiWVyk0 9OANDrRsA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kadFL-0006zw-QB; Thu, 05 Nov 2020 11:16:03 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kadFI-0006yV-Bx for linux-arm-kernel@lists.infradead.org; Thu, 05 Nov 2020 11:16:01 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 55E9E142F; Thu, 5 Nov 2020 03:15:58 -0800 (PST) Received: from C02TD0UTHF1T.local (unknown [10.57.58.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D5A9E3F719; Thu, 5 Nov 2020 03:15:55 -0800 (PST) Date: Thu, 5 Nov 2020 11:15:52 +0000 From: Mark Rutland To: Marco Elver Subject: Re: [PATCH] kfence: Use pt_regs to generate stack trace on faults Message-ID: <20201105111552.GD82102@C02TD0UTHF1T.local> References: <20201105092133.2075331-1-elver@google.com> <20201105105241.GC82102@C02TD0UTHF1T.local> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201105_061600_523126_A37C51CC X-CRM114-Status: GOOD ( 32.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Paul E. McKenney" , Jann Horn , the arch/x86 maintainers , LKML , kasan-dev , Linux Memory Management List , Alexander Potapenko , Linux ARM , Andrew Morton , Dmitry Vyukov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Nov 05, 2020 at 12:11:19PM +0100, Marco Elver wrote: > On Thu, 5 Nov 2020 at 11:52, Mark Rutland wrote: > > On Thu, Nov 05, 2020 at 10:21:33AM +0100, Marco Elver wrote: > > > Instead of removing the fault handling portion of the stack trace based > > > on the fault handler's name, just use struct pt_regs directly. > > > > > > Change kfence_handle_page_fault() to take a struct pt_regs, and plumb it > > > through to kfence_report_error() for out-of-bounds, use-after-free, or > > > invalid access errors, where pt_regs is used to generate the stack > > > trace. > > > > > > If the kernel is a DEBUG_KERNEL, also show registers for more > > > information. > > > > > > Suggested-by: Mark Rutland > > > Signed-off-by: Marco Elver > > > > Wow; I wasn't expecting this to be put together so quickly, thanks for > > doing this! > > > > From a scan, this looks good to me -- just one question below. > > > > > diff --git a/include/linux/kfence.h b/include/linux/kfence.h > > > index ed2d48acdafe..98a97f9d43cd 100644 > > > --- a/include/linux/kfence.h > > > +++ b/include/linux/kfence.h > > > @@ -171,6 +171,7 @@ static __always_inline __must_check bool kfence_free(void *addr) > > > /** > > > * kfence_handle_page_fault() - perform page fault handling for KFENCE pages > > > * @addr: faulting address > > > + * @regs: current struct pt_regs (can be NULL, but shows full stack trace) > > > * > > > * Return: > > > * * false - address outside KFENCE pool, > > > > > @@ -44,8 +44,12 @@ static int get_stack_skipnr(const unsigned long stack_entries[], int num_entries > > > case KFENCE_ERROR_UAF: > > > case KFENCE_ERROR_OOB: > > > case KFENCE_ERROR_INVALID: > > > - is_access_fault = true; > > > - break; > > > + /* > > > + * kfence_handle_page_fault() may be called with pt_regs > > > + * set to NULL; in that case we'll simply show the full > > > + * stack trace. > > > + */ > > > + return 0; > > > > For both the above comments, when/where is kfence_handle_page_fault() > > called with regs set to NULL? I couldn't spot that in this patch, so > > unless I mised it I'm guessing that's somewhere outside of the patch > > context? > > Right, currently it's not expected to happen, but I'd like to permit > this function being called not from fault handlers, for use-cases like > this: > > https://lkml.kernel.org/r/CANpmjNNxAvembOetv15FfZ=04mpj0Qwx+1tnn22tABaHHRRv=Q@mail.gmail.com > > The revised recommendation when trying to get KFENCE to give us more > information about allocation/free stacks after refcount underflow > (like what Paul was trying to do) would be to call > kfence_handle_page_fault(addr, NULL). > > > If this is a case we don't expect to happen, maybe add a WARN_ON_ONCE()? > > While it's currently not expected, I don't see why we should make this > WARN and limit the potential uses of the API if it works just fine if > we pass regs set to NULL. Although arguably the name > kfence_handle_page_fault() might be confusing for such uses, for now, > until more widespread use is evident (if at all) I'd say let's keep > as-is, but simply not prevent such use-cases. Fair enough! I guess in future we could always revise that anyhow. FWIW, for this as-is: Acked-by: Mark Rutland Mark. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel