Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2279342imm; Tue, 10 Jul 2018 17:11:43 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcioL6HES/tac8SU/FpaouYNEj4pW/udO1YbkPlOqtMf9yglCdM/Rr20MmA2h1pwdRhwK2w X-Received: by 2002:a63:b95c:: with SMTP id v28-v6mr18304758pgo.162.1531267903292; Tue, 10 Jul 2018 17:11:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531267903; cv=none; d=google.com; s=arc-20160816; b=xU76+Obnr1DwmrefMHED0ESSipYTE4RdkeuyrxxDmR+YrpP+uRrIMnmkO51AzIBD56 GlLey/tvFMoExN+Lr8vIje9DdjQSSw3JyPvX8TrSEhb/jbQ/64xWJPD6azg+YVy+VRzl Wu75CDLo1yMSz6Y0EAPRrffmnX8szXCH5zv9BhVkku6GMgEeEwncha0/1ts6mOAlQn23 i+DAeTfaSyMdL0EQkOqyahd9m4mD47LxD86Li4fn8LAJEvbLYyCn4WebK6K16DkdNP9F ll77kI8GVa9UJ0PrKQVwqaFYddyIpmW4AlIhJVLWBvtOOjLhwYk5Nvi8PxnRkVTK9FuG ES/g== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=SmnbLk4YNx/bwYldX5+8I1+fkVs3JucB/eysFQd7HPk=; b=J+OrOGZZo/9mP5FGZYSKYmI0F85rYenrkaDpcGSb0nZAKKWmIJKTeG/LlAfkIDOYC0 4vtohxK+fImCDlbiXdKYtHLOYXIas1QxLj0fDjNCxUSGaHF1bBK/+/Y7Fhi9+b2hFdX1 zAu9KnQJYcbcs8aeQX/4lBF2XNR41mGNDbIgQtEMYA9K7Z56zNItK7ksbljCVtId0Wx2 OdCP2rXPBPA5MmN4T/DphJ7SyT0jTq2botA0zftdmPH5af4C96mP/2xFIKRMH/oh1/se 0wz/AJiJd+rlE/S8zAdxP/jDBJBOa4RNeLwMk4t6Z94HptBygHmWGXn7lJ79m7EZ3Q8V jqrQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x1-v6si11968686pga.480.2018.07.10.17.11.27; Tue, 10 Jul 2018 17:11:43 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732306AbeGKALn (ORCPT + 99 others); Tue, 10 Jul 2018 20:11:43 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45492 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732262AbeGKALn (ORCPT ); Tue, 10 Jul 2018 20:11:43 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EA4B6818F703; Wed, 11 Jul 2018 00:10:10 +0000 (UTC) Received: from [10.10.120.22] (ovpn-120-22.rdu2.redhat.com [10.10.120.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9EC5111DD02; Wed, 11 Jul 2018 00:10:10 +0000 (UTC) Subject: Re: [PATCH] Check jvmti_agent snprintf return value to avoid build failures with GCC-8.1.1 To: Jiri Olsa Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, linux-kernel@vger.kernel.org, alexander.shishkin@linux.intel.com, namhyung@kernel.org References: <20180710182716.21801-1-wcohen@redhat.com> <20180710225824.GA11928@krava> From: William Cohen Message-ID: Date: Tue, 10 Jul 2018 20:10:10 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180710225824.GA11928@krava> Content-Type: text/plain; charset=utf-8 Content-Language: en-MW Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 11 Jul 2018 00:10:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 11 Jul 2018 00:10:11 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'wcohen@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/10/2018 06:58 PM, Jiri Olsa wrote: > On Tue, Jul 10, 2018 at 02:27:16PM -0400, William Cohen wrote: >> Newer versions of GCC perform static analysis to determine whether >> string truncation is possible with functions such as snprintf and >> provide a warning if truncation could occur. The make for >> jvmti_agent.c uses the compiler option that treats any compiler >> warnings as compiler errors. For GCC-8.1.1 in Fedora 28 this causes >> the build to fail. The return value of the snprint is now checked to >> ensure snprintf produced a NULL-terminated string. If the string for >> the path is invalid, the code does attempt to use the string. > > hi, > I posted fix for this recently: > https://lore.kernel.org/lkml/20180702134202.17745-1-jolsa@kernel.org/ > > it also covers the perf_regs.c, which was failing with gcc8 for me > > should be pulled in soon > > thanks, > jirka Hi Jirka, Thanks. I hadn't seen the patch, and this failing to build for the past week has been bugging me. Glad to hear there is already a fix queued up. -Will > >> >> Signed-off-by: William Cohen >> --- >> tools/perf/jvmti/jvmti_agent.c | 7 +++++-- >> 1 file changed, 5 insertions(+), 2 deletions(-) >> >> diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c >> index 0c6d1002b524..30f14eafe4b3 100644 >> --- a/tools/perf/jvmti/jvmti_agent.c >> +++ b/tools/perf/jvmti/jvmti_agent.c >> @@ -227,7 +227,7 @@ void *jvmti_open(void) >> { >> char dump_path[PATH_MAX]; >> struct jitheader header; >> - int fd; >> + int retlen, fd; >> FILE *fp; >> >> init_arch_timestamp(); >> @@ -249,7 +249,10 @@ void *jvmti_open(void) >> /* >> * jitdump file name >> */ >> - snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid()); >> + retlen = snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", >> + jit_path, getpid()); >> + if (retlen <= 0 || ((int) sizeof(dump_path)) <= retlen) >> + return NULL; >> >> fd = open(dump_path, O_CREAT|O_TRUNC|O_RDWR, 0666); >> if (fd == -1) >> -- >> 2.17.1 >>