Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp505792imu; Tue, 11 Dec 2018 02:58:43 -0800 (PST) X-Google-Smtp-Source: AFSGD/XE/ih761gdCkkyEDlN+GHioYxGFdmdkc9oTIg0hlcjuXA4HwjnkvuTXLqDdAu5aPzVV9fb X-Received: by 2002:a62:7e13:: with SMTP id z19mr15833339pfc.94.1544525923772; Tue, 11 Dec 2018 02:58:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544525923; cv=none; d=google.com; s=arc-20160816; b=A/b9+ESiZbYAYaPEE2Ds4Ybseb1cdnQwWSi8QzR+eaiF3X29j+677optSSV0UMRS3f /3hjo3OXvZTIeF/dIcFEKuDoRrZMswHF1M1KHxwrZDng+EH4JqZ5KTk4p2QkVAqSSKZp vYDQcGapEtZnt7SadE64Az63JM2RFNKfaBU8YvscrLlrW7nhGdNq2Fc+A+83qXreznCX CX7P5TitwOX01SYJ/n0jWiNZZSWdJz4XTgiJ7PS7gmTP/C2pM3oLUUmcqKsP07a6enYt 33IHOWZM1A1QLOWtSopuKFy8ZklYD03NGDM0DdkQbyA0nbV9Z6MUXKHJGphLPF9oyvbY 0MyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=+oce3y3MlGvg/ig4q///rHNhAA6VEygCtwfBqOJrH80=; b=O1EyAuVYMF7NoZHyz2fYUftEVPrLlRT0ELlBca/5WqGY7QViXH7n2m9Z/UDmC6bEQ0 r+7JSB4ZrTvTIjJSHo0UgOeVhInIBxYKKIsVnGIVWfevcyIoTEjAU2z7QlIfhx7l+5KO fZZnSaAiMHaAHxY0h/wAmgnO/SvwC9CQFOvCGnqcFie7i2UIFk1nTFR3VYMZzc9JB6aE Wtg7eXe+md6wN4oXNlFKF4KWYIs8XFF0KsJgFPcOe2L67fhgMApfAPgYEmyIWGH6Dk3M L/dnXKInKyiraw4yZQonk7sEv//+cuu6R0f4P7sLLfZmjYs1K+yE4Y3UWzlqIrZmJu0m WYhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=OYFcyYbu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z86si13205785pfl.209.2018.12.11.02.58.28; Tue, 11 Dec 2018 02:58:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=OYFcyYbu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726672AbeLKKzc (ORCPT + 99 others); Tue, 11 Dec 2018 05:55:32 -0500 Received: from mail-io1-f67.google.com ([209.85.166.67]:35624 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726527AbeLKKzb (ORCPT ); Tue, 11 Dec 2018 05:55:31 -0500 Received: by mail-io1-f67.google.com with SMTP id i1so9423572ioo.2 for ; Tue, 11 Dec 2018 02:55:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+oce3y3MlGvg/ig4q///rHNhAA6VEygCtwfBqOJrH80=; b=OYFcyYbujpbmJLMoorf8g2CGc3dRHhpaC4oHn7aX8C+pilj0+BUmD1PuOBBAcJutRU NlZxIVAjYLgNAGCZ28aD4VsUXDxT5NB0OzAMZY1RJUoKXWN4LTwUojH2yeqSpysB5iNL A42x7SB9zOM5MurTZecCvWFWksN43Ae6DSRD8cPq7p9XyoDRBiU0YKrpB9ETgqXOKVeQ cbOuhpyilH0yoa/VjlOgZvQPlJRuTlM4QoPtcCz1ksDdON6xeeGsa3f6SKzw/tarO6XZ 0Ng9h66+0z54ZXXZQLT5o6Lc2ak7m45gnjsY8igPlrcjS8c8vqVruog4uC+JbP7eaGYH JmPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+oce3y3MlGvg/ig4q///rHNhAA6VEygCtwfBqOJrH80=; b=XoVYbSgc7x1pSMrHS1ttQMHgEbAcYFk62zh97cPdFmsOfxJaicHBuGEP0e14B3qW6M Cdpe9JQ1P8hgC6VTcnilcz9WN0vf10+wTNJXepiYQSFz5hrqr+mxSohRHdjHXth+hnBK iUaB+5WkNHN1T93OlCMhMl6sccJaOCEkM7+Wgc9C+MsyKYXthAyfmsk6w5C4LQxaVeYE xWiyDFVUglvUlf78s/VkiR5HXROL/Gm0sNuJ35aRnCcRwXOjkXaMF0b/RHb40rBd0RFk 2BYvBP9hK77A9PscbFCH29nL4zwbCaiS8mzxA73AGFSZLwDZdYNenjOBRKbRzYSL/nIv iB/Q== X-Gm-Message-State: AA+aEWZPiE1WuN+NoDUmODUTsXhgYVlMdA9ysLfsElXF/nxSPoR3rv9d m/Kge0guuV3+dfvyzH85qMQlltOrBLyH2oonmw31bg== X-Received: by 2002:a5d:8491:: with SMTP id t17mr12603247iom.11.1544525729885; Tue, 11 Dec 2018 02:55:29 -0800 (PST) MIME-Version: 1.0 References: <20181211103733.22284-1-anders.roxell@linaro.org> In-Reply-To: <20181211103733.22284-1-anders.roxell@linaro.org> From: Dmitry Vyukov Date: Tue, 11 Dec 2018 11:55:18 +0100 Message-ID: Subject: Re: [PATCH] kasan: mark kasan_check_(read|write) as 'notrace' To: anders.roxell@linaro.org Cc: Andrey Ryabinin , kasan-dev , Linux-MM , LKML , Steven Rostedt Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 11, 2018 at 11:37 AM Anders Roxell wrote: > > When option CONFIG_KASAN is enabled toghether with ftrace, function > ftrace_graph_caller() gets in to a recursion, via functions > kasan_check_read() and kasan_check_write(). > > Breakpoint 2, ftrace_graph_caller () at ../arch/arm64/kernel/entry-ftrace.S:179 > 179 mcount_get_pc x0 // function's pc > (gdb) bt > #0 ftrace_graph_caller () at ../arch/arm64/kernel/entry-ftrace.S:179 > #1 0xffffff90101406c8 in ftrace_caller () at ../arch/arm64/kernel/entry-ftrace.S:151 > #2 0xffffff90106fd084 in kasan_check_write (p=0xffffffc06c170878, size=4) at ../mm/kasan/common.c:105 > #3 0xffffff90104a2464 in atomic_add_return (v=, i=) at ./include/generated/atomic-instrumented.h:71 > #4 atomic_inc_return (v=) at ./include/generated/atomic-fallback.h:284 > #5 trace_graph_entry (trace=0xffffffc03f5ff380) at ../kernel/trace/trace_functions_graph.c:441 > #6 0xffffff9010481774 in trace_graph_entry_watchdog (trace=) at ../kernel/trace/trace_selftest.c:741 > #7 0xffffff90104a185c in function_graph_enter (ret=, func=, frame_pointer=18446743799894897728, retp=) at ../kernel/trace/trace_functions_graph.c:196 > #8 0xffffff9010140628 in prepare_ftrace_return (self_addr=18446743592948977792, parent=0xffffffc03f5ff418, frame_pointer=18446743799894897728) at ../arch/arm64/kernel/ftrace.c:231 > #9 0xffffff90101406f4 in ftrace_graph_caller () at ../arch/arm64/kernel/entry-ftrace.S:182 > Backtrace stopped: previous frame identical to this frame (corrupt stack?) > (gdb) > > Rework so that kasan_check_read() and kasan_check_write() is marked with > 'notrace'. > > Signed-off-by: Anders Roxell > --- > mm/kasan/common.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index 03d5d1374ca7..71507d15712b 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -95,13 +95,13 @@ void kasan_disable_current(void) > current->kasan_depth--; > } > > -void kasan_check_read(const volatile void *p, unsigned int size) > +void notrace kasan_check_read(const volatile void *p, unsigned int size) > { > check_memory_region((unsigned long)p, size, false, _RET_IP_); > } > EXPORT_SYMBOL(kasan_check_read); > > -void kasan_check_write(const volatile void *p, unsigned int size) > +void notrace kasan_check_write(const volatile void *p, unsigned int size) > { > check_memory_region((unsigned long)p, size, true, _RET_IP_); > } Hi Anders, Thanks for fixing this! I wonder if there is some compiler/make flag to turn this off for the whole file? We turn as much instrumentation as possible already for this file in Makefile: KASAN_SANITIZE := n UBSAN_SANITIZE_kasan.o := n KCOV_INSTRUMENT := n CFLAGS_REMOVE_kasan.o = -pg CFLAGS_kasan.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) These functions call check_memory_region, which is presumably inlined. But if it's not inlined later in some configuration, or we just shuffle code a bit, we can get the same problem again.