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.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 B22CDC5517A for ; Thu, 5 Nov 2020 10:52:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3615121D81 for ; Thu, 5 Nov 2020 10:52:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3615121D81 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 988CF6B00DC; Thu, 5 Nov 2020 05:52:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 93ABB6B00DD; Thu, 5 Nov 2020 05:52:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 800E46B00DE; Thu, 5 Nov 2020 05:52:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0220.hostedemail.com [216.40.44.220]) by kanga.kvack.org (Postfix) with ESMTP id 4B9436B00DC for ; Thu, 5 Nov 2020 05:52:48 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E1F151EE6 for ; Thu, 5 Nov 2020 10:52:47 +0000 (UTC) X-FDA: 77450051574.17.table38_35044df272c9 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id CA122180D0181 for ; Thu, 5 Nov 2020 10:52:47 +0000 (UTC) X-HE-Tag: table38_35044df272c9 X-Filterd-Recvd-Size: 3274 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Thu, 5 Nov 2020 10:52:47 +0000 (UTC) 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 63BAE142F; Thu, 5 Nov 2020 02:52:46 -0800 (PST) Received: from C02TD0UTHF1T.local (unknown [10.57.58.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 848743F66E; Thu, 5 Nov 2020 02:52:44 -0800 (PST) Date: Thu, 5 Nov 2020 10:52:41 +0000 From: Mark Rutland To: Marco Elver Cc: akpm@linux-foundation.org, glider@google.com, dvyukov@google.com, jannh@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] kfence: Use pt_regs to generate stack trace on faults Message-ID: <20201105105241.GC82102@C02TD0UTHF1T.local> References: <20201105092133.2075331-1-elver@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201105092133.2075331-1-elver@google.com> 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, 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? If this is a case we don't expect to happen, maybe add a WARN_ON_ONCE()? Thanks, Mark.