Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5625805imu; Mon, 26 Nov 2018 03:10:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/XERzxlnHYRyR0as0r5oOmuPH3+RhHLqEIqLFrybPe513M6D5gqYWt/PEwm2jxWy/awuRI3 X-Received: by 2002:a63:d252:: with SMTP id t18mr24491654pgi.133.1543230646995; Mon, 26 Nov 2018 03:10:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543230646; cv=none; d=google.com; s=arc-20160816; b=Kt9VRkzjDBzwNW6eawmKoyzhwkuhsxoWaywZnp5hCzBYkKKVyRoY7EQW4skFl/d8YG k9mS/AUYi44oFT0k34Gt7kE1p2j5B6toSsNyoWX5NjeeAAmXWCNlz9eKuIeQrcQpNW15 7hgPFUVDTnyggwi6XhuoH8MpdZYd7WDQ87VaHbkYUxx1/npZ3y86ql0m+ETntb8nwAuc m1UgyR0Xt2nbM2DQ0ltDJU6iOyMOMXSEzHynXP2ugCFZ2Z4nCfuxJeOFHSlHrNx0ypRz 1ugemeSWciHnXKmo1VZuP34Mc15ykcWxuUl2DCjSi2YjLmdRmPkviPgfyiC8Eex9xKVy 8WWQ== 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=92vg/i28xCKsbVm0uT/VtX7R8rGd7EpJEk57pmWEKsE=; b=1LBLWxcggyXMqXiKoYI11xNznxIT5tjG2q95qN9ObaksDjr1TAJfQfMShwxipgdgkI KiNyGkET+hlgHRSsOTx3/FUus9QsIjaJCD0zDCoQzxHhXIeOMuHBvnI1xJvGYiqEiTdg ZF5ikCRlgxRb7GtcBGnh4A5KN7cNNgNfjycc32YeNuE6NdtStks9BQSZjMive94cyvsE GK9jnrloF5MxyOaccqYla5SCfh2voSXqLiB9HQ0vr30mOuq76sLKwsoJSSln+WnfKYxh oCSLzL1UC7YWu0tg3ixEe1SbDHOJdoeHC2tHFvMSLBzLw+xp6AUjw2aSc3vaSeqCjyIz w7ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=e7Mx1IA4; 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 m30si30823462pff.158.2018.11.26.03.10.32; Mon, 26 Nov 2018 03:10:46 -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=e7Mx1IA4; 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 S1731293AbeKZV7L (ORCPT + 99 others); Mon, 26 Nov 2018 16:59:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:44972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730303AbeKZV7K (ORCPT ); Mon, 26 Nov 2018 16:59:10 -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 EC0F120645; Mon, 26 Nov 2018 11:05:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543230324; bh=ElH9xEJI70Bbb3g5JLWstlUoXcK8xKpLk1OApFmwX0I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e7Mx1IA4OuHJKgAPMXY19gIKI7cw1tMOrbCFe/l6qPVOxSfr3sP0QSUJRkPpOvJf8 KyxnIM/wrzcpqpLIWp0YSdHyNbZ1n+8Ye5PBzsfrG3fUDZwd0xHlX5J5aDEbBNjPLL UZp/oASQCurl4qjefibhFiaHHTlYmEt/KlMJPiDk= 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.19 075/118] perf tools: Fix undefined symbol scnprintf in libperf-jvmti.so Date: Mon, 26 Nov 2018 11:51:09 +0100 Message-Id: <20181126105104.493028280@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181126105059.832485122@linuxfoundation.org> References: <20181126105059.832485122@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.19-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 ac1bcdc17dae..f7eb63cbbc65 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