From patchwork Mon Mar 25 15:58:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 10869533 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 620A314DE for ; Mon, 25 Mar 2019 16:01:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D9A629484 for ; Mon, 25 Mar 2019 16:01:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40F3C29488; Mon, 25 Mar 2019 16:01:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D558829484 for ; Mon, 25 Mar 2019 16:01:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h8S0j-0000kD-So; Mon, 25 Mar 2019 15:59:41 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h8S0j-0000k8-7w for xen-devel@lists.xenproject.org; Mon, 25 Mar 2019 15:59:41 +0000 X-Inumbo-ID: fedfcb0a-4f16-11e9-bcd3-03f835757cfb Received: from mx1.redhat.com (unknown [209.132.183.28]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id fedfcb0a-4f16-11e9-bcd3-03f835757cfb; Mon, 25 Mar 2019 15:59:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03C2A3082E0F; Mon, 25 Mar 2019 15:59:39 +0000 (UTC) Received: from localhost (ovpn-116-57.ams2.redhat.com [10.36.116.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 419FD8429C; Mon, 25 Mar 2019 15:59:26 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Mon, 25 Mar 2019 15:58:51 +0000 Message-Id: <20190325155857.10661-2-stefanha@redhat.com> In-Reply-To: <20190325155857.10661-1-stefanha@redhat.com> References: <20190325155857.10661-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 25 Mar 2019 15:59:39 +0000 (UTC) Subject: [Xen-devel] [PULL 1/7] trace: handle tracefs path truncation X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Peter Maydell , kvm@vger.kernel.org, David Hildenbrand , Jason Wang , Mark Cave-Ayland , Michael Roth , Gerd Hoffmann , Eric Blake , Liam Merwick , Stefano Stabellini , xen-devel@lists.xenproject.org, qemu-block@nongnu.org, Juan Quintela , Aleksandar Rikalo , Helge Deller , "Michael S. Tsirkin" , Markus Armbruster , Halil Pasic , Christian Borntraeger , Marcel Apfelbaum , Anthony Perard , =?utf-8?q?Marc-Andr=C3=A9_Lurea?= =?utf-8?q?u?= , David Gibson , Artyom Tarasenko , Eduardo Habkost , Riku Voipio , "Dr. David Alan Gilbert" , Yuval Shaia , Greg Kurz , Alex Williamson , Paul Durrant , Stefan Hajnoczi , Igor Mammedov , John Snow , Richard Henderson , Kevin Wolf , Laurent Vivier , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Cornelia Huck , qemu-s390x@nongnu.org, Max Reitz , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Aleksandar Markovic , Paolo Bonzini , =?utf-8?q?Andreas_F=C3=A4rber?= , Aurelien Jarno , Stefan Berger Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP If the tracefs mountpoint has a very long path we may exceed PATH_MAX. This is a system misconfiguration and the user must resolve it so that applications can perform path-based system calls successfully. This issue does not occur on real-world systems since tracefs is mounted on /sys/kernel/debug/tracing/, but the compiler is smart enough to foresee the possibility and warn about the unchecked snprintf(3) return value. This patch fixes the compiler warning. Reported-by: Markus Armbruster Signed-off-by: Stefan Hajnoczi Reviewed-by: Markus Armbruster Reviewed-by: Liam Merwick Message-id: 20190321170831.6539-2-stefanha@redhat.com Message-Id: <20190321170831.6539-2-stefanha@redhat.com> Signed-off-by: Stefan Hajnoczi --- trace/ftrace.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/trace/ftrace.c b/trace/ftrace.c index 61692a8682..9749543d9b 100644 --- a/trace/ftrace.c +++ b/trace/ftrace.c @@ -53,7 +53,11 @@ bool ftrace_init(void) } if (tracefs_found) { - snprintf(path, PATH_MAX, "%s%s/tracing_on", mount_point, subdir); + if (snprintf(path, PATH_MAX, "%s%s/tracing_on", mount_point, subdir) + >= sizeof(path)) { + fprintf(stderr, "Using tracefs mountpoint would exceed PATH_MAX\n"); + return false; + } trace_fd = open(path, O_WRONLY); if (trace_fd < 0) { if (errno == EACCES) { @@ -72,7 +76,11 @@ bool ftrace_init(void) } close(trace_fd); } - snprintf(path, PATH_MAX, "%s%s/trace_marker", mount_point, subdir); + if (snprintf(path, PATH_MAX, "%s%s/trace_marker", mount_point, subdir) + >= sizeof(path)) { + fprintf(stderr, "Using tracefs mountpoint would exceed PATH_MAX\n"); + return false; + } trace_marker_fd = open(path, O_WRONLY); if (trace_marker_fd < 0) { perror("Could not open ftrace 'trace_marker' file");