From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37F84C433E0 for ; Fri, 5 Mar 2021 23:00:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EEB7A6509B for ; Fri, 5 Mar 2021 23:00:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230045AbhCEW7v (ORCPT ); Fri, 5 Mar 2021 17:59:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:48122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230070AbhCEW7t (ORCPT ); Fri, 5 Mar 2021 17:59:49 -0500 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (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 20EB364FC9 for ; Fri, 5 Mar 2021 22:59:49 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.94) (envelope-from ) id 1lIJQC-0020Ax-3t for linux-trace-devel@vger.kernel.org; Fri, 05 Mar 2021 17:59:48 -0500 Message-ID: <20210305225947.996772451@goodmis.org> User-Agent: quilt/0.66 Date: Fri, 05 Mar 2021 17:52:28 -0500 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Subject: [PATCH 5/9 v2] trace-cmd input: Validate the input handle when copying from it References: <20210305225223.794554327@goodmis.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (VMware)" Now that there's validation states, make sure that the input handle is at the correct state to validate it. Link: https://lore.kernel.org/linux-trace-devel/20210301143857.694136727@goodmis.org Signed-off-by: Steven Rostedt (VMware) --- lib/trace-cmd/trace-input.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index debc8160880e..b7166a9b1f40 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -3472,6 +3472,10 @@ static int copy_header_files(struct tracecmd_input *handle, int fd) { unsigned long long size; + /* The input handle has to have at least read the headers */ + if (handle->file_state < TRACECMD_FILE_HEADERS) + return -1; + lseek64(handle->fd, handle->header_files_start, SEEK_SET); /* "header_page" */ @@ -3503,6 +3507,10 @@ static int copy_ftrace_files(struct tracecmd_input *handle, int fd) unsigned int count; unsigned int i; + /* The input handle has to have at least read the ftrace events */ + if (handle->file_state < TRACECMD_FILE_FTRACE_EVENTS) + return -1; + if (read_copy_size4(handle, fd, &count) < 0) return -1; @@ -3526,6 +3534,10 @@ static int copy_event_files(struct tracecmd_input *handle, int fd) unsigned int count; unsigned int i,x; + /* The input handle has to have at least read all its events */ + if (handle->file_state < TRACECMD_FILE_ALL_EVENTS) + return -1; + if (read_copy_size4(handle, fd, &systems) < 0) return -1; @@ -3558,6 +3570,10 @@ static int copy_proc_kallsyms(struct tracecmd_input *handle, int fd) { unsigned int size; + /* The input handle has to have at least has kallsyms */ + if (handle->file_state < TRACECMD_FILE_KALLSYMS) + return -1; + if (read_copy_size4(handle, fd, &size) < 0) return -1; if (!size) @@ -3573,6 +3589,10 @@ static int copy_ftrace_printk(struct tracecmd_input *handle, int fd) { unsigned int size; + /* The input handle has to have at least has printk stored */ + if (handle->file_state < TRACECMD_FILE_PRINTK) + return -1; + if (read_copy_size4(handle, fd, &size) < 0) return -1; if (!size) @@ -3588,6 +3608,10 @@ static int copy_command_lines(struct tracecmd_input *handle, int fd) { unsigned long long size; + /* The input handle has to have at least read the cmdlines */ + if (handle->file_state < TRACECMD_FILE_CMD_LINES) + return -1; + if (read_copy_size8(handle, fd, &size) < 0) return -1; if (!size) -- 2.30.0