Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2167710imu; Wed, 12 Dec 2018 10:37:11 -0800 (PST) X-Google-Smtp-Source: AFSGD/VV9DNySYqzCkJBi7YUAycjfebJY4H2+LMbuROf0h0gBSZXJmcqEI4CSov127WILMNSoWyO X-Received: by 2002:a17:902:48:: with SMTP id 66mr20229765pla.68.1544639831396; Wed, 12 Dec 2018 10:37:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544639831; cv=none; d=google.com; s=arc-20160816; b=s2ksHJBfcKKq8UyWTWiSNDSNEVkX9hryIwcdxqztDQdmbQHKZgEJRRrtfoJnDXUqQg K0UHiF/VGYW3/Vd04Shk1jy19SZReBNVhW6SjtNAs2tvhAq05wWZ0KwgtdtjCYjNLOLR gDt7YZTM0Vt/bNlAMT9AW1nZ5uzix1M++6+kdWeGZBySRgmKeo7yOLjDdRxPbhOQ2fmS 3ofJUR+A4P6jy703eNmH/dU94KZFD4Ux9OQBlsf6KsXQ1rTKcVXfhqzzvgtbnqMgHAAb mFe2xYsgyLz2Eb0Fl1tpOAmmOqL2Kcd4uQCRErKXKmxvK0iS+k89tlcqXez1+09gWGDo ailg== 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=gLFkzZ47/NSlvBRoi2hymf7yNACYMKV1jQLM//dnV+8=; b=hnDpB1xRtqQQ6Iw+cRpsaR2P15T6rmVVM1BDs4LISguZfjK6P198fw6tSYbRI0Tnm/ CijXw8QsWkRIkOjCQFL9QLURTqVDw8mvdvybtzP1NLN4XoHYoP8JNJ+gsqeZSJFFBfTP 1spXddanYO5Ptjsjxtl4+CGEDJ/7CTGI2lwKtUcJ9A5CynUTZMd0b8+PEHgdRcOqJ4A7 +ACln1q5947nHWq2IZI1BiBYzz08zLD4lyk77R97kaO8vNp7K89ecZzQFYWGhYpnkQx5 sPw24MIbHJgXqGK8XsV6xL1KuDiF6/TrU1lWXaiBzXNKNsix2+YsSsdIiNPonN/boCJe 0zrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KiXjvh4+; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v10si14869594pgg.510.2018.12.12.10.36.55; Wed, 12 Dec 2018 10:37:11 -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=@linaro.org header.s=google header.b=KiXjvh4+; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728183AbeLLSgC (ORCPT + 99 others); Wed, 12 Dec 2018 13:36:02 -0500 Received: from mail-yw1-f68.google.com ([209.85.161.68]:33095 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727888AbeLLSgB (ORCPT ); Wed, 12 Dec 2018 13:36:01 -0500 Received: by mail-yw1-f68.google.com with SMTP id q11so7389779ywa.0 for ; Wed, 12 Dec 2018 10:36:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gLFkzZ47/NSlvBRoi2hymf7yNACYMKV1jQLM//dnV+8=; b=KiXjvh4+R8WJNSxrnzLpaIVgFqVoaoV0N4E0b98yGfj2rr8CSMALR6a2RoUS3j6NQy 29ndrmcb/QUb2uuy/LbXMxHvkf9CkG7m1xIgJwF0y7u9RrTieX2V53LoeiMuN4snQdqZ SqttWjASOOT63AJT6B7syOSSEwOuiHNkcoRSU= 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=gLFkzZ47/NSlvBRoi2hymf7yNACYMKV1jQLM//dnV+8=; b=qz4PTC5kgr/a5dS8Kd7m68uEu7PwVyXYAJhkJjTgBbeJq+2Kht/Xzidaxpt5WM76VW DPYtR7IGVo7zhxdk5Vgis5nA7pKmjDrIDpWrJ+LCwWWWp0YEG5ZcU+aYp7rqUkI1b6sJ K3zHX540ociHXgbayCJy8VI3AqOb+vwVFOvhAPpv9LgSaJZpcqUibNz9TmJNZlulzux7 QcilVkt+lLYdDWHL3VEOb8+OcMlPx4ToBFnHYgYYORTmrFPPxDlostzwjYx0pacfw0KH HraQQ2khzChtBnQffiI1UAisclwPm7qRtGGatUpzuDhk0zIho+8Q2x0606r0RFczFc1O h/nw== X-Gm-Message-State: AA+aEWbY+VZRFkEY2MPwU7DgvNx+mYu/LLjH7V3vhJs95TmpUdnfI6To G+k6Lg8QfYoI6gYrwvcAO6QDJBpK2I/ifXRRHzRgpjxg23Q= X-Received: by 2002:a81:e40b:: with SMTP id r11mr21546436ywl.56.1544639760220; Wed, 12 Dec 2018 10:36:00 -0800 (PST) MIME-Version: 1.0 References: <20181211103733.22284-1-anders.roxell@linaro.org> In-Reply-To: From: Anders Roxell Date: Wed, 12 Dec 2018 19:35:48 +0100 Message-ID: Subject: Re: [PATCH] kasan: mark kasan_check_(read|write) as 'notrace' To: Dmitry Vyukov Cc: aryabinin@virtuozzo.com, kasan-dev@googlegroups.com, linux-mm@kvack.org, Linux Kernel Mailing List , rostedt@goodmis.org 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, 11 Dec 2018 at 11:55, Dmitry Vyukov wrote: > > 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. Thank you for the review. I'll send out a v2 shortly where I turned off the hole file. Cheers, Anders