Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5616571imu; Mon, 26 Nov 2018 03:03:53 -0800 (PST) X-Google-Smtp-Source: AJdET5dREreAqp+0t2XhzTqg3WLQMeh3vHr5Ub6AxOWj+lzEMGnCGqIy3d3CK4Nq0N0jBa8Ky0pb X-Received: by 2002:a62:5716:: with SMTP id l22mr27181899pfb.16.1543230233802; Mon, 26 Nov 2018 03:03:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543230233; cv=none; d=google.com; s=arc-20160816; b=RVdid8mGBpEaqKKvgxKOT9ddiPn3MyamfHmMympSnuF+KxN7qh9i6dt7oCV7+q+Bcm D9TZBeObXnm8U8z5saYvXofs3jLFiynUaB3MisAwAo76pJ6RcQN3V7gAQc09S2L11fhS venftXS4nrVJpe7baJnJZpoNdPyXmZ+NMYJEcfvEhskd8m/wdN3iydbKrr531yCtRFV8 OWZbs6WIKQQCjVnkKHNC034wtii7/3C+sswuzyJyn6dBNwQ4rpnFvvwVJsAXQ4xMf5CF e1KK5WzkzNlzeGBlC+afFtBfEbG40P9+/bVCsLv5Fmelec4PJnhBbIXuqY6Xs8JxpTwx BN1w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DiOMzQbEFKgiy2VVyV2miN7Eg3N6QZA3vKxF7e6ghiY=; b=e1+IzVlhbwRB1PGy1skpCBDd2gEp0tsIyAvHchn+hL6gIVfjBH5wYMhkO/ooXUGC+7 d5nHqtWCnUhbJ/itb94PWRXY2RAj7GcfpRM2IkhrIrqe04LFNK9aSPYejXL+EiV4ztsJ Gq2o0vPt/pmq6ycPdrTQ8/2I080Sie/HjkOojz8zzHpT9PH9TRek+DNldOf8nrpFcWqQ jDbNjjA2sK4WgRJYWCOBvrZp1jO8+7ABb1S2JisX8nMXPPAtRG8SWALSRBY0xbsW/HoJ LvzehlhQQOCyuaoB8XxkB1AbHX7jkYg+1k8hZzeXqMS3BJaZgr2MngY4iBt4gPx5SC2x RdGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="U/Y6GSNQ"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a25si26318261pgw.195.2018.11.26.03.03.37; Mon, 26 Nov 2018 03:03:53 -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=@kernel.org header.s=default header.b="U/Y6GSNQ"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729947AbeKZVyf (ORCPT + 99 others); Mon, 26 Nov 2018 16:54:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:36790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728754AbeKZVye (ORCPT ); Mon, 26 Nov 2018 16:54:34 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 634AF21104; Mon, 26 Nov 2018 11:00:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543230048; bh=8muD36xnniW+erm5UE0elZT0S8oBwmT8lvGvA9kPhkU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U/Y6GSNQ8LuYfEP4R6sy5kFlSBYtOOIM4t20aep22snjrASRBDTpG1j5dYj5HDrDc sormLCe7l2nvizZMrsYMD+KFgzyYbhJhW5bgAgQxdfQoNFb7upNNMQjyjV12uDSd8I UpVd/nb4GsoxwJK2q8kQYEyUm01AnR2uH+uISy54= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gustavo Romero , Jiri Olsa , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.14 34/62] perf tools: Fix undefined symbol scnprintf in libperf-jvmti.so Date: Mon, 26 Nov 2018 11:51:15 +0100 Message-Id: <20181126105053.504181964@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181126105050.592727680@linuxfoundation.org> References: <20181126105050.592727680@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 6ac2226229d931153331a93d90655a3de05b9290 ] Currently jvmti agent can not be used because function scnprintf is not present in the agent libperf-jvmti.so. As a result the JVM when using such agent to record JITed code profiling information will fail on looking up scnprintf: java: symbol lookup error: lib/libperf-jvmti.so: undefined symbol: scnprintf This commit fixes that by reverting to the use of snprintf, that can be looked up, instead of scnprintf, adding a proper check for the returned value in order to print a better error message when the jitdump file pathname is too long. Checking the returned value also helps to comply with some recent gcc versions, like gcc8, which will fail due to truncated writing checks related to the -Werror=format-truncation= flag. Signed-off-by: Gustavo Romero Acked-by: Jiri Olsa LPU-Reference: 1541117601-18937-2-git-send-email-gromero@linux.vnet.ibm.com Link: https://lkml.kernel.org/n/tip-mvpxxxy7wnzaj74cq75muw3f@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/jvmti/jvmti_agent.c | 49 ++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c index c1d20d951434..4ad9948fe594 100644 --- a/tools/perf/jvmti/jvmti_agent.c +++ b/tools/perf/jvmti/jvmti_agent.c @@ -125,7 +125,7 @@ perf_get_timestamp(void) } static int -debug_cache_init(void) +create_jit_cache_dir(void) { char str[32]; char *base, *p; @@ -144,8 +144,13 @@ debug_cache_init(void) strftime(str, sizeof(str), JIT_LANG"-jit-%Y%m%d", &tm); - snprintf(jit_path, PATH_MAX - 1, "%s/.debug/", base); - + ret = snprintf(jit_path, PATH_MAX, "%s/.debug/", base); + if (ret >= PATH_MAX) { + warnx("jvmti: cannot generate jit cache dir because %s/.debug/" + " is too long, please check the cwd, JITDUMPDIR, and" + " HOME variables", base); + return -1; + } ret = mkdir(jit_path, 0755); if (ret == -1) { if (errno != EEXIST) { @@ -154,20 +159,32 @@ debug_cache_init(void) } } - snprintf(jit_path, PATH_MAX - 1, "%s/.debug/jit", base); + ret = snprintf(jit_path, PATH_MAX, "%s/.debug/jit", base); + if (ret >= PATH_MAX) { + warnx("jvmti: cannot generate jit cache dir because" + " %s/.debug/jit is too long, please check the cwd," + " JITDUMPDIR, and HOME variables", base); + return -1; + } ret = mkdir(jit_path, 0755); if (ret == -1) { if (errno != EEXIST) { - warn("cannot create jit cache dir %s", jit_path); + warn("jvmti: cannot create jit cache dir %s", jit_path); return -1; } } - snprintf(jit_path, PATH_MAX - 1, "%s/.debug/jit/%s.XXXXXXXX", base, str); - + ret = snprintf(jit_path, PATH_MAX, "%s/.debug/jit/%s.XXXXXXXX", base, str); + if (ret >= PATH_MAX) { + warnx("jvmti: cannot generate jit cache dir because" + " %s/.debug/jit/%s.XXXXXXXX is too long, please check" + " the cwd, JITDUMPDIR, and HOME variables", + base, str); + return -1; + } p = mkdtemp(jit_path); if (p != jit_path) { - warn("cannot create jit cache dir %s", jit_path); + warn("jvmti: cannot create jit cache dir %s", jit_path); return -1; } @@ -228,7 +245,7 @@ void *jvmti_open(void) { char dump_path[PATH_MAX]; struct jitheader header; - int fd; + int fd, ret; FILE *fp; init_arch_timestamp(); @@ -245,12 +262,22 @@ void *jvmti_open(void) memset(&header, 0, sizeof(header)); - debug_cache_init(); + /* + * jitdump file dir + */ + if (create_jit_cache_dir() < 0) + return NULL; /* * jitdump file name */ - scnprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid()); + ret = snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid()); + if (ret >= PATH_MAX) { + warnx("jvmti: cannot generate jitdump file full path because" + " %s/jit-%i.dump is too long, please check the cwd," + " JITDUMPDIR, and HOME variables", jit_path, getpid()); + return NULL; + } fd = open(dump_path, O_CREAT|O_TRUNC|O_RDWR, 0666); if (fd == -1) -- 2.17.1