From patchwork Thu Jun 4 13:49:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Popov X-Patchwork-Id: 11588005 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC0D690 for ; Thu, 4 Jun 2020 13:50:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C52D620772 for ; Thu, 4 Jun 2020 13:50:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728720AbgFDNus (ORCPT ); Thu, 4 Jun 2020 09:50:48 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:44327 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728337AbgFDNur (ORCPT ); Thu, 4 Jun 2020 09:50:47 -0400 Received: by mail-lj1-f195.google.com with SMTP id c17so7346666lji.11; Thu, 04 Jun 2020 06:50:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HscaqQ3a9rlG7LMvxfetj9PZadqBQlxA9luDvY709kI=; b=ai6pgs+Tew/uxPdpW0D6kM9fjKaFU57Yse/NujW+695tWtAZsHbMGGjsRLwvkvSFdM tKaKvGQpWjWbihXm9SM7bzwIuUyydb6gftVGfGn+rqrf8iT84i2RTj6MP76Pkb3s7Wtv u2i1GX3tx60c2Sye/K5XP1y5zvn163ycQ1SR1IDsoyjiGPkmpQ9nc5k8xIuY7cpNXkxe Ny3vMLTeLJHhVYOFYSlJMhAkaXrk7pKOBF/AP1p5BtvMyovAinP3X23oSRcwCyermoIZ OOdjYs1SLiwTCfRS0PA+Ha75IlelzNAKXJeEctRiFvw7bbdTtJSLgfapP+/Nti9yhtyg q8Nw== X-Gm-Message-State: AOAM530Fkf4utpvodap55ttY2/yNOYsu0YKEeaGDv2lW83PULYVAn2oJ 4Axxi4wbLXQjpHiWggk/vqM= X-Google-Smtp-Source: ABdhPJwFgNnX9eJFc5s+1RCeoml4wry3jADSZr+Uk82Gr4M4947yFLD4wkmGdf/0gl0X9+wHhybHLA== X-Received: by 2002:a2e:8ec9:: with SMTP id e9mr2378478ljl.152.1591278644807; Thu, 04 Jun 2020 06:50:44 -0700 (PDT) Received: from localhost.localdomain ([185.248.161.177]) by smtp.gmail.com with ESMTPSA id u16sm1202140lji.58.2020.06.04.06.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 06:50:43 -0700 (PDT) From: Alexander Popov To: Kees Cook , Emese Revfy , Miguel Ojeda , Masahiro Yamada , Michal Marek , Andrew Morton , Masahiro Yamada , Thiago Jung Bauermann , Luis Chamberlain , Jessica Yu , Sven Schnelle , Iurii Zaikin , Catalin Marinas , Will Deacon , Vincenzo Frascino , Thomas Gleixner , Peter Collingbourne , Naohiro Aota , Alexander Monakov , Mathias Krause , PaX Team , Brad Spengler , Laura Abbott , Florian Weimer , Alexander Popov , kernel-hardening@lists.openwall.com, linux-kbuild@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, gcc@gcc.gnu.org Cc: notify@kernel.org Subject: [PATCH 1/5] gcc-plugins/stackleak: Exclude alloca() from the instrumentation logic Date: Thu, 4 Jun 2020 16:49:53 +0300 Message-Id: <20200604134957.505389-2-alex.popov@linux.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200604134957.505389-1-alex.popov@linux.com> References: <20200604134957.505389-1-alex.popov@linux.com> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Some time ago Variable Length Arrays (VLA) were removed from the kernel. The kernel is built with '-Wvla'. Let's exclude alloca() from the instrumentation logic and make it simpler. The build-time assertion against alloca() is added instead. Unfortunately, for that assertion we can't simply check cfun->calls_alloca during RTL phase. It turned out that gcc before version 7 called allocate_dynamic_stack_space() from expand_stack_vars() for runtime alignment of constant-sized stack variables. That caused cfun->calls_alloca to be set for functions that don't use alloca(). Signed-off-by: Alexander Popov --- scripts/gcc-plugins/stackleak_plugin.c | 51 +++++++++++--------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/scripts/gcc-plugins/stackleak_plugin.c b/scripts/gcc-plugins/stackleak_plugin.c index cc75eeba0be1..1ecfe50d0bf5 100644 --- a/scripts/gcc-plugins/stackleak_plugin.c +++ b/scripts/gcc-plugins/stackleak_plugin.c @@ -9,10 +9,9 @@ * any of the gcc libraries * * This gcc plugin is needed for tracking the lowest border of the kernel stack. - * It instruments the kernel code inserting stackleak_track_stack() calls: - * - after alloca(); - * - for the functions with a stack frame size greater than or equal - * to the "track-min-size" plugin parameter. + * It instruments the kernel code inserting stackleak_track_stack() calls + * for the functions with a stack frame size greater than or equal to + * the "track-min-size" plugin parameter. * * This plugin is ported from grsecurity/PaX. For more information see: * https://grsecurity.net/ @@ -46,7 +45,7 @@ static struct plugin_info stackleak_plugin_info = { "disable\t\tdo not activate the plugin\n" }; -static void stackleak_add_track_stack(gimple_stmt_iterator *gsi, bool after) +static void stackleak_add_track_stack(gimple_stmt_iterator *gsi) { gimple stmt; gcall *stackleak_track_stack; @@ -56,12 +55,7 @@ static void stackleak_add_track_stack(gimple_stmt_iterator *gsi, bool after) /* Insert call to void stackleak_track_stack(void) */ stmt = gimple_build_call(track_function_decl, 0); stackleak_track_stack = as_a_gcall(stmt); - if (after) { - gsi_insert_after(gsi, stackleak_track_stack, - GSI_CONTINUE_LINKING); - } else { - gsi_insert_before(gsi, stackleak_track_stack, GSI_SAME_STMT); - } + gsi_insert_before(gsi, stackleak_track_stack, GSI_SAME_STMT); /* Update the cgraph */ bb = gimple_bb(stackleak_track_stack); @@ -87,14 +81,13 @@ static bool is_alloca(gimple stmt) /* * Work with the GIMPLE representation of the code. Insert the - * stackleak_track_stack() call after alloca() and into the beginning - * of the function if it is not instrumented. + * stackleak_track_stack() call into the beginning of the function. */ static unsigned int stackleak_instrument_execute(void) { basic_block bb, entry_bb; - bool prologue_instrumented = false, is_leaf = true; - gimple_stmt_iterator gsi; + bool is_leaf = true; + gimple_stmt_iterator gsi = { 0 }; /* * ENTRY_BLOCK_PTR is a basic block which represents possible entry @@ -111,27 +104,17 @@ static unsigned int stackleak_instrument_execute(void) */ FOR_EACH_BB_FN(bb, cfun) { for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) { - gimple stmt; - - stmt = gsi_stmt(gsi); + gimple stmt = gsi_stmt(gsi); /* Leaf function is a function which makes no calls */ if (is_gimple_call(stmt)) is_leaf = false; - if (!is_alloca(stmt)) - continue; - - /* Insert stackleak_track_stack() call after alloca() */ - stackleak_add_track_stack(&gsi, true); - if (bb == entry_bb) - prologue_instrumented = true; + /* Variable Length Arrays are forbidden in the kernel */ + gcc_assert(!is_alloca(stmt)); } } - if (prologue_instrumented) - return 0; - /* * Special cases to skip the instrumentation. * @@ -168,7 +151,7 @@ static unsigned int stackleak_instrument_execute(void) bb = single_succ(ENTRY_BLOCK_PTR_FOR_FN(cfun)); } gsi = gsi_after_labels(bb); - stackleak_add_track_stack(&gsi, false); + stackleak_add_track_stack(&gsi); return 0; } @@ -185,12 +168,20 @@ static bool large_stack_frame(void) /* * Work with the RTL representation of the code. * Remove the unneeded stackleak_track_stack() calls from the functions - * which don't call alloca() and don't have a large enough stack frame size. + * that don't have a large enough stack frame size. */ static unsigned int stackleak_cleanup_execute(void) { rtx_insn *insn, *next; + /* + * gcc before version 7 called allocate_dynamic_stack_space() from + * expand_stack_vars() for runtime alignment of constant-sized stack + * variables. That caused cfun->calls_alloca to be set for functions + * that don't use alloca(). + * For more info see gcc commit 7072df0aae0c59ae437e. + * Let's leave such functions instrumented. + */ if (cfun->calls_alloca) return 0; From patchwork Thu Jun 4 13:49:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Popov X-Patchwork-Id: 11588011 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5242C90 for ; Thu, 4 Jun 2020 13:51:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 35E8D207DF for ; Thu, 4 Jun 2020 13:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728747AbgFDNu7 (ORCPT ); Thu, 4 Jun 2020 09:50:59 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:46102 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728337AbgFDNu7 (ORCPT ); Thu, 4 Jun 2020 09:50:59 -0400 Received: by mail-lj1-f195.google.com with SMTP id z9so7348162ljh.13; Thu, 04 Jun 2020 06:50:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=veE4ryhNxfX6ZFy5y/056vSNcU7CVnJM+8TvlXBsnxg=; b=Kvh0L4M/3Mk+toh11iCe3Jynas1NiBKd151xmfRDcxvY3dO49OwrOc0ltmRPDeTD0X 5HfPRDlR6JCUPq9QdmOQB91La5A9WqfU34syL8wZHwV/JgovEH87Mf8xGPQN1/oIGdJn AliZ8ReGl60Tj1o8xg5Yi3RZEcs2jfvzyjFYQ0qgakc3VjQwsO0tVxoTWTP2ocI9N+Rt o+/GCqr9f2G7zWKrdGuVYtwPVOU3vbTbXl5j3csIiDvhcfCbTRwXVv74Hw2sV2YtGJ3o 2zykpVyVei324Q01v0p3us/wfpJjBxay7hSkKbY7ri4G9hG1petFS2OMEwQzoCAKchdI 2osg== X-Gm-Message-State: AOAM531QB8bQVG4eGtcXbAHWr9G2YTMje75no+4LHkm1k5oXppY4UQL9 cLY0RGhN8iP9Fb7Ur8p2KA8= X-Google-Smtp-Source: ABdhPJz45dvq67oRkAcFtWa0JEo3iXihFP3HlC8qTG+v1AYwJ3zV75VqaPI1cWNLL3tULYWeEuqGdw== X-Received: by 2002:a2e:85da:: with SMTP id h26mr465715ljj.170.1591278652554; Thu, 04 Jun 2020 06:50:52 -0700 (PDT) Received: from localhost.localdomain ([185.248.161.177]) by smtp.gmail.com with ESMTPSA id u16sm1202140lji.58.2020.06.04.06.50.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 06:50:51 -0700 (PDT) From: Alexander Popov To: Kees Cook , Emese Revfy , Miguel Ojeda , Masahiro Yamada , Michal Marek , Andrew Morton , Masahiro Yamada , Thiago Jung Bauermann , Luis Chamberlain , Jessica Yu , Sven Schnelle , Iurii Zaikin , Catalin Marinas , Will Deacon , Vincenzo Frascino , Thomas Gleixner , Peter Collingbourne , Naohiro Aota , Alexander Monakov , Mathias Krause , PaX Team , Brad Spengler , Laura Abbott , Florian Weimer , Alexander Popov , kernel-hardening@lists.openwall.com, linux-kbuild@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, gcc@gcc.gnu.org Cc: notify@kernel.org Subject: [PATCH 2/5] gcc-plugins/stackleak: Use asm instrumentation to avoid useless register saving Date: Thu, 4 Jun 2020 16:49:54 +0300 Message-Id: <20200604134957.505389-3-alex.popov@linux.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200604134957.505389-1-alex.popov@linux.com> References: <20200604134957.505389-1-alex.popov@linux.com> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org The kernel code instrumentation in stackleak gcc plugin works in two stages. At first, stack tracking is added to GIMPLE representation of every function (except some special cases). And later, when stack frame size info is available, stack tracking is removed from the RTL representation of the functions with small stack frame. There is an unwanted side-effect for these functions: some of them do useless work with caller-saved registers. As an example of such case, proc_sys_write without instrumentation: 55 push %rbp 41 b8 01 00 00 00 mov $0x1,%r8d 48 89 e5 mov %rsp,%rbp e8 11 ff ff ff callq ffffffff81284610 5d pop %rbp c3 retq 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 00 00 00 proc_sys_write with instrumentation: 55 push %rbp 48 89 e5 mov %rsp,%rbp 41 56 push %r14 41 55 push %r13 41 54 push %r12 53 push %rbx 49 89 f4 mov %rsi,%r12 48 89 fb mov %rdi,%rbx 49 89 d5 mov %rdx,%r13 49 89 ce mov %rcx,%r14 4c 89 f1 mov %r14,%rcx 4c 89 ea mov %r13,%rdx 4c 89 e6 mov %r12,%rsi 48 89 df mov %rbx,%rdi 41 b8 01 00 00 00 mov $0x1,%r8d e8 f2 fe ff ff callq ffffffff81298e80 5b pop %rbx 41 5c pop %r12 41 5d pop %r13 41 5e pop %r14 5d pop %rbp c3 retq 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1) 00 00 Let's improve the instrumentation to avoid this: 1. Make stackleak_track_stack() save all register that it works with. Use no_caller_saved_registers attribute for that function. This attribute is available for x86_64 and i386 starting from gcc-7. 2. Insert calling stackleak_track_stack() in asm: asm volatile("call stackleak_track_stack" :: "r" (current_stack_pointer)) Here we use ASM_CALL_CONSTRAINT trick from arch/x86/include/asm/asm.h. The input constraint is taken into account during gcc shrink-wrapping optimization. It is needed to be sure that stackleak_track_stack() call is inserted after the prologue of the containing function, when the stack frame is prepared. This work is a deep reengineering of the idea described on grsecurity blog https://grsecurity.net/resolving_an_unfortunate_stackleak_interaction Signed-off-by: Alexander Popov Acked-by: Miguel Ojeda --- include/linux/compiler_attributes.h | 13 ++ kernel/stackleak.c | 16 +- scripts/Makefile.gcc-plugins | 2 + scripts/gcc-plugins/stackleak_plugin.c | 206 +++++++++++++++++++++---- 4 files changed, 196 insertions(+), 41 deletions(-) diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h index cdf016596659..522d57ae8532 100644 --- a/include/linux/compiler_attributes.h +++ b/include/linux/compiler_attributes.h @@ -41,6 +41,7 @@ # define __GCC4_has_attribute___nonstring__ 0 # define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8) # define __GCC4_has_attribute___fallthrough__ 0 +# define __GCC4_has_attribute___no_caller_saved_registers__ 0 #endif /* @@ -175,6 +176,18 @@ */ #define __mode(x) __attribute__((__mode__(x))) +/* + * Optional: only supported since gcc >= 7 + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html#index-no_005fcaller_005fsaved_005fregisters-function-attribute_002c-x86 + * clang: https://clang.llvm.org/docs/AttributeReference.html#no-caller-saved-registers + */ +#if __has_attribute(__no_caller_saved_registers__) +# define __no_caller_saved_registers __attribute__((__no_caller_saved_registers__)) +#else +# define __no_caller_saved_registers +#endif + /* * Optional: not supported by clang * diff --git a/kernel/stackleak.c b/kernel/stackleak.c index b193a59fc05b..a8fc9ae1d03d 100644 --- a/kernel/stackleak.c +++ b/kernel/stackleak.c @@ -104,19 +104,9 @@ asmlinkage void notrace stackleak_erase(void) } NOKPROBE_SYMBOL(stackleak_erase); -void __used notrace stackleak_track_stack(void) +void __used __no_caller_saved_registers notrace stackleak_track_stack(void) { - /* - * N.B. stackleak_erase() fills the kernel stack with the poison value, - * which has the register width. That code assumes that the value - * of 'lowest_stack' is aligned on the register width boundary. - * - * That is true for x86 and x86_64 because of the kernel stack - * alignment on these platforms (for details, see 'cc_stack_align' in - * arch/x86/Makefile). Take care of that when you port STACKLEAK to - * new platforms. - */ - unsigned long sp = (unsigned long)&sp; + unsigned long sp = current_stack_pointer; /* * Having CONFIG_STACKLEAK_TRACK_MIN_SIZE larger than @@ -125,6 +115,8 @@ void __used notrace stackleak_track_stack(void) */ BUILD_BUG_ON(CONFIG_STACKLEAK_TRACK_MIN_SIZE > STACKLEAK_SEARCH_DEPTH); + /* 'lowest_stack' should be aligned on the register width boundary */ + sp = ALIGN(sp, sizeof(unsigned long)); if (sp < current->lowest_stack && sp >= (unsigned long)task_stack_page(current) + sizeof(unsigned long)) { diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins index 5f7df50cfe7a..952e46876329 100644 --- a/scripts/Makefile.gcc-plugins +++ b/scripts/Makefile.gcc-plugins @@ -33,6 +33,8 @@ gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \ += -DSTACKLEAK_PLUGIN gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \ += -fplugin-arg-stackleak_plugin-track-min-size=$(CONFIG_STACKLEAK_TRACK_MIN_SIZE) +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \ + += -fplugin-arg-stackleak_plugin-arch=$(SRCARCH) ifdef CONFIG_GCC_PLUGIN_STACKLEAK DISABLE_STACKLEAK_PLUGIN += -fplugin-arg-stackleak_plugin-disable endif diff --git a/scripts/gcc-plugins/stackleak_plugin.c b/scripts/gcc-plugins/stackleak_plugin.c index 1ecfe50d0bf5..0769c5b9156d 100644 --- a/scripts/gcc-plugins/stackleak_plugin.c +++ b/scripts/gcc-plugins/stackleak_plugin.c @@ -19,7 +19,7 @@ * * Debugging: * - use fprintf() to stderr, debug_generic_expr(), debug_gimple_stmt(), - * print_rtl() and print_simple_rtl(); + * print_rtl_single() and debug_rtx(); * - add "-fdump-tree-all -fdump-rtl-all" to the plugin CFLAGS in * Makefile.gcc-plugins to see the verbose dumps of the gcc passes; * - use gcc -E to understand the preprocessing shenanigans; @@ -31,6 +31,7 @@ __visible int plugin_is_GPL_compatible; static int track_frame_size = -1; +static bool build_for_x86 = false; static const char track_function[] = "stackleak_track_stack"; /* @@ -42,27 +43,28 @@ static GTY(()) tree track_function_decl; static struct plugin_info stackleak_plugin_info = { .version = "201707101337", .help = "track-min-size=nn\ttrack stack for functions with a stack frame size >= nn bytes\n" + "arch=target_arch\tspecify target build arch\n" "disable\t\tdo not activate the plugin\n" }; -static void stackleak_add_track_stack(gimple_stmt_iterator *gsi) +static void add_stack_tracking_gcall(gimple_stmt_iterator *gsi) { gimple stmt; - gcall *stackleak_track_stack; + gcall *gimple_call; cgraph_node_ptr node; basic_block bb; - /* Insert call to void stackleak_track_stack(void) */ + /* Insert calling stackleak_track_stack() */ stmt = gimple_build_call(track_function_decl, 0); - stackleak_track_stack = as_a_gcall(stmt); - gsi_insert_before(gsi, stackleak_track_stack, GSI_SAME_STMT); + gimple_call = as_a_gcall(stmt); + gsi_insert_before(gsi, gimple_call, GSI_SAME_STMT); /* Update the cgraph */ - bb = gimple_bb(stackleak_track_stack); + bb = gimple_bb(gimple_call); node = cgraph_get_create_node(track_function_decl); gcc_assert(node); cgraph_create_edge(cgraph_get_node(current_function_decl), node, - stackleak_track_stack, bb->count, + gimple_call, bb->count, compute_call_stmt_bb_frequency(current_function_decl, bb)); } @@ -79,6 +81,76 @@ static bool is_alloca(gimple stmt) return false; } +static tree get_current_stack_pointer_decl(void) +{ + varpool_node_ptr node; + + FOR_EACH_VARIABLE(node) { + tree var = NODE_DECL(node); + tree name = DECL_NAME(var); + + if (DECL_NAME_LENGTH(var) != sizeof("current_stack_pointer") - 1) + continue; + + if (strcmp(IDENTIFIER_POINTER(name), "current_stack_pointer")) + continue; + + return var; + } + + return NULL_TREE; +} + +static void add_stack_tracking_gasm(gimple_stmt_iterator *gsi) +{ + gasm *asm_call = NULL; + tree sp_decl, input; + vec *inputs = NULL; + + /* 'no_caller_saved_registers' is currently supported only for x86 */ + gcc_assert(build_for_x86); + + /* + * Insert calling stackleak_track_stack() in asm: + * asm volatile("call stackleak_track_stack" + * :: "r" (current_stack_pointer)) + * Use ASM_CALL_CONSTRAINT trick from arch/x86/include/asm/asm.h. + * This constraint is taken into account during gcc shrink-wrapping + * optimization. It is needed to be sure that stackleak_track_stack() + * call is inserted after the prologue of the containing function, + * when the stack frame is prepared. + */ + sp_decl = get_current_stack_pointer_decl(); + if (sp_decl == NULL_TREE) { + add_stack_tracking_gcall(gsi); + return; + } + input = build_tree_list(NULL_TREE, build_const_char_string(2, "r")); + input = chainon(NULL_TREE, build_tree_list(input, sp_decl)); + vec_safe_push(inputs, input); + asm_call = gimple_build_asm_vec("call stackleak_track_stack", + inputs, NULL, NULL, NULL); + gimple_asm_set_volatile(asm_call, true); + gsi_insert_before(gsi, asm_call, GSI_SAME_STMT); + update_stmt(asm_call); +} + +static void add_stack_tracking(gimple_stmt_iterator *gsi) +{ + /* + * The 'no_caller_saved_registers' attribute is used for + * stackleak_track_stack(). If the compiler supports this attribute for + * the target arch, we can add calling stackleak_track_stack() in asm. + * That improves performance: we avoid useless operations with the + * caller-saved registers in the functions from which we will remove + * stackleak_track_stack() call during the stackleak_cleanup pass. + */ + if (lookup_attribute_spec(get_identifier("no_caller_saved_registers"))) + add_stack_tracking_gasm(gsi); + else + add_stack_tracking_gcall(gsi); +} + /* * Work with the GIMPLE representation of the code. Insert the * stackleak_track_stack() call into the beginning of the function. @@ -151,7 +223,7 @@ static unsigned int stackleak_instrument_execute(void) bb = single_succ(ENTRY_BLOCK_PTR_FOR_FN(cfun)); } gsi = gsi_after_labels(bb); - stackleak_add_track_stack(&gsi); + add_stack_tracking(&gsi); return 0; } @@ -165,29 +237,10 @@ static bool large_stack_frame(void) #endif } -/* - * Work with the RTL representation of the code. - * Remove the unneeded stackleak_track_stack() calls from the functions - * that don't have a large enough stack frame size. - */ -static unsigned int stackleak_cleanup_execute(void) +static void remove_stack_tracking_gcall(void) { rtx_insn *insn, *next; - /* - * gcc before version 7 called allocate_dynamic_stack_space() from - * expand_stack_vars() for runtime alignment of constant-sized stack - * variables. That caused cfun->calls_alloca to be set for functions - * that don't use alloca(). - * For more info see gcc commit 7072df0aae0c59ae437e. - * Let's leave such functions instrumented. - */ - if (cfun->calls_alloca) - return 0; - - if (large_stack_frame()) - return 0; - /* * Find stackleak_track_stack() calls. Loop through the chain of insns, * which is an RTL representation of the code for a function. @@ -248,6 +301,92 @@ static unsigned int stackleak_cleanup_execute(void) } #endif } +} + +static bool remove_stack_tracking_gasm(void) +{ + bool removed = false; + rtx_insn *insn, *next; + + /* 'no_caller_saved_registers' is currently supported only for x86 */ + gcc_assert(build_for_x86); + + /* + * Find stackleak_track_stack() asm calls. Loop through the chain of + * insns, which is an RTL representation of the code for a function. + * + * The example of a matching insn: + * (insn 11 5 12 2 (parallel [ (asm_operands/v + * ("call stackleak_track_stack") ("") 0 + * [ (reg/v:DI 7 sp [ current_stack_pointer ]) ] + * [ (asm_input:DI ("r")) ] []) + * (clobber (reg:CC 17 flags)) ]) -1 (nil)) + */ + for (insn = get_insns(); insn; insn = next) { + rtx body; + + next = NEXT_INSN(insn); + + /* Check the expression code of the insn */ + if (!NONJUMP_INSN_P(insn)) + continue; + + /* + * Check the expression code of the insn body, which is an RTL + * Expression (RTX) describing the side effect performed by + * that insn. + */ + body = PATTERN(insn); + + if (GET_CODE(body) != PARALLEL) + continue; + + body = XVECEXP(body, 0, 0); + + if (GET_CODE(body) != ASM_OPERANDS) + continue; + + if (strcmp(ASM_OPERANDS_TEMPLATE(body), + "call stackleak_track_stack")) { + continue; + } + + delete_insn_and_edges(insn); + gcc_assert(!removed); + removed = true; + } + + return removed; +} + +/* + * Work with the RTL representation of the code. + * Remove the unneeded stackleak_track_stack() calls from the functions + * that don't have a large enough stack frame size. + */ +static unsigned int stackleak_cleanup_execute(void) +{ + bool removed = false; + + /* + * gcc before version 7 called allocate_dynamic_stack_space() from + * expand_stack_vars() for runtime alignment of constant-sized stack + * variables. That caused cfun->calls_alloca to be set for functions + * that don't use alloca(). + * For more info see gcc commit 7072df0aae0c59ae437e. + * Let's leave such functions instrumented. + */ + if (cfun->calls_alloca) + return 0; + + if (large_stack_frame()) + return 0; + + if (lookup_attribute_spec(get_identifier("no_caller_saved_registers"))) + removed = remove_stack_tracking_gasm(); + + if (!removed) + remove_stack_tracking_gcall(); return 0; } @@ -383,6 +522,15 @@ __visible int plugin_init(struct plugin_name_args *plugin_info, plugin_name, argv[i].key, argv[i].value); return 1; } + } else if (!strcmp(argv[i].key, "arch")) { + if (!argv[i].value) { + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), + plugin_name, argv[i].key); + return 1; + } + + if (!strcmp(argv[i].value, "x86")) + build_for_x86 = true; } else { error(G_("unknown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key); From patchwork Thu Jun 4 13:49:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Popov X-Patchwork-Id: 11588013 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF9B414F6 for ; Thu, 4 Jun 2020 13:51:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD02820823 for ; Thu, 4 Jun 2020 13:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728765AbgFDNvE (ORCPT ); Thu, 4 Jun 2020 09:51:04 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:36533 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728337AbgFDNvE (ORCPT ); Thu, 4 Jun 2020 09:51:04 -0400 Received: by mail-lj1-f194.google.com with SMTP id a25so7393145ljp.3; Thu, 04 Jun 2020 06:51:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bKAdfvJmk5cJtK5g50ZHk8hu9sp158iPwKZPpTWkeYg=; b=DV96Se4S22dmiFQNd/zpCZb4Udp/1dnorm0KnM9bvHrcSU/Bi8GS1pPYkrzI8M8mv9 qMFWkmpK8d26PRC4j41lixJL/vCL+6LuEbmNDQTpl30cVCwCzLa8+FTVQwjSICPf8wu7 kBhZnoUEuk8XBfQtOPjuiPFqyxlcZMiJuP1Kl8i4+A/whxa0pMQ/ONd1FAR32+I/O628 7vPUnS9WMBxOrGelLbb6Kj8iihDeAAW6evLIHzHsXdlNPqkVtQ5/31aatEvDRfdDJkLx 30WJsqEpMUraq4QT4UOtAnvTrUT20Pijz1JqWiyic/zMrmRl214aRHNFIomjnGsPDqCH IF3g== X-Gm-Message-State: AOAM530Jca8lBZ2ID2KeXoyeVfPP4BW8YHRzYhwc/G/fmFFjiLSEySO2 SLiFA76+0FqjFe5bsR8jrU0= X-Google-Smtp-Source: ABdhPJyaEJiFG1nukoZekZitzyjRXSvRiSbJSp8S8jS/4CPjpOJZ15oCqdnMtSvYh0QGwlrPyIn8nA== X-Received: by 2002:a2e:9917:: with SMTP id v23mr2338833lji.225.1591278660052; Thu, 04 Jun 2020 06:51:00 -0700 (PDT) Received: from localhost.localdomain ([185.248.161.177]) by smtp.gmail.com with ESMTPSA id u16sm1202140lji.58.2020.06.04.06.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 06:50:59 -0700 (PDT) From: Alexander Popov To: Kees Cook , Emese Revfy , Miguel Ojeda , Masahiro Yamada , Michal Marek , Andrew Morton , Masahiro Yamada , Thiago Jung Bauermann , Luis Chamberlain , Jessica Yu , Sven Schnelle , Iurii Zaikin , Catalin Marinas , Will Deacon , Vincenzo Frascino , Thomas Gleixner , Peter Collingbourne , Naohiro Aota , Alexander Monakov , Mathias Krause , PaX Team , Brad Spengler , Laura Abbott , Florian Weimer , Alexander Popov , kernel-hardening@lists.openwall.com, linux-kbuild@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, gcc@gcc.gnu.org Cc: notify@kernel.org Subject: [PATCH 3/5] gcc-plugins/stackleak: Add 'verbose' plugin parameter Date: Thu, 4 Jun 2020 16:49:55 +0300 Message-Id: <20200604134957.505389-4-alex.popov@linux.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200604134957.505389-1-alex.popov@linux.com> References: <20200604134957.505389-1-alex.popov@linux.com> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Add 'verbose' plugin parameter for stackleak gcc plugin. It can be used for printing additional info about the kernel code instrumentation. For using it add the following to scripts/Makefile.gcc-plugins: gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \ += -fplugin-arg-stackleak_plugin-verbose Signed-off-by: Alexander Popov Acked-by: Kees Cook --- scripts/gcc-plugins/stackleak_plugin.c | 31 +++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/scripts/gcc-plugins/stackleak_plugin.c b/scripts/gcc-plugins/stackleak_plugin.c index 0769c5b9156d..19358712d4ed 100644 --- a/scripts/gcc-plugins/stackleak_plugin.c +++ b/scripts/gcc-plugins/stackleak_plugin.c @@ -33,6 +33,8 @@ __visible int plugin_is_GPL_compatible; static int track_frame_size = -1; static bool build_for_x86 = false; static const char track_function[] = "stackleak_track_stack"; +static bool disable = false; +static bool verbose = false; /* * Mark these global variables (roots) for gcc garbage collector since @@ -45,6 +47,7 @@ static struct plugin_info stackleak_plugin_info = { .help = "track-min-size=nn\ttrack stack for functions with a stack frame size >= nn bytes\n" "arch=target_arch\tspecify target build arch\n" "disable\t\tdo not activate the plugin\n" + "verbose\t\tprint info about the instrumentation\n" }; static void add_stack_tracking_gcall(gimple_stmt_iterator *gsi) @@ -98,6 +101,10 @@ static tree get_current_stack_pointer_decl(void) return var; } + if (verbose) { + fprintf(stderr, "stackleak: missing current_stack_pointer in %s()\n", + DECL_NAME_POINTER(current_function_decl)); + } return NULL_TREE; } @@ -366,6 +373,7 @@ static bool remove_stack_tracking_gasm(void) */ static unsigned int stackleak_cleanup_execute(void) { + const char *fn = DECL_NAME_POINTER(current_function_decl); bool removed = false; /* @@ -376,11 +384,17 @@ static unsigned int stackleak_cleanup_execute(void) * For more info see gcc commit 7072df0aae0c59ae437e. * Let's leave such functions instrumented. */ - if (cfun->calls_alloca) + if (cfun->calls_alloca) { + if (verbose) + fprintf(stderr, "stackleak: instrument %s() old\n", fn); return 0; + } - if (large_stack_frame()) + if (large_stack_frame()) { + if (verbose) + fprintf(stderr, "stackleak: instrument %s()\n", fn); return 0; + } if (lookup_attribute_spec(get_identifier("no_caller_saved_registers"))) removed = remove_stack_tracking_gasm(); @@ -506,9 +520,6 @@ __visible int plugin_init(struct plugin_name_args *plugin_info, /* Parse the plugin arguments */ for (i = 0; i < argc; i++) { - if (!strcmp(argv[i].key, "disable")) - return 0; - if (!strcmp(argv[i].key, "track-min-size")) { if (!argv[i].value) { error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), @@ -531,6 +542,10 @@ __visible int plugin_init(struct plugin_name_args *plugin_info, if (!strcmp(argv[i].value, "x86")) build_for_x86 = true; + } else if (!strcmp(argv[i].key, "disable")) { + disable = true; + } else if (!strcmp(argv[i].key, "verbose")) { + verbose = true; } else { error(G_("unknown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key); @@ -538,6 +553,12 @@ __visible int plugin_init(struct plugin_name_args *plugin_info, } } + if (disable) { + if (verbose) + fprintf(stderr, "stackleak: disabled for this translation unit\n"); + return 0; + } + /* Give the information about the plugin */ register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info); From patchwork Thu Jun 4 13:49:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Popov X-Patchwork-Id: 11588015 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2B64C739 for ; Thu, 4 Jun 2020 13:51:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1CEEA207DF for ; Thu, 4 Jun 2020 13:51:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728669AbgFDNvJ (ORCPT ); Thu, 4 Jun 2020 09:51:09 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:45601 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728337AbgFDNvJ (ORCPT ); Thu, 4 Jun 2020 09:51:09 -0400 Received: by mail-lf1-f67.google.com with SMTP id d7so3632854lfi.12; Thu, 04 Jun 2020 06:51:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JQF4gusMMse1t+P2Qqr0GcfguvDdOuRmX3WacGaJBcQ=; b=jF6IvBPDfMIYlTCQV/874CGcg+W6j/SRtw8BgSNN1uQQqTIMWsvwPMo30KpjABSsA2 8hEYk9DwoZdit+/S+QM45zZBeO2m2sqwm8AOvJfFZ13RyngfU9IJZrchZXhxtNES2NDm P2JNVPSgvDxgpnPrZ6ALtujS5TC7ytqjTgwnlUpB95NzkMxHojnRHJ+7zxqBJYtUxHBD sd+Q9PX0RN9m9hZFN3OrctTDwH/gk1L+w4Q4j+5w1PI5lN5tDBoCl53uieUeJDCQv+9x 9l6lN+tH1LYJgo9yUR4J6q9t/M6eqvynqT6/EfOOCPJ3k8yqbHypwOQg5pdEQfcvwqXa +Whg== X-Gm-Message-State: AOAM533rHTzkcbSv6nzmJ5qEQrbDmke6aUZBsIShTcniVv4e2aFYZB49 RWQr2myVyTqGM+DNiX2KFE4= X-Google-Smtp-Source: ABdhPJxGDD5ukdedXoxuQ27N5jKq1fSsreuCe9q3nAgk5mstTvN2pJQfkeE/l29dSTZfbBg2leMMKA== X-Received: by 2002:a05:6512:3214:: with SMTP id d20mr2637853lfe.203.1591278666991; Thu, 04 Jun 2020 06:51:06 -0700 (PDT) Received: from localhost.localdomain ([185.248.161.177]) by smtp.gmail.com with ESMTPSA id u16sm1202140lji.58.2020.06.04.06.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 06:51:06 -0700 (PDT) From: Alexander Popov To: Kees Cook , Emese Revfy , Miguel Ojeda , Masahiro Yamada , Michal Marek , Andrew Morton , Masahiro Yamada , Thiago Jung Bauermann , Luis Chamberlain , Jessica Yu , Sven Schnelle , Iurii Zaikin , Catalin Marinas , Will Deacon , Vincenzo Frascino , Thomas Gleixner , Peter Collingbourne , Naohiro Aota , Alexander Monakov , Mathias Krause , PaX Team , Brad Spengler , Laura Abbott , Florian Weimer , Alexander Popov , kernel-hardening@lists.openwall.com, linux-kbuild@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, gcc@gcc.gnu.org Cc: notify@kernel.org Subject: [PATCH 4/5] gcc-plugins/stackleak: Don't instrument itself Date: Thu, 4 Jun 2020 16:49:56 +0300 Message-Id: <20200604134957.505389-5-alex.popov@linux.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200604134957.505389-1-alex.popov@linux.com> References: <20200604134957.505389-1-alex.popov@linux.com> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org There is no need to try instrumenting functions in kernel/stackleak.c. Otherwise that can cause issues if the cleanup pass of stackleak gcc plugin is disabled. Signed-off-by: Alexander Popov Acked-by: Kees Cook --- kernel/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/Makefile b/kernel/Makefile index 4cb4130ced32..d372134ac9ec 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -118,6 +118,7 @@ obj-$(CONFIG_RSEQ) += rseq.o obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o +CFLAGS_stackleak.o += $(DISABLE_STACKLEAK_PLUGIN) obj-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak.o KASAN_SANITIZE_stackleak.o := n KCOV_INSTRUMENT_stackleak.o := n From patchwork Thu Jun 4 13:49:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Popov X-Patchwork-Id: 11588019 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BDAF7739 for ; Thu, 4 Jun 2020 13:51:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB130207F7 for ; Thu, 4 Jun 2020 13:51:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728769AbgFDNvQ (ORCPT ); Thu, 4 Jun 2020 09:51:16 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:40568 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728337AbgFDNvP (ORCPT ); Thu, 4 Jun 2020 09:51:15 -0400 Received: by mail-lj1-f195.google.com with SMTP id n23so7383230ljh.7; Thu, 04 Jun 2020 06:51:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b54SpJMSTOd6h+DBnk1Lku3f1oWBTa5w9a5vkJqB3fA=; b=NOKcnCnHmgLbHUot2+eJwnhNzECR4FMJbk1qYoqQ++S6V2X9r5jBm1/aDrPWux9kwy m5F5YKtwExVAXlAfK49L4gUJmTQvaoTjxmyG7L6/xUmKQ6iIAPIuMgp6oaRPQkdgkNBz Dd6QdErvBVfzOFIaT5DcZ0Az8tl7YC4DQXIKlUizcvvV4D/ULFHbZJgURjYeqyFVVvFB DmsFka4YcYyzeQfvItGHaw8a/lIrpRR9VUiJ1uHPgP+8tUWzQBIwix+oYOwV1fF7OUt1 lzx45X/YW1QqeS73mP+f8ggeTav//83ZS++hJP5swqVnZdInGo3ZnClz6nq/RpH1dr+p 8zRw== X-Gm-Message-State: AOAM532isEgAATR8l2s5HmPS1pTIEoHJPvtDt4NPuDjHRU9q6bnj8/fc 4M+w2vojj9gRWxPyH2K1Ci4= X-Google-Smtp-Source: ABdhPJwJN+QU/v5qwJyKhHL0R8cAYtbe3PO9Gpb/m6COOlcWqK5m8q5guhRTY5qY7edIDaq2chb7lg== X-Received: by 2002:a2e:9dd8:: with SMTP id x24mr2410838ljj.304.1591278673307; Thu, 04 Jun 2020 06:51:13 -0700 (PDT) Received: from localhost.localdomain ([185.248.161.177]) by smtp.gmail.com with ESMTPSA id u16sm1202140lji.58.2020.06.04.06.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 06:51:12 -0700 (PDT) From: Alexander Popov To: Kees Cook , Emese Revfy , Miguel Ojeda , Masahiro Yamada , Michal Marek , Andrew Morton , Masahiro Yamada , Thiago Jung Bauermann , Luis Chamberlain , Jessica Yu , Sven Schnelle , Iurii Zaikin , Catalin Marinas , Will Deacon , Vincenzo Frascino , Thomas Gleixner , Peter Collingbourne , Naohiro Aota , Alexander Monakov , Mathias Krause , PaX Team , Brad Spengler , Laura Abbott , Florian Weimer , Alexander Popov , kernel-hardening@lists.openwall.com, linux-kbuild@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, gcc@gcc.gnu.org Cc: notify@kernel.org Subject: [PATCH 5/5] gcc-plugins/stackleak: Don't instrument vgettimeofday.c in arm64 VDSO Date: Thu, 4 Jun 2020 16:49:57 +0300 Message-Id: <20200604134957.505389-6-alex.popov@linux.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200604134957.505389-1-alex.popov@linux.com> References: <20200604134957.505389-1-alex.popov@linux.com> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Don't try instrumenting functions in arch/arm64/kernel/vdso/vgettimeofday.c. Otherwise that can cause issues if the cleanup pass of stackleak gcc plugin is disabled. Signed-off-by: Alexander Popov --- arch/arm64/kernel/vdso/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile index 3862cad2410c..9b84cafbd2da 100644 --- a/arch/arm64/kernel/vdso/Makefile +++ b/arch/arm64/kernel/vdso/Makefile @@ -32,7 +32,8 @@ UBSAN_SANITIZE := n OBJECT_FILES_NON_STANDARD := y KCOV_INSTRUMENT := n -CFLAGS_vgettimeofday.o = -O2 -mcmodel=tiny -fasynchronous-unwind-tables +CFLAGS_vgettimeofday.o = -O2 -mcmodel=tiny -fasynchronous-unwind-tables \ + $(DISABLE_STACKLEAK_PLUGIN) ifneq ($(c-gettimeofday-y),) CFLAGS_vgettimeofday.o += -include $(c-gettimeofday-y)