Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1518946ybg; Thu, 4 Jun 2020 11:43:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9npqv+MGPcNg5PzDZF8fqWaOCGO9cItBIJNqc4b/ATRWJ1aYbvcBjVCvJaPoorXV0nQld X-Received: by 2002:a17:906:5e05:: with SMTP id n5mr4955515eju.278.1591296192885; Thu, 04 Jun 2020 11:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591296192; cv=none; d=google.com; s=arc-20160816; b=Ssy2hRY9j/d7cLutQAoBssCJf3EE2A3Hh0nGx1alUPsZPxL5DS5qd3ct6t4Jwf4EOx KEEytgIFLMicJTx4jTwG7wXfpTHdcCDOCOJACg3NwA9mkLCu37vIfL7Zsil2JDOKQ0Kr zEdr7bt3ngOh5cgjPCFpBgSxGeHh7VClL1wofbxxDUHaQTkUx+EBBspm/lglg11VwaeQ CtXCDKZyiExhgfwAjeHzsKDBEEVGCbgQ6jR1mrKYM0ZXjzBq772P6HpQU8DTvlVjepvK detBzYd/1LEdWW4URWsiLcY6EPld7ogxhwz829Tgmcx6qrjigu/nv1mSaiLt9kZbk0ct Q0dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=bKAdfvJmk5cJtK5g50ZHk8hu9sp158iPwKZPpTWkeYg=; b=JzZv6gO9+uHFnkjnZzVTS6j9ER997rz0zyo7TqsQXFLB8oRSZlFJ9iPJxmCyjMAwsf JNRK1r05D4puCdq91vCq3nWWodXCi3WBA9nnqUIJCOWCBRa6b2B6YhZkGihL2vvwG+SN XU+BXdUSlXNoBfv/2Zw+I8h/v2eFtmZqN8haaS+BWqSdb+bl7NpUhfIRU6D8X/0ZEWV4 LKEX9jnF1N+T8s7tnRtVtXLVBEBNRLthAyy7Vh/68WHoYvPnOW80WPdjOpecx7SwWgZQ uCVBe0KYKEwErQUyFOAHmqvE5+4KMC/Vbdk1wZtj29bk3aC8cQUWBxYItlVElJy898Rl vd0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cx3si2159508edb.547.2020.06.04.11.42.50; Thu, 04 Jun 2020 11:43:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728752AbgFDNvF (ORCPT + 99 others); Thu, 4 Jun 2020 09:51:05 -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-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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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); -- 2.25.2