From patchwork Wed Jun 5 13:40:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686947 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7184195FE5 for ; Wed, 5 Jun 2024 13:41:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594867; cv=none; b=FC5LAQF9edudGb6Aor6CWMZNDZBcpuVl8xRoOe3mpIWNC/IWrSryquYATm0lncI64354Q6DJt3lDGAeNkTnh94sUqU//K6Mlw+FG1IQ2SCThc4Zy6L0TK7o72AeVRUzDau90iBtkMeN4oMXYO/GYFmt+XlzNue9Ukshu+q7X9DE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594867; c=relaxed/simple; bh=Gyf0Ao0Z2gjWvuNmJS3dHbHkhe1u6OjzaStYIP3Y74Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qUrVJNk4upRRqlL71IKs0/4T4DCmhAmtSQGOcuk+vqTmAV8RPJEx/X0JsL4Eqg55nzU2mYZi19XM+T0MeD9Is+SAWbyuXQVsa23KY7FA4a5ahyjsFPKauavO8R5CiKYtwmMrMux5CGswkeq8AJksZUkez32XMoPpZxQ9k5GvtFY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ixqa5WRf; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ixqa5WRf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2VqFyjphm+3LAKVuySnRLNB5SrdYb9PbNw/VjFFGRr4=; b=ixqa5WRfbLWPX0P5Le6nkPFPc4rcCO+KomI1k21CpME2FKvHIjUXqh2HmRLCebWP9jLajE GY2FdC8Jd/PJrUZtVEDev6Qqd2pqehRJXj54+LpyLDV4npRKnkJBUstIouOrNzfK73do+J 3adfTVO7YZ8H3b2yzqJBz1XECtsPurw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-155-bdU2IUz0Pjiq09hBfWw5Fg-1; Wed, 05 Jun 2024 09:41:01 -0400 X-MC-Unique: bdU2IUz0Pjiq09hBfWw5Fg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3F8C085A588; Wed, 5 Jun 2024 13:41:01 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id 68C6737D0; Wed, 5 Jun 2024 13:40:59 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:40:58 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 01/38] trace-cmd listen: close ofd before exiting process_client() Date: Wed, 5 Jun 2024 15:40:16 +0200 Message-ID: <20240605134054.2626953-2-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Close ofd in the error path and at the end of the function. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- tracecmd/trace-listen.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tracecmd/trace-listen.c b/tracecmd/trace-listen.c index 5894a92d..09f442c7 100644 --- a/tracecmd/trace-listen.c +++ b/tracecmd/trace-listen.c @@ -696,8 +696,10 @@ static int process_client(struct tracecmd_msg_handle *msg_handle, ofd = create_client_file(node, port); pid_array = create_all_readers(node, port, pagesize, msg_handle); - if (!pid_array) + if (!pid_array) { + close(ofd); return -ENOMEM; + } /* on signal stop this msg */ stop_msg_handle = msg_handle; @@ -725,6 +727,7 @@ static int process_client(struct tracecmd_msg_handle *msg_handle, msg_handle->version < V3_PROTOCOL); destroy_all_readers(cpus, pid_array, node, port); + close(ofd); return ret; } From patchwork Wed Jun 5 13:40:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686948 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4F2E195FE4 for ; Wed, 5 Jun 2024 13:41:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594871; cv=none; b=PCwZT0EDuHaDOwYWQrJniRc/vHBLo8s3QNPR2tEJRqIXtfBIsZ0CzgpRO6sUahbtzOGQouyvyjsGL9EPI2YREC2g20rI9trxgtiiBI9cx9Tf7D3HDNTkFL/Ulr5rdWHxKlRGJu9M4Rm8S8aOU+9PHb6sA9DAvT58rbVwj6bYwWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594871; c=relaxed/simple; bh=kSdj8X2YTt1jV/AVgWCwFTejqymYC5/BXMN6lNpM2Jw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BwNwrsSZ5tuMyAHsltfVSinnegnI9g966VwvmJLLmJ3OVItBWPNYikF2gpbw52K5YJ2Ck7f433K0+fVRYElDtUXx3PbtmE4QAk1x/B9L0IJfg+qPb93glXkngUHEJrfzEfy9f/v5C9gl13oExRzqzqruNg8GTFWPJpOPnHbTwCM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Hnn1lsHp; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Hnn1lsHp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594868; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Yv4Jsp6nEsOsNYMxuQDgQPrhjnu8PW9f0Zwj6uqDtbk=; b=Hnn1lsHpYBiUWy/mUrDk7pO3yHhwVzXtsx646a3Hjhygqde18kzvWj2eAHN/wqTF5VPZGe mC9e5Lc1EKdYeVQ1bnGvDBVYYOh5jN4LLrxUzIxvkGKLBdZUyIrei/nXnfyg28jEt9RRo/ F1Rhc42y7UHMX7RhrP3fcz6Onz4txiQ= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-124-zk7VbjiHO_KExTmdLy2kGA-1; Wed, 05 Jun 2024 09:41:06 -0400 X-MC-Unique: zk7VbjiHO_KExTmdLy2kGA-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 72E171955D78; Wed, 5 Jun 2024 13:41:05 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 15A8F1956055; Wed, 5 Jun 2024 13:41:02 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:01 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 02/38] trace-cmd msg: prevent a memory leak in get_trace_req_args() Date: Wed, 5 Jun 2024 15:40:17 +0200 Message-ID: <20240605134054.2626953-3-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 In get_trace_req_args() vagrs is not freed when the function exits without an error. This could be of course be fixed by freeing vagrs before exit, but actually I don't see the point of the buffer at all since it just use to copy the content of buf and then read to fill args. Why not just read from buf to begin with? Remove vagrs and use buf directly. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-msg.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/lib/trace-cmd/trace-msg.c b/lib/trace-cmd/trace-msg.c index 3a555c36..f5c604f1 100644 --- a/lib/trace-cmd/trace-msg.c +++ b/lib/trace-cmd/trace-msg.c @@ -1247,7 +1247,6 @@ static int get_trace_req_args(char *buf, int length, int *argc, char ***argv) unsigned int nr_args; char *p, *buf_end; char **args = NULL; - char *vagrs = NULL; int ret; int i; @@ -1266,15 +1265,8 @@ static int get_trace_req_args(char *buf, int length, int *argc, char ***argv) goto out; } - vagrs = calloc(length, sizeof(char)); - if (!vagrs) { - ret = -ENOMEM; - goto out; - } - - memcpy(vagrs, buf, length); - buf_end = vagrs + length; - for (i = 0, p = vagrs; i < nr_args; i++, p++) { + buf_end = buf + length; + for (i = 0, p = buf; i < nr_args; i++, p++) { if (p >= buf_end) { ret = -EINVAL; goto out; @@ -1289,7 +1281,6 @@ static int get_trace_req_args(char *buf, int length, int *argc, char ***argv) out: free(args); - free(vagrs); return ret; } From patchwork Wed Jun 5 13:40:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686949 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35AB3195FE4 for ; Wed, 5 Jun 2024 13:41:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594874; cv=none; b=N01GcHBQrjH/B1jyiZB00wGhaQ2HY1jkic+fi8w9BzLgaysqS7tujjeBM1gZkbYf5nHO16opSZDRAXaxprykaRpzH346d17EpJfqiPPfQfrOKzJmljpneWnMoemUgPNg6JrQH05HEYHBXhA0xduvtdUuJRJA2rd1dfA2srzG/lo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594874; c=relaxed/simple; bh=O4PJMMqyGKFigLXli0H76Ma27Bi8cFo6ZSankqUUVqY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XQPgfOz+NvE33hPfM76ZzCviMyU7WFlXk8nhm86pRlY4kbyzv2PjFjksVLngNJkgDQ5IwA24dQVjZr1h4lfeCzNye3sIb0G7Hr9yrHFvyuJhu1b3JbnFmrOPQAW+tPnU6mZpgF0bULw2SOFJaGYKuuEeKBByWerUZlRhWZbj+2w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=d05IEX4R; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="d05IEX4R" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594872; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZMUUdJmHdsZIUgCcBsI+CMz60m+gIRuaFqHSTUGioZ0=; b=d05IEX4RBy0zK2jGDpnycVyAH45yLDl7JBbFYE1jAfCFmMFjArLoEv4E3VMnbzalr9JJ0f cLjGprxnSpyn/ijdJm/TillcSkgkPwK9GP2bBn/MQGxjJoRDMWrYWGhHlnL54yRIYXfm76 3JwHZe30C9aD/eRk5cq1Hm0ZGABk0k4= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-39-VNUOPQHsPcKaOoBv5qrW2w-1; Wed, 05 Jun 2024 09:41:11 -0400 X-MC-Unique: VNUOPQHsPcKaOoBv5qrW2w-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C28951953966; Wed, 5 Jun 2024 13:41:09 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 58D0E1956055; Wed, 5 Jun 2024 13:41:07 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:05 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 03/38] trace-cmd lib: prevent a memory leak in read_header_files() Date: Wed, 5 Jun 2024 15:40:18 +0200 Message-ID: <20240605134054.2626953-4-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 In read_header_files() path is allocated a few times by get_tracing_file(). It isn't freed in multiple error paths. Free it whenever needed. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-output.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index eee847e3..59498edc 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -644,8 +644,10 @@ static int read_header_files(struct tracecmd_output *handle, bool compress) flags |= TRACECMD_SEC_FL_COMPRESS; offset = out_write_section_header(handle, TRACECMD_OPTION_HEADER_INFO, "headers", flags, true); - if (offset == (off_t)-1) + if (offset == (off_t)-1) { + put_tracing_file(path); return -1; + } out_compression_start(handle, compress); ret = stat(path, &st); @@ -671,23 +673,23 @@ static int read_header_files(struct tracecmd_output *handle, bool compress) fd = open(path, O_RDONLY); if (fd < 0) { tracecmd_warning("can't read '%s'", path); - goto out_close; + goto out_free; } /* unfortunately, you can not stat debugfs files for size */ size = get_size_fd(fd); if (do_write_check(handle, "header_page", 12)) - goto out_close; + goto out_free; endian8 = convert_endian_8(handle, size); if (do_write_check(handle, &endian8, 8)) - goto out_close; + goto out_free; check_size = copy_file_fd(handle, fd, 0); close(fd); if (size != check_size) { tracecmd_warning("wrong size for '%s' size=%lld read=%lld", path, size, check_size); errno = EINVAL; - goto out_close; + goto out_free; } put_tracing_file(path); @@ -698,21 +700,21 @@ static int read_header_files(struct tracecmd_output *handle, bool compress) fd = open(path, O_RDONLY); if (fd < 0) { tracecmd_warning("can't read '%s'", path); - goto out_close; + goto out_free; } size = get_size_fd(fd); if (do_write_check(handle, "header_event", 13)) - goto out_close; + goto out_free; endian8 = convert_endian_8(handle, size); if (do_write_check(handle, &endian8, 8)) - goto out_close; + goto out_free; check_size = copy_file_fd(handle, fd, 0); close(fd); if (size != check_size) { tracecmd_warning("wrong size for '%s'", path); - goto out_close; + goto out_free; } put_tracing_file(path); if (out_compression_end(handle, compress)) @@ -724,6 +726,8 @@ static int read_header_files(struct tracecmd_output *handle, bool compress) return 0; + out_free: + put_tracing_file(path); out_close: out_compression_reset(handle, compress); if (fd >= 0) From patchwork Wed Jun 5 13:40:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686950 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DA6F1953AF for ; Wed, 5 Jun 2024 13:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594879; cv=none; b=S3YgQIarLKDyUgsssw8m36RhnklwpVQg9yk2PY657n48mweGBRvZ710k+6DbdP9A5bEgpL79rRXeVj3xc0+OxfVAmdSSpyGUAltXA5HtfXprEk//NWOQrr4YeeeBzDxISgsR81lNRrT1hYBr4Mz29F2YQaTb0kBNVPYUXhbAVko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594879; c=relaxed/simple; bh=fE4pa+EZKd10ub6G12ivLf5vbbfIfTkWVofOcX/uFIw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p48E1QP3MBA0tG36FahI4+9r4xhQVBisbjza3zkXlrT3GZh4+ObwBrsBfQIL4aBJVg2QJ9lKXPUQgzd+oo2h0MRGBRXrZ+i2przrAkK+e4p82zwQSE9IMwUIMcotzi8s591QDDQwnBMQVIeB3PxRq44IHl4TLkRw0DCAmTBC+wo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PmcwoaLW; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PmcwoaLW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594877; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JlWyOLogzAhq47uomDvl+vnyySl8hlXXeiMSg2kvXRI=; b=PmcwoaLW517nOWsLdH39zDQ5qZ2nLAErCZRee7p/V9igV3Y4VlPLvjIEQb0Yzau098ogYD 0uD/YVJzvbfWHAR4oBsBmTwTu77bZZ+4TSFCtu7E/rAIY3djdQz1AWAGHdcaEtOHDghn1L 6CWf1rpTD7HoJUeJJ7F7sZkplfIPjo8= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-BqJJPvAxOcOW73_FdwR91Q-1; Wed, 05 Jun 2024 09:41:16 -0400 X-MC-Unique: BqJJPvAxOcOW73_FdwR91Q-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4BE1A1955DB9; Wed, 5 Jun 2024 13:41:15 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 550441955E8E; Wed, 5 Jun 2024 13:41:11 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:10 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 04/38] trace-cmd: call dlclose() in the error path of load_plugin() Date: Wed, 5 Jun 2024 15:40:19 +0200 Message-ID: <20240605134054.2626953-5-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 The handle returned by dlopen() isn't closes if something else fails afterwards. Call dlclose in the error path to fix that. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-plugin.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/trace-cmd/trace-plugin.c b/lib/trace-cmd/trace-plugin.c index 127771ea..0d477dff 100644 --- a/lib/trace-cmd/trace-plugin.c +++ b/lib/trace-cmd/trace-plugin.c @@ -126,13 +126,13 @@ load_plugin(struct trace_plugin_context *trace, const char *path, if (!func) { tracecmd_warning("could not find func '%s' in plugin '%s'\n%s", TRACECMD_PLUGIN_LOADER_NAME, plugin, dlerror()); - goto out_free; + goto out_close; } list = malloc(sizeof(*list)); if (!list) { tracecmd_warning("could not allocate plugin memory"); - goto out_free; + goto out_close; } list->next = *plugin_list; @@ -143,7 +143,9 @@ load_plugin(struct trace_plugin_context *trace, const char *path, tracecmd_info("registering plugin: %s", plugin); func(trace); return; - + +out_close: + dlclose(handle); out_free: free(plugin); } From patchwork Wed Jun 5 13:40:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686951 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 962A2195FE9 for ; Wed, 5 Jun 2024 13:41:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594884; cv=none; b=R7rXdh2MAcibnzUgJLH10hXEOlAcjaja+nBKFnD36W11Qcl3GrNBDfNPFR55Cwl6VkKVZb4QGzuAkK0VVgjdo2G3QTVec0Aw+Ep2KERESUsoscQNiXGO+EzfpnkXPMYxjBx+J0FOe4/h7ptUuXj6ipVJXy9L4bWx5Zpr18MPotI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594884; c=relaxed/simple; bh=dNZL2O9Un2dQ/KKsO2HTYL+AyQxOHA8cuQZetnPTCBM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RybehkORS4PhPrIEhlDDTe5TJsYnmuyHQbINyN9kP2FAjY5qDeQ7gnPrVramp/vn3FsEk0aSJaXNKqDYSc5/Cq04nh/8ZADY8BKj1FhUZhqo1IuyHFPIaOs6ShX7E51VevH0z3qEMDo4pmjXLVSwJyskAQD6D4X5psl3zQJuLn0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FC3KYuTW; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FC3KYuTW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594881; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S5tTpftksqgDfMzfbzE87T+ijuUaWf9OyJHE3Htr24k=; b=FC3KYuTWUynl1I3euuOF+8M4uOKdCPJkBLguGs/D2nQClzIG937zodYgP6cmgEsgLeBOI5 PSwu1Rg8rCzNtMhOHRaz75wsHyCGJ68BKeCn8cuN7Od4Ke2eNPvctEvPLQPzjmE+vINd4p jjJizvzuplbRDptFrOCZz0n5rC0opbc= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-qztPHwyzOue_2br5NEm2Yw-1; Wed, 05 Jun 2024 09:41:20 -0400 X-MC-Unique: qztPHwyzOue_2br5NEm2Yw-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4D3CB195DE46; Wed, 5 Jun 2024 13:41:19 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id F0EA51955DC0; Wed, 5 Jun 2024 13:41:16 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:15 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 05/38] trace-cmd lib: prevent possible memory coruption in add_plugin_file() Date: Wed, 5 Jun 2024 15:40:20 +0200 Message-ID: <20240605134054.2626953-6-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 If strdup() fails the error path access original address of pdata->files after it has been dereferenced. Make sure that pdata->files contains the up-to-date pointer before calling calling a function that could fail. This was flagged as ressource leak (CWE-772) because ptr isn't freed in that scenario, but there is something worse going on that the static analysis missed. Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c index b5002f1d..47ca3db1 100644 --- a/lib/trace-cmd/trace-util.c +++ b/lib/trace-cmd/trace-util.c @@ -279,11 +279,11 @@ static void add_plugin_file(struct tep_handle *pevent, const char *path, if (!ptr) goto out_free; + pdata->files = ptr; ptr[pdata->index] = strdup(name); if (!ptr[pdata->index]) goto out_free; - pdata->files = ptr; pdata->index++; pdata->files[pdata->index] = NULL; return; From patchwork Wed Jun 5 13:40:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686952 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7FDB195FF4 for ; Wed, 5 Jun 2024 13:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594888; cv=none; b=a0s6sdg2tGg1fFbatqMCbmp+XzvhVVlWI4l4khxFgTwM/gsjNkF7Vi+tyGsY/2zJYDbkdCSTQ1tEaAIAhLPhhm/vcv7i7ifxaLFm+QS1XJuQVIzxEK6c/XKqpGiKJd3ANTOIqXxWxQiEyHV1O3wTlp5RQ9dHZQHaKt1xc2rKY7I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594888; c=relaxed/simple; bh=fVirk2G677fvNtEnHPSObvgw1qogj4SaT7CUBGD9/zQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rmotf8nJ+kFmFF7a77kLS3Xp2kr2TMjJCyOMSvD+94TFduV0vun0Ij16TClG6c9Ox2MOwB33LpeQ6xrNiNnmUietdMoEEl6IEcQjgnIiMyk5sphrNUUcaU60ELepKAr01oWUNm/YKcMXLMkMB9SusMmqAo2wllfKXRkE8K4M/ko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZMm84IFp; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZMm84IFp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594885; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F00/N84Ys+qgsusfhdL0T7CRVc7B3PCgPFwgJ8bdPNc=; b=ZMm84IFpr6Fth+LMCDQqX0Ehp4kCeLZpneEsL2XmNh/CM2vmc2Lop0/tymGzIMm/0WH6je lJgE+sK2sI8t5H7bWOI3cP063CrUk0F9dAYSxSwA9MjuhldIUzBkaNe3qNHstIklCU1Fvj GwpWINtyFqqpxOEo4k8T4m6t5/TAojc= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-127-PZ2qfUHQPACwa33R9jVzYg-1; Wed, 05 Jun 2024 09:41:24 -0400 X-MC-Unique: PZ2qfUHQPACwa33R9jVzYg-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 95BE21955D78; Wed, 5 Jun 2024 13:41:23 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 2D30C1955F79; Wed, 5 Jun 2024 13:41:20 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:19 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 06/38] trace-cmd lib: prevent a memory leak in handle_options() Date: Wed, 5 Jun 2024 15:40:21 +0200 Message-ID: <20240605134054.2626953-7-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Free buf in the error path. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-input.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index ce4ecf43..2cf0d1c1 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -4030,7 +4030,7 @@ static int handle_options(struct tracecmd_input *handle) } ret = do_read_check(handle, buf, size); if (ret) - goto out; + goto out_free; switch (option) { case TRACECMD_OPTION_DATE: @@ -4084,7 +4084,7 @@ static int handle_options(struct tracecmd_input *handle) buf + 8, 4); ret = tsync_cpu_offsets_load(handle, buf + 12, size - 12); if (ret < 0) - goto out; + goto out_free; tracecmd_enable_tsync(handle, true); break; case TRACECMD_OPTION_CPUSTAT: @@ -4093,7 +4093,7 @@ static int handle_options(struct tracecmd_input *handle) handle->cpustats_size + size + 1); if (!cpustats) { ret = -ENOMEM; - goto out; + goto out_free; } memcpy(cpustats + handle->cpustats_size, buf, size); handle->cpustats_size += size; @@ -4104,7 +4104,7 @@ static int handle_options(struct tracecmd_input *handle) case TRACECMD_OPTION_BUFFER_TEXT: ret = handle_buffer_option(handle, option, buf, size); if (ret < 0) - goto out; + goto out_free; break; case TRACECMD_OPTION_TRACECLOCK: tracecmd_parse_trace_clock(handle, buf, size); @@ -4183,6 +4183,8 @@ static int handle_options(struct tracecmd_input *handle) ret = 0; +out_free: + free(buf); out: if (compress) in_uncompress_reset(handle); From patchwork Wed Jun 5 13:40:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686953 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D73F195FF5 for ; Wed, 5 Jun 2024 13:41:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594893; cv=none; b=imusWoxhZIND0d+haPvDDM59YUJ6L2ASMZKorPVGyBftWBvQLl1r2exDVGdxIs8YtPNtqt61GvVM3XTIRTHqf3gRGJqK6/mx6TRAinPQvLd12fhmDdt9ytAtstWdQyVgGAwv9kjdmpzColmU8vq2Ig+Hl3DHchG6rW+hnp/RoYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594893; c=relaxed/simple; bh=5ObqETasSDT5kuUx+YlUHYSDYpGmx2dD7zc3CXEXmxI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qNsBQUt1YU5e14NDunwQLUgRZWM/ImS5NujV5sA3aeICYTZiqUT8zhvqDD9ytlrQ+iRHhUQRUFjLbs2v7K8pRBssvroi+jQ9Jw1FuOToZu+CCDdMaMqHyrGnOdAp4VNSXMDn68YMeG/yTWfQBPEKCN30PZ/66ugTIKtFjVk+QIg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PtdVMFcV; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PtdVMFcV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594890; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YAQZhfOHny/csUEwAv3oEvGMIpVzggTsqPOS8ncjOns=; b=PtdVMFcV1LEXoWvpaNuq6xloq7WOSO2/7LbWZc3ChjzpuV1S6PbU2puItu40riete7pFIp QDrTzABSwYnL5ZiNNlrPO0DK9nkNBztbqmzMYVct+0qQvQB20pl95XYYqu3uZu9tp5UEj5 rMgEEMXVNzx0XaWvFKdmT/hHWgoXA5c= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-519-0pZfJ11NOMGsyWYxnOIxHA-1; Wed, 05 Jun 2024 09:41:28 -0400 X-MC-Unique: 0pZfJ11NOMGsyWYxnOIxHA-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C107419541A8; Wed, 5 Jun 2024 13:41:27 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 5DBDD300060C; Wed, 5 Jun 2024 13:41:25 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:23 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 07/38] trace-cmd lib: prevent a memory leak in regex_event_buf() Date: Wed, 5 Jun 2024 15:40:22 +0200 Message-ID: <20240605134054.2626953-8-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Free buf before exiting if strtok fails. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-input.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 2cf0d1c1..3284dbd4 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -666,6 +666,7 @@ static int regex_event_buf(const char *file, int size, regex_t *epreg) line = strtok(buf, "\n"); if (!line) { tracecmd_warning("No newline found in '%s'", buf); + free(buf); return 0; } /* skip name if it is there */ From patchwork Wed Jun 5 13:40:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686954 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBA79195FF3 for ; Wed, 5 Jun 2024 13:41:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594895; cv=none; b=fF4blXOY+gwnowczF3yw4dBuUI82pOh/G98XU0C8BwZboNTPG9/xaEhUxZ4h/ujxowH23/gn/L7HpkpKkx9YNtLw4J5IYCHUJ2zq+X/lnhqTlvIBqbV/Tc1K0EaKS72u4sdB7TYlgv17ARBEh70W2Q77bTrzoI5ApvOWP5QciYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594895; c=relaxed/simple; bh=YPzNj/PUaAGdpiCZwkmvpo/YxyhRxFlbdyE1VCmRJis=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pcS07OMMiWhDM9aoN89uSalanwg3Thg0U1SFLUyZkXqsLPiXya99iWqmgHAgDcjSFfNaGyXxRggHx1Wv5vZSaUnDbSd1okMvX+er+wBfpc4LFr39QgQt+4B5Dih0TRDV7Lqs6Yw2iOUOZvQ87183w5SVfEq1UTCGAOjOhmMHckA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fejpiy6F; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fejpiy6F" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594892; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=spax7Yod4Fqxbqlr5kfahKesUEd3qUBg9Z2+ohgV7Qo=; b=fejpiy6Fmj5/FZI350FT9rOEAiycItDw+1lFRUsvEAb4KOrs6yXEh1sXp+XVj9GJAuv79H pL91bIfrK+Cf+7QaLvceomD5s5IZpqWHADh4LyKvicCyN2PMwsSZh+xw7H3h4sMhtxqnTF rFFJPv1CouZLzVLJTCTZ4rpX+4++5uM= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-389-e6PNsXV2P0C_lTHyP3vRPw-1; Wed, 05 Jun 2024 09:41:31 -0400 X-MC-Unique: e6PNsXV2P0C_lTHyP3vRPw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D0A831C05122; Wed, 5 Jun 2024 13:41:30 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id DE5C140D1B68; Wed, 5 Jun 2024 13:41:28 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:28 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 08/38] trace-cmd lib: prevent a memory leak in create_event_list_item() Date: Wed, 5 Jun 2024 15:40:23 +0200 Message-ID: <20240605134054.2626953-9-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Free ptr if malloc() fails. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-output.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 59498edc..4a9ecc5d 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -955,7 +955,8 @@ create_event_list_item(struct tracecmd_output *handle, free(str); return; err_mem: - tracecmd_warning("Insufficient memory"); + free(ptr); + tracecmd_warning("Insufficient memory"); } static int read_ftrace_files(struct tracecmd_output *handle, bool compress) From patchwork Wed Jun 5 13:40:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686955 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E36B1148317 for ; Wed, 5 Jun 2024 13:41:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594899; cv=none; b=eh7hqUOkEYIvrcKFJpDftOw5dyZt0xF1hg86+HrFG+lNpoSeamu5XgsbOMUgLy2ZO0TmuublZRCIVaWc+XUNnZaUdo1fgck1eTzjpTleUJ6EopJdhwQm+4pPBgGYa7iB+ldVnABuNuBsq/xqKa1eonUXFGmZ/p0/zNK1v7BC70o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594899; c=relaxed/simple; bh=BBlz553ogim245M8Wac7L4+ZWqsb9T/rFIyDTu5TNeM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vk0j+TXBoQm7dbIs7nQUv205GgcK4FBJpHDIM/FFiP9IQuln3A1Ik76RzvxOYOGAGQFk5+rAkCLEjWcY25mGcW5NZ1HiO4Ufw2aAesvXf//3H3giL5rlxCldBZS6VjZ3mNsPxUzkR5v05zyeqtRWP6kSjJD2S9lEZVqOmjv6KIA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TWZJbfA6; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TWZJbfA6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594897; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+UNJdzkqR5zRCkmYfdcwa/zAkqcYBb3xg2oIrVslVd8=; b=TWZJbfA65EYorLwAXwEK5oALLSr463swcTvad7SOzUxTlIEtLBE8cbc1k9NqWGT/82SCNM 1M40Jothd3RJARPP7TUdM6o7zMzU5qNUFiOn3iF0DjRPC66HYUllyptnhJfIvXZXiz3Asa BZOHWEXxCFe37vFhRAuxBH+RXu4XjzE= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-453-XvZOPoQbNryW0AszT9SCrg-1; Wed, 05 Jun 2024 09:41:34 -0400 X-MC-Unique: XvZOPoQbNryW0AszT9SCrg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AF65329ABA03; Wed, 5 Jun 2024 13:41:33 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id D68511C0005E; Wed, 5 Jun 2024 13:41:31 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:31 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 09/38] trace-cmd lib: prevent a memory leak in read_ftrace_printk() Date: Wed, 5 Jun 2024 15:40:24 +0200 Message-ID: <20240605134054.2626953-10-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 Free path if out_write_section_header() fails. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-output.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 4a9ecc5d..5ba0a145 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1214,8 +1214,10 @@ static int read_ftrace_printk(struct tracecmd_output *handle, bool compress) if (compress) flags |= TRACECMD_SEC_FL_COMPRESS; offset = out_write_section_header(handle, TRACECMD_OPTION_PRINTK, "printk", flags, true); - if (offset == (off_t)-1) + if (offset == (off_t)-1) { + put_tracing_file(path); return -1; + } out_compression_start(handle, compress); ret = stat(path, &st); From patchwork Wed Jun 5 13:40:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686956 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9916B19D8A8 for ; Wed, 5 Jun 2024 13:41:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594903; cv=none; b=Yh0xpGHIoOj34U50tr3IOslColT5fAC+m6BxXRPfxv6YGbv99i4Zcfz5svynJVRXkiX7E7qTU/fBWv/SXI+Pw4u8wGZUybNiw0186wiWtKA0UM8PBmMNPHBe7G0zMbIM/gEj4R4COq8wO6hAf+QVLaTTTM+gVgn9vPJ9wLxR724= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594903; c=relaxed/simple; bh=jUZTiyebtc0dkMAzws81Zqq/oLOqIzsvf5vXNVHpc2k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fk5nHi891IIV4ourvcCxmCkum7/cjHI+nkxEeSQPs2VU/8VY+//K8vqswtanBIgjI9kwFLOB4SLp+InbZH4ClNh45tVonX3nNrNoNtqoXOogo70RQfCIwqNUkmJZLZGgMZOIL9WRFCn8coxl8gsYDPPQU3oeN827uGTikmze3MU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hUA49nPj; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hUA49nPj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594900; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FavApTEUCNvzUVqppKKtckL72ZSPWL/sIQjg9OzoyXA=; b=hUA49nPjAWm4cy0W49wXv1RM5ddmQrEFJBE0FvarK+hot/scY51+tRJZ29renCpLdPPX5i fC7wzWGLwJjF+5VfeyiQlg4aq5EyyQEOHeHo6kjCN+zLh309/6VJGIZVrdJdZApqrBqFqv 4ajBB0PqsPjJelF9tr0PxSHDx1oRUgw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-25-uPPo4JtRPB6VdfRdzZojMQ-1; Wed, 05 Jun 2024 09:41:37 -0400 X-MC-Unique: uPPo4JtRPB6VdfRdzZojMQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C40C5811E85; Wed, 5 Jun 2024 13:41:36 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id B67FBC15970; Wed, 5 Jun 2024 13:41:34 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:33 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 10/38] trace-cmd: don't print a NULL string in append_pid_filter() Date: Wed, 5 Jun 2024 15:40:25 +0200 Message-ID: <20240605134054.2626953-11-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 In append_pid_filter() a NULL pointer is passed as the argument for a %s format. Change the error message to what is used in trace-record.c append_pid_filter. Signed-off-by: Jerome Marchand --- tracecmd/trace-read.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c index beaf97a8..a5a0e10a 100644 --- a/tracecmd/trace-read.c +++ b/tracecmd/trace-read.c @@ -482,7 +482,7 @@ static char *append_pid_filter(char *curr_filter, char *pid) if (!curr_filter) { filter = malloc(len); if (!filter) - die("Failed to allocate for filter %s", curr_filter); + die("Failed to allocate pid filter"); sprintf(filter, ".*:" FILTER_FMT, pid, pid, pid); } else { curr_len = strlen(curr_filter); From patchwork Wed Jun 5 13:40:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686957 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EB261957E7 for ; Wed, 5 Jun 2024 13:41:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594905; cv=none; b=dgD0reupFa1LztvUEe5N1GIqRKuyzW7/GxtGp5IcHa37swkKmHU0ZoKkUKlFpEglvMUUcHiRbGCON7aeqrj9Cb4KJpfm4Dx7/1U1FM9eVMPS3+1qpntzTAVtCAENZV56vCTSRPKuNxy3o02x0l9KMPRPuZ1poBHMc1YYa/Q2ZxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594905; c=relaxed/simple; bh=0Ce7jOE5E/w4OCrMIZ6dOEH62F/LTxWBFmZY7fhjQRk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=prKgkVetziVb3vs5hz6zQuxD8R1zkwDoeqt2/9abDt1izhV1wA2SvD3yHqNtI8UI0N6JBbs05/fUhesPF+mihxaY2QO+RsbRucmhQ1TxKCL02OUCJokH1m5y/IPUnWI8JVglT0dPbBRO7ASt45zhc24EgEYEXI+5zXVAy+P3ws8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=R2r6pzGi; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="R2r6pzGi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594902; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=obTzUGN5FVWNsyENElKmTg5DcPTYLmPR4sdzondgsNE=; b=R2r6pzGij4QeDe0C7Qd40J7W+Lnm2XDmhWEpdu7k+e7b17fi69S3M2gwiadkLrTyX0HJ1c OsYMPmUi6XB3m0OIdy2zaLd/n2vmavrOCzI44mi1CzBIILeM9GhdV9D0ug6UuqtNdK6RwC HpFW8T7CJABLzWqtlnjKk1JX3AZWg5Y= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-48-xiiSjevdPxKYogKBmdoniA-1; Wed, 05 Jun 2024 09:41:41 -0400 X-MC-Unique: xiiSjevdPxKYogKBmdoniA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AD1DD1955D68; Wed, 5 Jun 2024 13:41:40 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 77DA619560A7; Wed, 5 Jun 2024 13:41:38 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:37 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 11/38] trace-cmd record: prevent possible memory coruption in get_pid_addr_maps() Date: Wed, 5 Jun 2024 15:40:26 +0200 Message-ID: <20240605134054.2626953-12-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 If strdup() fails the error path access original address of maps->lib_maps after it has been dereferenced. Make sure that maps->lib_maps contains the up-to-date pointer before calling calling a function that could fail. This was flagged as ressource leak (CWE-772) because map isn't freed in that scenario, but there is something worse going on that the static analysis missed. Signed-off-by: Jerome Marchand --- tracecmd/trace-record.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 91cc90d4..f05a58d1 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -1230,12 +1230,12 @@ static int get_pid_addr_maps(struct buffer_instance *instance, int pid) (maps->nr_lib_maps + 1) * sizeof(*map)); if (!map) goto out_fail; + maps->lib_maps = map; map[maps->nr_lib_maps].end = end; map[maps->nr_lib_maps].start = begin; map[maps->nr_lib_maps].lib_name = strdup(mapname); if (!map[maps->nr_lib_maps].lib_name) goto out_fail; - maps->lib_maps = map; maps->nr_lib_maps++; } } From patchwork Wed Jun 5 13:40:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686958 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28B89194AC2 for ; Wed, 5 Jun 2024 13:41:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594909; cv=none; b=Jodq/OqkC7+FhRMUNBNu9FmKYeFuI/v+8CqLqziLG1yssTXC3vRgV85PBOPAgq3csb90OFqJdyKbQjQ12gi3ADVQlnhyqkDOX1ptIvZizC2S8IqAACReaFNxZW21xSzF5/kfs/3ZjrELcYl0aG397/yQk4rHBmZD0xw33I24Nk8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594909; c=relaxed/simple; bh=2J8GA1bakINdvLCtrk3987PfFz48w6A9trPsMDXxMbs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tIfrIHtmd2NW3dxPsAouQwUPhkD8Y2j6xbH/7abqkumv3hFzJEp7BH00PsnLRNybzXb2J6ciIqOEAbHGlsKLENnqUv98ZDsFSUzf1A0er+tpcpGLPNhVUqUv9vdyslxMNZYMvtCeTKOUPqgGqnpqTREUvL1YnFxOJBafbWhOdBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=iphAEh+B; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iphAEh+B" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594907; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2FDj3oyBf35pPIB1IVZj9/btdZpFvvWMzg2GkAF3AqY=; b=iphAEh+Be+srlm06JDVpfo86ORKPvO/OfGzjSoKQ/kQnFs8jtmap8e67ZFOwUpLzAYtWam UzrSMd293Me4SEVMzi1Vu2DfVqu3NEvjjEHMG+LN2S1nXjlUYmAOCJNuQfLEEDkIpx20dC DmehqhDKwXn7gKDGbiCOa6kJfcPnN7A= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-621-JhFk8FYXNZmWNanT3DCIRA-1; Wed, 05 Jun 2024 09:41:44 -0400 X-MC-Unique: JhFk8FYXNZmWNanT3DCIRA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E94383806702; Wed, 5 Jun 2024 13:41:43 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id 1D123C15970; Wed, 5 Jun 2024 13:41:41 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:41 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 12/38] trace-cmd hist: close tracecmd handle when trace_hist() exits early Date: Wed, 5 Jun 2024 15:40:27 +0200 Message-ID: <20240605134054.2626953-13-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Call tracecmd_close() before returning if tracecmd_read_headers() fails. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- tracecmd/trace-hist.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tracecmd/trace-hist.c b/tracecmd/trace-hist.c index 62fe4f9b..47dcd6f8 100644 --- a/tracecmd/trace-hist.c +++ b/tracecmd/trace-hist.c @@ -1043,8 +1043,10 @@ void trace_hist(int argc, char **argv) die("can't open %s\n", input_file); ret = tracecmd_read_headers(handle, 0); - if (ret) + if (ret) { + tracecmd_close(handle); return; + } ret = tracecmd_init_data(handle); if (ret < 0) From patchwork Wed Jun 5 13:40:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686959 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2794819D8A8 for ; Wed, 5 Jun 2024 13:41:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594912; cv=none; b=GcXXpTfGKIk1G/YE3tDCGcDyjRkBecBkAOz2XR90CyN9YXaX2uZXOuJnyUtTpdKgaipowjoEm3/qj8eMmtIj6KfJ3A3cCbikcyMNBXeioCa41OC2GWspzjHrjCL4gBrnpkEPCeeC78dYjal6zZlwxyrWZm/F1ZjRs57TYiFjUuc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594912; c=relaxed/simple; bh=kn9qEAQZiOOlOT69CEPK5wKUowJJCq2NDZLDy8djnFY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gzSYUf1SZcq5PdNyAvkNhXnZdwK0mQn4nHPKQw9Zz7CPPwSsSyjvRmFhwTbUmkarBXcALJCbG81trPUx/2dwXRbSNXEBOlzg8eLIJWANr7C0KzSCsh/sHgpNAoCuqGdY7ETDJcUgeHO/MSQBh4O6JVXMTCOYKoMqC02f+XcgzLw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Tg3ikd5r; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Tg3ikd5r" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594910; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L0csOYl5mrYAN1++D7VAQRUoLPDVs1VTI5Cj0jS8D+s=; b=Tg3ikd5rlX0Ymq0wtCGLerYNXsNVdD3K/HLMvDn95aroWXp4T+JBKGsnZDQuqNerAtfQJ6 YRvBAKhRIX4vG8EO296/xbgBozhTERCigNtvgvgB9dWRBLhEi7sl7HwqwPnK3xZ9pyMS1q N2nufFX6ClmgedAmn7/zDq0x5QDAaxY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-546-FM_zmFORNhWh4M5xAwm3ZA-1; Wed, 05 Jun 2024 09:41:47 -0400 X-MC-Unique: FM_zmFORNhWh4M5xAwm3ZA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C96B28007A1; Wed, 5 Jun 2024 13:41:46 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id F14D137D0; Wed, 5 Jun 2024 13:41:44 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:44 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 13/38] trace-cmd record: prevent a memory leak in show_error() Date: Wed, 5 Jun 2024 15:40:28 +0200 Message-ID: <20240605134054.2626953-14-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 In show_error() the pointer p is used for several functions. At some point it is used to contain the error log file. It's not freed before being replaced by the result of read_file(path), which is not freed either. Free p in both case. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- tracecmd/trace-record.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index f05a58d1..3e29f922 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -2364,13 +2364,16 @@ static void show_error(const char *file, const char *type) goto read_file; } read_error_log(p); + free(p); goto out; } read_file: p = read_file(path); - if (p) + if (p) { printf("%s", p); + free(p); + } out: printf("Failed %s of %s\n", type, file); From patchwork Wed Jun 5 13:40:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686961 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3F28194AC2 for ; Wed, 5 Jun 2024 13:41:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594915; cv=none; b=b8G6CPhIJ6EdndkUpNbGR9rVXphFVUJylW4di+6yjKkM5l4XQt6XxU0VncLR69cdCzkSa05QGmDkOvb4JgaIFKMeaPXlcriO8q4amecqzd7Nxhc8XUOXAdteauTsPNbfdBOowyVq+UNZK7IeSuJsbvPQse7zLwEchs7l73LM5qM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594915; c=relaxed/simple; bh=t65R1iG83VacrKuReY8A4ZSCSt+GnV/UiYaHWmXhSqw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IMFqRcQQ87Srucwi2J9lJAyyQA2HcW1Su/PfuMhWm0pzF85wGpNHAqmlZsSeO7qFhTrxsxQKy9ZGyb03pZsjYh6gEAHlPw8OVO4CuWsw6kZBhjaW0akaG5I+pPq1QbZEDGLy09j5UkscSPggov86gpwStJlScvBDp3EEEelZWmQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fwaM4E+O; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fwaM4E+O" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594913; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=thz4h3w64XIE8wlAoS+C9l2TPwCTB/0aMTSHmchxuMM=; b=fwaM4E+O5o8OBa1xavTUfZlMci38Tr0z6gXpRj7aeEszVRSke6haJCPMoPXG6zhLO0/ibQ q8DwfPP3amix4q6wVQP3NIVboLBOYIHoTnV5qb64lzeuNR4flpTqBPnplPF9C4cR4FW3bI DQ1YvxWdj99cJqYWePEpDlrf5AYX9Js= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-P20njlAGO9q_p3v41mciSw-1; Wed, 05 Jun 2024 09:41:50 -0400 X-MC-Unique: P20njlAGO9q_p3v41mciSw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8F820185B920; Wed, 5 Jun 2024 13:41:49 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id B7D33492BE9; Wed, 5 Jun 2024 13:41:47 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:47 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 14/38] trace-cmd record: prevent memory leak in update_pid_filters() Date: Wed, 5 Jun 2024 15:40:29 +0200 Message-ID: <20240605134054.2626953-15-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 Free filter before exiting update_pid_filters() Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- tracecmd/trace-record.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 3e29f922..c4d43469 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -2881,6 +2881,7 @@ static void update_pid_filters(struct buffer_instance *instance) } while (ret >= 0 && len); out: + free(filter); close(fd); } From patchwork Wed Jun 5 13:40:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686962 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E25119D8A8 for ; Wed, 5 Jun 2024 13:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594918; cv=none; b=DraXlFxXZLUCvRDCuwXgh10lWGUw2MK+IdKrKjJMQOlnbDA3MJqNXhubN+kUURE7ngHWSp+kvbItvvNoJ6PkKLZ8yi2mc0nQ4Bt2A+z4OI2nwVd//5LaRXXGIS7VJGMqIYGq/yxB1XxJ+CU7KV7JPsk0dZteEOfNEIp3Ds2JZrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594918; c=relaxed/simple; bh=U6dsy/JyA+kvQ+BYMQmNIaVA0+9fJNM+Paws/j0bD3k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eUJQpqUgckp09LY20Dhcv4J1Rpu4XPrTzNSf/fIH3oz/xCcE3tQUPXDDsYzL2xgAkusum6s7Yd8+FmxsZ+jgPBztdkovUFauu93cgEgrr7OD9xou3p/Qp8JdwxUCZU4GWoonjwBihVpSnLfN0ChvSYARxKvgNK4ef85RecXlr8s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=f1TXoQ84; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="f1TXoQ84" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594915; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nNsK2TXhWen7RqUaDDLK3h9BZOGMdQnuwnmcUCsLZ50=; b=f1TXoQ84NH01Te9wpMFNa+MBjwomXFAFAaBsf0Xro6mHpaGN0MDMHzRQSD55WeBEGf+aJ3 k8E90qnncjbei7UAq//w34Sn6Ya5pZXooUWWX5efpLu0UIDD+maKQ3t0wynqDh5tJq0fGm l9nHMhMshvhG0P+ifARJU2kYXR5jGNc= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-628-WTvJcsCPOW6s-HOH_9NZXg-1; Wed, 05 Jun 2024 09:41:54 -0400 X-MC-Unique: WTvJcsCPOW6s-HOH_9NZXg-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 90BA519560B1; Wed, 5 Jun 2024 13:41:53 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 2FA9A19560A2; Wed, 5 Jun 2024 13:41:50 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:49 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 15/38] trace-cmd lib: check the return value of do_lssek() in trace_get_options() Date: Wed, 5 Jun 2024 15:40:30 +0200 Message-ID: <20240605134054.2626953-16-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Check that do_lseek doesn't fail before calling malloc() with a -1 argument. This is flagged as an overrun error (CWE-119) by static anaysis because of the call to read() later, but I don't imagine that malloc would succeed. Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-output.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 5ba0a145..35904620 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -2069,6 +2069,8 @@ __hidden void *trace_get_options(struct tracecmd_output *handle, size_t *len) } offset = do_lseek(&out_handle, 0, SEEK_CUR); + if(offset == (off_t)-1) + goto out; buf = malloc(offset); if (!buf) goto out; From patchwork Wed Jun 5 13:40:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686963 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB1091957EB for ; Wed, 5 Jun 2024 13:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594922; cv=none; b=Vr7Jl46Dji+y6hSIu+Snrsb8UJudLXeTCYeCcupQafuQDJ2rNpXBB5yvlJHVek+QyUD+760VNAgKRxAlCxvgyQ9Pp2qYcs3EOcXG/4g2e6GiVabTIPHttQbteAeKoStji1PQxvlyYwk/8TXm1vENfB9Eq15BkXgpKwmaYVBVmOg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594922; c=relaxed/simple; bh=GKVzg6lq9G0dIXWqfbx87RNmLXU33FysFWJsjHTXWhE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RD802RXpHLxpqx5+xwssjfwhO9QJ6EnUfp4nWl6055AAZGjjlky4D8Vu3OBsKAVaN2+BA79YaYs2sHHmC1WRgeCFG8oyfmzKbArCE9o7T+JNYOtRld/O267ZuNSj4UlD8iGD1qzYLkODVzEQO49Wp6MDxbRCcneI2WQEduujnOI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PRIqG5VW; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PRIqG5VW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594919; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uHLlvnokkk/09xwa0Lk3p1AgBtCROe8Gprobn4fGLJk=; b=PRIqG5VW9iTWao3CX6cvfwqrC+VurvcclUd0Wn15ignephe5RyxhZ3uW6rVg/usT0abIF3 R/0IlMW+xp23qZylMjH43KAWvNOYyziMcyYVccZ42xb2OqxHCCly3uN6ofGr+URTRmIVNL qY1kIbP3/JpGw5fFcU91MsxAvzwjCwk= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-303-CH3iPDLANrSRwx-bMQhX5Q-1; Wed, 05 Jun 2024 09:41:58 -0400 X-MC-Unique: CH3iPDLANrSRwx-bMQhX5Q-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E285E1954210; Wed, 5 Jun 2024 13:41:57 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 618B319560A2; Wed, 5 Jun 2024 13:41:55 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:53 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 16/38] trace-cmd lib: don't double close a file descriptor in read_header_files() Date: Wed, 5 Jun 2024 15:40:31 +0200 Message-ID: <20240605134054.2626953-17-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 In read_header_files(), if we encounter an error after we close the first file but before we open the second one, the exit code tries to close it again. Move the call to close() just before the second open to prevent that. Fixes a USE_AFTER_FREE error (CWE-416) Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 35904620..c270d03f 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -685,7 +685,6 @@ static int read_header_files(struct tracecmd_output *handle, bool compress) if (do_write_check(handle, &endian8, 8)) goto out_free; check_size = copy_file_fd(handle, fd, 0); - close(fd); if (size != check_size) { tracecmd_warning("wrong size for '%s' size=%lld read=%lld", path, size, check_size); errno = EINVAL; @@ -697,6 +696,7 @@ static int read_header_files(struct tracecmd_output *handle, bool compress) if (!path) goto out_close; + close(fd); fd = open(path, O_RDONLY); if (fd < 0) { tracecmd_warning("can't read '%s'", path); From patchwork Wed Jun 5 13:40:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686964 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00194383 for ; Wed, 5 Jun 2024 13:42:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594927; cv=none; b=Mz3jOIMwlZ0RBHpZ6iD7AjF79CVnWWMq8nDwHTiyRGrUtxawW6d2pRjccK9nUgPrFBz8IzxOK56wDUbAHSg8RWJ67hBG83iXlbxPEPp5BzK4lPzjSBL/pNfdf1J3ELUgXH9F9blIVpIlcEW+nNDplNCZeR9/TWRZWIb696oR6Kk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594927; c=relaxed/simple; bh=9bQlDZW+VFD+rnIm39+7Y1t9V1YX/9f1B/TPwk9urP4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rv0QJFWs9O898YvIJGjwkkFwEX/dd+2Ab6/PznVy+cz4aF30G8WGs4qxEueMj+cCjM+plE/zVfGx5K26p08tCW7ThqXuHQIYjHQTtWjQupquq8uYydQQhul7yVAa18HOM3++e/A8dGtwQtBeVlRWes6Hswi2eGecG+KZ9j3/Oio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Gh3CE0QF; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Gh3CE0QF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594923; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S6nRBfSy5fQHzGiA/diBKUgulvdouKq4yo3YET0FB6k=; b=Gh3CE0QFdYSU/vtNaOaBLm6Bl/p5FL2jrX3SQMmN3/9+E94stywWSMQko599/xoCx5/PSd B4tBpqlQ5p7+5T4eebqheSMwjzOPG0mo0qJzj8mkZuzF4eC6KwxAPEzm+mrkfUTCd5FP9k +X+ofibFJeKiomV/nFYnkCMdQxg6Tq4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-302-3vRnG5lXMRmxIc5xhUjdEw-1; Wed, 05 Jun 2024 09:42:02 -0400 X-MC-Unique: 3vRnG5lXMRmxIc5xhUjdEw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D14EE1C0512D; Wed, 5 Jun 2024 13:42:00 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id 03CC0C15970; Wed, 5 Jun 2024 13:41:58 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:41:58 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 17/38] trace-cmd lib: prevent memory leak in ptp_clock_server() Date: Wed, 5 Jun 2024 15:40:32 +0200 Message-ID: <20240605134054.2626953-18-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 The pointer results is allocated in tracecmd_msg_recv_time_sync(). It isn't freed if ptp_clock_server() exits with an error. Free it in the error path. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-timesync-ptp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/trace-cmd/trace-timesync-ptp.c b/lib/trace-cmd/trace-timesync-ptp.c index 20e6e6f1..402edeb2 100644 --- a/lib/trace-cmd/trace-timesync-ptp.c +++ b/lib/trace-cmd/trace-timesync-ptp.c @@ -608,8 +608,10 @@ static int ptp_clock_server(struct tracecmd_time_sync *tsync, sync_proto, &sync_msg, &size, (char **)&results); if (ret || strncmp(sync_proto, PTP_NAME, TRACECMD_TSYNC_PNAME_LENGTH) || - sync_msg != PTP_SYNC_PKT_PROBES || size == 0 || results == NULL) + sync_msg != PTP_SYNC_PKT_PROBES || size == 0 || results == NULL) { + free(results); return -1; + } ntoh_ptp_results(results); if (ptp->flags & PTP_FLAG_USE_MARKER) From patchwork Wed Jun 5 13:40:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686965 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE012383 for ; Wed, 5 Jun 2024 13:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594929; cv=none; b=PHstF6IW9zLOOTsrhbiJOh7amo+IBWF7XIQfu/x5zHXEpy0pavzoa+x1Jd/7gmVfWWAOkuVkVsWP9AZYuDTP1udQ5W5KlTvsZUssCMcw7k4pE1VRJtLbvYn9TjKW3HRslOuc9PKZUYvF97RcHwhuRbGgv6DXPTiefJPEPqdH9i8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594929; c=relaxed/simple; bh=7d7dXkY3IAwNZNAcOv8rGsLEEJczaT3GcwE6ChWUjEU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mM3stMvuyavvMAzYMkreK27/J+xbLMgOgEoy7RI+4GoXwjGldlUekMNU4nOdET1pBmjNcS2bt7aG3fxx/NlLdl+Pw+SlTszwi3ZaY0q2lG9Q6wsYJeLSHV/FpIIFavu7WMVbf/GNyrN1aRNk0c3DFvX1F7PrEWtofObh0BusuxY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HgbwnLfq; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HgbwnLfq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594927; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GyEnMcCx78hNb7umDffZ40rYs4R4qVE3bhAHJHKN48M=; b=HgbwnLfqQLSK/3o8HThWSiruntBEMyMQlkmTwv3Ei2kcwpZrLHFFTLmQXGIF136JRiHwtz rB26m+w3DUfCA7V7NZ6HYDN5e9Qno7L5OjGdNO2aNP0xW1zmbA9y/5EORqvdlWocDeSpG8 ualHv6DXHagQEdxK/HlIK4wWRCCcX4E= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-513-ZULXe2AQM5CKRGse4i56-w-1; Wed, 05 Jun 2024 09:42:04 -0400 X-MC-Unique: ZULXe2AQM5CKRGse4i56-w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AFF5D85A588; Wed, 5 Jun 2024 13:42:03 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id D74C21C0005E; Wed, 5 Jun 2024 13:42:01 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:01 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 18/38] trace-cmd lib: remove useless code in tracecmd_plog() Date: Wed, 5 Jun 2024 15:40:33 +0200 Message-ID: <20240605134054.2626953-19-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 In __plog(), both branch of the "if (newline)" statement are identical. I guess the original intent was to print a newline if the last message didn't end in one. But it seems that all messages send to tracecmd_plog() terminates with a newline and are short enough to not get truncated. Remove all newline code that doesn't do anything. Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-util.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c index 47ca3db1..a4334a98 100644 --- a/lib/trace-cmd/trace-util.c +++ b/lib/trace-cmd/trace-util.c @@ -453,7 +453,6 @@ void __weak tracecmd_debug(const char *fmt, ...) #define LOG_BUF_SIZE 1024 static void __plog(const char *prefix, const char *fmt, va_list ap, FILE *fp) { - static int newline = 1; char buf[LOG_BUF_SIZE]; int r; @@ -463,11 +462,7 @@ static void __plog(const char *prefix, const char *fmt, va_list ap, FILE *fp) r = LOG_BUF_SIZE; if (logfp) { - if (newline) - fprintf(logfp, "[%d]%s%.*s", getpid(), prefix, r, buf); - else - fprintf(logfp, "[%d]%s%.*s", getpid(), prefix, r, buf); - newline = buf[r - 1] == '\n'; + fprintf(logfp, "[%d]%s%.*s", getpid(), prefix, r, buf); fflush(logfp); return; } From patchwork Wed Jun 5 13:40:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686966 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E386188CAD for ; Wed, 5 Jun 2024 13:42:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594932; cv=none; b=gNhp3bGfSAVxFl4i18P2Z24AAknhfR/GNA5C4QFPk5vTujSY0r7r0iTBvoVSKQxstGlih/7UCMlTFVf3e5WVbJtsgNIsCKh4wmBNE3fnKQaWowGSxeaXlTX5HPZW5iUDPjk35juPaR+2nDAyOX9M5L85ylvF4qkQDKOFW7J3ZZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594932; c=relaxed/simple; bh=+TlN1phKIevAkUlymuoC5IcWe8f9t7XNHO9e1cNtrB4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C8GEBsXqK1I+sbVDLl46hrf7WN+bXl2owmHN1s+YFMygpqG/TfaeuDh7kVKWpMNp21/v8X5ZX2stLeiHaaljxqst8VsYgUqjkxi2w95tcm62DOvmhcHhd/SkOcEITCsHupIPFsEWlFn24lpl0CwUHlK4y3oLyCrpDVsAtFB3IEw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ds//Ew7h; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ds//Ew7h" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594930; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SWiU6Ud80ekGOMRX4VebbVhP0Q+11kyUksdo6eZk1Ek=; b=Ds//Ew7hlE9MtIbK6C5ycMljmdD0NWenasxXaFkJ+4lPPlUT8RNVy5FdnzGsz+39ONe+2Z ZZJ9iRB8PQmSKINJg64MVRtqu7O7/OC5F8l6RmPstvvDWHhTziTKtDBwH3jPczHCYO0RGF 8IqbZ7HaKncKelJdOXfUxmfWEcFBpfA= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-509-B2zUFIrcNLeUkinfBaK7qA-1; Wed, 05 Jun 2024 09:42:08 -0400 X-MC-Unique: B2zUFIrcNLeUkinfBaK7qA-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E82A61955D79; Wed, 5 Jun 2024 13:42:07 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 68F9C300061C; Wed, 5 Jun 2024 13:42:05 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:03 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 19/38] trace-cmd record: prevent memory leak in add_all_instances() Date: Wed, 5 Jun 2024 15:40:34 +0200 Message-ID: <20240605134054.2626953-20-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 In __add_all_instances(), name is allocated by strdup(dent->d_name) but is never freed. Anyway, the content of *name is copied in append_file() and allocate_instance(), so it didn't need to be strduped to begin with. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- tracecmd/trace-record.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index c4d43469..a9e5e64d 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -422,7 +422,7 @@ static int __add_all_instances(const char *tracing_dir) } while ((dent = readdir(dir))) { - const char *name = strdup(dent->d_name); + const char *name = dent->d_name; char *instance_path; struct buffer_instance *instance; From patchwork Wed Jun 5 13:40:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686968 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56D70193094 for ; Wed, 5 Jun 2024 13:42:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594941; cv=none; b=WU+z0giBA7It8KscyU9q0EgdestsWgiyVW9omOnyGCn4ap4+fghsdCQ1oUk8+BYint+DNNpnFSG2OUBeDnxZSidLDLi9Rg9OKynvbQh5W5EozTPloXGeOY0xQMysZZZbQ9f/34mZ4JJKS3uQEGbhmCm1SRO+7C0TDoyZvcv6Yfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594941; c=relaxed/simple; bh=2Ge05KBWAfcMya41hDApaCCzf2xreZnZmDHe67BO21k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NynyMejsIJpLsRX/VtpXktFPy9Mv8T8GeQEktiv0F4YD3/7iJO69500HSp/tjGijXF6RrPV1Zug+5te4r0Rr6sPonN0eke8i58Tszzn3XD++wupNt8+wSNUJpqL454dJ3HqzQTG6rpNEexv2H+aAhwkcNFd+Bf52kCwGE7FYWMo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dk2HCiGI; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dk2HCiGI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594939; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2J9RpEfm+P5tNpnFCx5OHAnHnj2zwjI2eSWMoS4B2kI=; b=dk2HCiGIcy81ICuWGkvFqknmglojKBHybej2JOm51Ecju7wHwJE6LQZNeD0l8nOMC+sUIb q+7vTqJInCA9PWZH3ol9FzmTVyjKuaY+Xlk3NeErm1uSSTtKm1DrzVyXiziwocSk7tsxvq ZnasYkg+1UIokM+SLS1OBt8sok1psrI= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-381-ZzFESUS-OvKcXQ1rBmT4AA-1; Wed, 05 Jun 2024 09:42:14 -0400 X-MC-Unique: ZzFESUS-OvKcXQ1rBmT4AA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0550A195421D; Wed, 5 Jun 2024 13:42:12 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id AE1451955DC1; Wed, 5 Jun 2024 13:42:09 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:08 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 20/38] trace-cmd lib: check for a negative return value of read in tracecmd_compress_copy_from() Date: Wed, 5 Jun 2024 15:40:35 +0200 Message-ID: <20240605134054.2626953-21-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Check that read() return a non negative value before adding it to all in tracecmd_compress_copy_from(). If all == 1 before that, we would exit the loops thinking it succeeded. Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-compress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/trace-cmd/trace-compress.c b/lib/trace-cmd/trace-compress.c index e550dbd4..3ca0e21f 100644 --- a/lib/trace-cmd/trace-compress.c +++ b/lib/trace-cmd/trace-compress.c @@ -714,10 +714,10 @@ int tracecmd_compress_copy_from(struct tracecmd_compression *handle, int fd, int do { r = read(fd, buf_from + all, rchunk - all); - all += r; - if (r <= 0) break; + + all += r; } while (all != rchunk); From patchwork Wed Jun 5 13:40:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686967 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DCB8188CAD for ; Wed, 5 Jun 2024 13:42:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594941; cv=none; b=AM+o9caKjbAnzJTR+30FZ0EQk+ywEAcwi7Ne3El7RY6GLZ2EsIkpO8GomfvW4/zyD8V9ndZ77rhjfSwTNjJYLgDk7su43T4zrfNivMY3OohNVbcAsvdYgdp44q/OBZNIZ5IDIqGXOXHI/rNTMMgp89sVtBMudKG8fuZIcCPVF3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594941; c=relaxed/simple; bh=O06QTDqQJ+B8p/Rs65MbqeQtNgmuUu/E6CBAoMDVT2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i3XP52lreORQlSa0U9mjlygl/Quf+rQfEk+IqqRimU74cLDu+Y12U5fs7HmIfW1pgxPpMoiqB5Sz/T9MQLwChEWhaPPh3rRJsVYssTmnJl1lVVxjR6ORW6uaKiWLo7FdktX3eyVJYZp1hmK6JE2ocoHU128rjyzEi2DkOk6jHA0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XUtNtINd; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XUtNtINd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594939; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+aAZ1Cwx63dV+UjyEeA4ljlo8JJOVLq7NFEZvbv/7EQ=; b=XUtNtINdV+ivVUd9E3rghp6E8bGFmwwK2EAdFiGHuhNuoVCs7gMyozZl8LtYFCdcb+R18x Vu/bh875V712GRY5wpD8Ikx9Kkw30Pq4dV9+Gy1nB5TjkDy70vOmy414h3Y1950W+cOD2U FngtmryYQGkThtjUD+TLEe83PSVIxOo= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-313-PeVYuAN-MAOfoXROcfq0dg-1; Wed, 05 Jun 2024 09:42:17 -0400 X-MC-Unique: PeVYuAN-MAOfoXROcfq0dg-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4407D1955D78; Wed, 5 Jun 2024 13:42:16 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id BB80B1955EB8; Wed, 5 Jun 2024 13:42:13 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:12 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 21/38] trace-cmd record: prevent memory leak in clear_func_filter() Date: Wed, 5 Jun 2024 15:40:36 +0200 Message-ID: <20240605134054.2626953-22-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Free buf at the end of the function. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- tracecmd/trace-record.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index a9e5e64d..2223d5bb 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -2509,6 +2509,7 @@ static void clear_func_filter(const char *file) filter[len+1] = '\0'; write_file(file, filter); } + free(buf); } static void update_reset_triggers(void) From patchwork Wed Jun 5 13:40:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686969 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFBDF81F for ; Wed, 5 Jun 2024 13:42:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594949; cv=none; b=EGSFL9bbmRWWCKCxe9Y60DXm1GMF6CmjF/orF2e7JUklLtQ9m27AjIK1qbVgSfEO2E+2otI7Ib4BX294EJ+j4TNicP0siQB+YnJnBCuqTCH4IY+egavnoNYP85GqOikAe0t7xwsTNPZWaGqk/dybR3EXWF4F9+0l3xknVqV8fkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594949; c=relaxed/simple; bh=V9g3zGsdvEeYMLvTodkdwPMwpH067mkz3hStftE/7D0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dDbDbC+Km73B39EVxqujjxPJ/dnAtZQGD4UUfK7PEq5MQcmN3DIqnRyTZw3aVYs9PpXxSEyTdFaXiZAcQXGNPCQI644GoXu+xqXR0DExWFirsC8OODFAGPk/km0mN5o9X/iOxPXVWI2f7Dlnx8mkRXBRxLprs6P7QQETskk32RI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=V+AHS99k; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="V+AHS99k" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594947; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aHV3qq2prNNSL+K6lDj1Fo9TduGupxQ4gKUt5bnUCn0=; b=V+AHS99kynVSnzRaIIGTj7E11xyHOK67NHp7bqKjnPsjz6xLuGKPSBafom4D9FR8L31YnG jELiDcTGUqI2XW6lgV3GaEAB5dcB2QEqCDRIim2iKd6d/hXt28H8JCvyry5MJkSBXr7RBI E/Q9F7581XvLfJMOVKCwfYZzZgob/FY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-641-JnYEYtehPp-o1U-p11PiNA-1; Wed, 05 Jun 2024 09:42:20 -0400 X-MC-Unique: JnYEYtehPp-o1U-p11PiNA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 82B2029AA386; Wed, 5 Jun 2024 13:42:20 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id 3B2C7492BE8; Wed, 5 Jun 2024 13:42:17 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:16 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 22/38] trace-cmd dump: prevent buffer overrun in dump_clock() Date: Wed, 5 Jun 2024 15:40:37 +0200 Message-ID: <20240605134054.2626953-23-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 The clock isn't big enough to hold the string with the null terminating character. Worse, clock[size], which is out of range, is set to 0. Allocate a big enough buffer. Fixes an OVERRUN error (CWE-119) Signed-off-by: Jerome Marchand --- tracecmd/trace-dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 11c1baf1..c0a282c9 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -961,7 +961,7 @@ static void dump_clock(int fd) } if (read_file_number(fd, &size, 8)) die("cannot read clock size"); - clock = calloc(1, size); + clock = calloc(1, size+1); if (!clock) die("cannot allocate clock %lld bytes", size); From patchwork Wed Jun 5 13:40:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C6CB193094 for ; Wed, 5 Jun 2024 13:42:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594949; cv=none; b=bM2pCvAai92qY0w35DwFeng9hTANUdq81fGfHgXqqZSDmxnYb5RxbNng95VYqT8eBjPkZZscG2xv0OuO4LPhBnDKuKDKi8IiGMgqCaP6S9N1YWopsg+0SAOoWQfUqPppqI5l63BNC6schp13okw8/blf/cpVauY7wfalQlquMzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594949; c=relaxed/simple; bh=W2bsMX+bwKKgs7RPDvcwZLAbIr7EjgWgSSo8b/TskMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DFq1zEe6UK3hr0GgVh22i0chkFxGFfwXrjgqgQRK6AIPvS/PhcBrefZqXXKcHCRIGM63unfo/+8H8x6UlTl4Rdj7xaZFiYHgzMQfLahGFtr2TBJwcQ8d3d4gBeuak6lfp8iE58nak3lntapp9iEPy7QTblG97vnxs2ugzGJjYXw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gQ+nlmEu; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gQ+nlmEu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594947; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4LsHWYBIxF7f92vylZzYoxYL6lJ8P9abttdny3bqni8=; b=gQ+nlmEuK2CyD3NyV/GwYOQJV0uQirC3APZw4vCqyp4uS6B9wuNwOM8EtMNTpdLqu6yBrn LupivFVv72yih0m2eirMul4aIt51NmKtXFV9WcuBTaUPli8sRvl+WTp1EqoQAxEbt1tWDH dSPixud6fzcbVMk1tYG4bXOmgxHZmfc= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-54-4pSwPj2NPMaQG-h6SHTr4A-1; Wed, 05 Jun 2024 09:42:24 -0400 X-MC-Unique: 4pSwPj2NPMaQG-h6SHTr4A-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 974151954B3C; Wed, 5 Jun 2024 13:42:23 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 0F24619560AE; Wed, 5 Jun 2024 13:42:20 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:19 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 23/38] trace-cmd lib: prevent buffer overrun in read_string() Date: Wed, 5 Jun 2024 15:40:38 +0200 Message-ID: <20240605134054.2626953-24-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 In read_string() we try to write a null character at str(size), which is out of range: if (str) { size += i + 1; str = realloc(str, size); if (!str) return NULL; memcpy(str + (size - i), buf, i); str[size] = 0; } The character that should be zeroed is supposed to be at the size - 1 index, which is the size of str prior the reallocation plus i. We also know that buf[i] == 0 so we can simply memcpy that too instead of zeroing it by hand. That simplifies the code a little. Fixes an OVERRUN error (CWE-119) Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-input.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 3284dbd4..c485acea 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -447,15 +447,13 @@ static char *read_string(struct tracecmd_input *handle) str = realloc(str, size); if (!str) return NULL; - memcpy(str + (size - i), buf, i); - str[size] = 0; + memcpy(str + (size - i), buf, i + 1); } else { size = i + 1; str = malloc(size); if (!str) return NULL; - memcpy(str, buf, i); - str[i] = 0; + memcpy(str, buf, i + 1); } return str; From patchwork Wed Jun 5 13:40:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686971 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5CA31957F6 for ; Wed, 5 Jun 2024 13:42:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594953; cv=none; b=MSbd5wXW+dJlLSCBJcQ+l6byCgvIaiM7yz7G1wRPsc+S2WR6d+Qk7xOYIbyVl7+V0vnegsxOGH57PdkNEttnSyu06N7jJO50DNLxra1xWPGBEe/hWMGeVyH9P1k4kgVc6mJy5C65Hg9W+fczGg9XK8yq8jAB3tckHiZXsLocm9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594953; c=relaxed/simple; bh=7OtPmzMX7Ph+30jLs+nryv8I5gdagJxCkXwDsc0lpps=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j5Ca50yxPg2NRuLWC0LmlAoS8Xi17B8Y3zZLAX7IcXtXsA/KMGet5Bh5QlYbz0aHJBMA+3ZB+mHZpsRQavsPUNfO45xi29Ll3MXwIBJTrmbt+09NCCjXqM1dRCO4abN1QZU8GOf1TgCFQ1q9guSE7guy8VEEuaCmc/Q1gCuy1PI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TT/OEgxP; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TT/OEgxP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594950; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xi7J2Y9NUHnwrTU4fxuVIHNFXsP4EBF0vmC3cski0Ps=; b=TT/OEgxP7LRTqnAMuOlfagTkn7trzgIwuZfRwqdtyGEGp3rpwvGMnnja29V7lC93Uk6Brc 6N6DLXc0wOfkV3VFJEBTy/XVom58jtSPHbksmrqeacZVSxJGYNIZbjjaGsfN4H+bKefjBz Lm009gxZRcfvn9vBiYtyTXQOjzTcj5s= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-119-KNust7FoOBCvQyd9wA1sgw-1; Wed, 05 Jun 2024 09:42:28 -0400 X-MC-Unique: KNust7FoOBCvQyd9wA1sgw-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DCB97195E92B; Wed, 5 Jun 2024 13:42:27 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 779951956086; Wed, 5 Jun 2024 13:42:25 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:23 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 24/38] trace-cmd: close file descriptor in trace_vsock_make() Date: Wed, 5 Jun 2024 15:40:39 +0200 Message-ID: <20240605134054.2626953-25-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Close the socket file descriptor in the error paths. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- tracecmd/trace-vsock.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tracecmd/trace-vsock.c b/tracecmd/trace-vsock.c index baa310f7..df1a9800 100644 --- a/tracecmd/trace-vsock.c +++ b/tracecmd/trace-vsock.c @@ -43,12 +43,16 @@ int __hidden trace_vsock_make(unsigned int port) setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)); if (bind(sd, (struct sockaddr *)&addr, sizeof(addr))) - return -errno; + goto error; if (listen(sd, SOMAXCONN)) - return -errno; + goto error; return sd; + +error: + close(sd); + return -errno; } int __hidden trace_vsock_make_any(void) From patchwork Wed Jun 5 13:40:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686972 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 407E1195801 for ; Wed, 5 Jun 2024 13:42:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594954; cv=none; b=gUawPOERsucwslwlcWcRVzTY0HtKQTVWaMm0KqMWpsKogyd+5fn/KOJUP/SkxebUP07UhOzP7IxQEqSZoubxNS/s4Bw4EaOXEgQ+0Y+jWxBijutV4u7N+v6CMIu6X0E8/CoZL7uYzbkzkrRNBXLk/4xMBl4SIsVrgifH5zHGSmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594954; c=relaxed/simple; bh=NEaW4Mmb8TfoGv7lr2GJugQzfYqsHKFAhDnXEX6woPs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZUfEFu+a0VhUNKD+XNeLeOiUgfGXiVhcl7HYR9I4jduBwmrqhVU8CklJwpP6QYW+aHUcSNp4uzkFHwiHpPcqBTvolBn7GOuugpZRCZQ3r3WmskRqs/WpdRbkmxH/iiNpfjNqAObAwN27hyeWjh0kIKw9933wuBIzhiu9FBZS78A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=c6aMWDq3; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="c6aMWDq3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EGjtt+ZInajUUp3yUqx/LLQEIhk6bbhaR/CRPy8T/eI=; b=c6aMWDq3AGv+8WTFEoWiAsvknQ5UpVIgb40ptO/sCXaEEthGe8NxZ5oiuE99yj1m1dnvrZ uGpHaiQfeVuvaBAWF+/vzx3/ohn140t0Y71E14vHtUypw9etLG75GedJORNy+TF9R6CPST UVR5HtUXh1RdT1CkqorTYKhcQnMCv9g= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-397-h1WGum5OPBiOr6xzl4oXIg-1; Wed, 05 Jun 2024 09:42:31 -0400 X-MC-Unique: h1WGum5OPBiOr6xzl4oXIg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B7F4F3806700; Wed, 5 Jun 2024 13:42:30 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id E2EC740D1B68; Wed, 5 Jun 2024 13:42:28 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:28 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 25/38] trace-cmd lib: prevent memory leak in glob_events() Date: Wed, 5 Jun 2024 15:40:40 +0200 Message-ID: <20240605134054.2626953-26-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Free event_path if malloc() doesn't succeed. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-output.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index c270d03f..7be175af 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -868,8 +868,10 @@ static void glob_events(struct tracecmd_output *handle, path = malloc(events_len + strlen(str) + strlen("/format") + 2); - if (!path) + if (!path) { + put_tracing_file(events_path); return; + } path[0] = '\0'; strcat(path, events_path); strcat(path, "/"); From patchwork Wed Jun 5 13:40:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686973 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 852B0188CB3 for ; Wed, 5 Jun 2024 13:42:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594960; cv=none; b=lP4t2sIyR65pXj7k8kuUZWQQqETkhnOIbCFLUafJgn052wW/a4l1irqUwmvkuwTtSmASyhx5Pt9lAzIaAax05cCdNpUj+gUYgbSU++E9B7VGNGLSiWCjQCnjN3+U/ARBoBVBAaajhQEQJg9UzIqnIEjfpXLFpILaX5LCJIginII= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594960; c=relaxed/simple; bh=WxiEWqjqJvXNeNz6muzQk7gA7aec2o5twqsrH3Wd/F4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gfUAK4jJfShv80461h7jj8KhSRSPv6Hw+yIEz+pMn+bSmRCx494uSBCSBaM7LpqKPQOytaNPpUd2BjMupe/HWIfv9XTkWWFVapnpzSX9chuM6BSswhKg/Z873t8nl2vr758BG2BohjZhYPrOe/2eec7SQ/2mLQdSya78FKK4Fr4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PWB3k/nQ; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PWB3k/nQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594958; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MNF4zgtfYv1348FEzWn08y7vNfXIO41Jk68YoJT9IJw=; b=PWB3k/nQod20KYPIX6K33Vq4oZ0tsZQBMyGVOJYSm7KlWMNVKu9PLrJ94NaelyjyijaBDi BUxnjOvIU9/9VYQILYHo5/7M8hBf8sIXzA9WtuZuHzbKY04NOjVz+wzBtTc+Pt4CAJM/7b DrtlBCtyaQwrXYL4ka7tDH2LC0blqZ0= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-6-6l6v1OBEPBO4AwudWXoL2w-1; Wed, 05 Jun 2024 09:42:35 -0400 X-MC-Unique: 6l6v1OBEPBO4AwudWXoL2w-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A8BBC1944D2B; Wed, 5 Jun 2024 13:42:34 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 55E0B1956086; Wed, 5 Jun 2024 13:42:32 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:31 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 26/38] trace-cmd record: don't print a NULL string in get_temp_file() Date: Wed, 5 Jun 2024 15:40:41 +0200 Message-ID: <20240605134054.2626953-27-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 In get_temp_file() if we fails to allocate a temp file for a top instance, a NULL pointer is passed as the argument for a %s format in the error message. Signed-off-by: Jerome Marchand --- tracecmd/trace-record.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 2223d5bb..b4cbd438 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -559,7 +559,7 @@ static char *get_temp_file(struct buffer_instance *instance, int cpu) size = snprintf(file, 0, "%s.cpu%d", output_file, cpu); file = malloc(size + 1); if (!file) - die("Failed to allocate temp file for %s", name); + die("Failed to allocate temp file"); sprintf(file, "%s.cpu%d", output_file, cpu); } From patchwork Wed Jun 5 13:40:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686974 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F187F1957FB for ; Wed, 5 Jun 2024 13:42:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594963; cv=none; b=RkgD4R4ZgYJrJjBpDvs+L73unVs/3BfSZeX/tStGIrY2ke22tuGwYBAq8KQdPC03rVQNgc9JdakDlJWl4v0HmfDTgJ0eOBe74bnJRGY5Js1dKmtSJdPP98tLaZKQIbLJLtsiSmzzitTv1k4u85Ps5lm8LeTWqFJAcVM4f2km820= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594963; c=relaxed/simple; bh=AxtAwmDYqa7/1ZOz7DCVdBqsTzasCLhjtGCHB8Bd2DQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tyKQ8f+NuOmxz0j8gr8sxVKuEi6KI+DUXWWTYDUNIwXqQQKDwnqK3xC0BeZ+fVT/K0Sn6vNI+HVp+sL+2bHNg/0r4eYoCiy7HrasV3NEs6oxU+lSlkPQf1xkMkFQvu39Rcs/0lemg1x6CLnOyVCWyuEVcEh4ShUC/w7OLKL9rS0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=d7IXsJwL; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="d7IXsJwL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594961; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6/D0JS99Ps6t+1OFBOSTvqCizS1L3blN75IH206VAQw=; b=d7IXsJwLnnMKev7ORNHfmbxRwci0xrXOVAVd/JkOA5/U4qcy1fJm60S+HJD3tcwUgYxAlY Uns62DiubQWLq0q7EctJqkQg91Ee/Ke+mHmv+9NCPYKrVzpI+JfWgQdmkBiVz4zEuAE97f lpLLe5vMzv0OFApns113E5mrDdWMmkI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-332-boNdEVK5MzaVrmE1oOKH3w-1; Wed, 05 Jun 2024 09:42:37 -0400 X-MC-Unique: boNdEVK5MzaVrmE1oOKH3w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 963B7185B948; Wed, 5 Jun 2024 13:42:37 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id C101B40D1B68; Wed, 5 Jun 2024 13:42:35 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:35 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 27/38] trace-cmd lib: prevent a possible file descriptor leak in set_proc_kptr_restrict() Date: Wed, 5 Jun 2024 15:40:42 +0200 Message-ID: <20240605134054.2626953-28-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 In set_proc_kptr_restrict() we test whether fd > 0 to close it. Theorically, open() could have returned zero if stdin was closed. I don't think it could happen here, but changing the test with fd >= 0 silence the static analyser which complains about a ressource leak. Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 7be175af..6a9606c7 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1124,7 +1124,7 @@ static void set_proc_kptr_restrict(int reset) if (write(fd, &buf, 1) > 0) ret = 0; err: - if (fd > 0) + if (fd >= 0) close(fd); if (ret) tracecmd_warning("can't set kptr_restrict"); From patchwork Wed Jun 5 13:40:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686975 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6589194A74 for ; Wed, 5 Jun 2024 13:42:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594968; cv=none; b=HxY+7pv8W8yzoUTbQkT+ApocjI2YjaTEhbkQy+Ck/IDL0Es7nB0c+Wk6PDgDojJHuEFIcUHK2Uuggkyehl4evXy/vVFShoo+IwHWcg7+4wSUMWPaYqcrZSkS+HrZkdMFm9MQxgJTCi/4IgN+pqgHCGe7vSUr+E7MI04vPdmWMp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594968; c=relaxed/simple; bh=u5ETIK3Yq/id9GNfDZ+x8oyWayW+n39oCs1w9h6g1Z0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QIsb+H/FikvuybBTD1ztf2w3XFbEeA8I2mvR5OMXeY3m8sJc+D+gbIFzw3c+XVTT+d875WIyQRI0nw4e8aee3mG7iGT4c5T60xQdlCpVxflWvK2qgHg44IGr9VqngH24SIq5N/tpgVwpNzMoAkzu1ugrUOm1T4u1c1DJSHnuPZg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FBwL5ecW; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FBwL5ecW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594965; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YPX1++GmcnJREoAy6xVC/uQn5dUL/rATh/cyPgdz9wg=; b=FBwL5ecW8xfKiICgatruRhafle5Yh3cbAb8KLA6mg54hYlNuW6wIj1skV0BdRbOCNDQHVN ypHu2U2yT46jTSsMdn9UNqyLgOU9zrKerRnkHYeKyndmEWtAOvcTal9RRyBM97G/wK5CiB 1OPnD5u59HRKPWmv5R8p5ZJ0gIWuPRI= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-586-ZWC_Cj8AOLWqMgAHIeIzuA-1; Wed, 05 Jun 2024 09:42:42 -0400 X-MC-Unique: ZWC_Cj8AOLWqMgAHIeIzuA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CCD061955D6E; Wed, 5 Jun 2024 13:42:41 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 67A751955DD0; Wed, 5 Jun 2024 13:42:39 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:37 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 28/38] trace-cmd lib: remove unused tracecmd_parse_cmdlines() function Date: Wed, 5 Jun 2024 15:40:43 +0200 Message-ID: <20240605134054.2626953-29-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Static analysis warned about a possible use-after-free error in tracecmd_parse_cmdlines() sscanf() fails to match both items. However, the function seems to not be used at all si we might as well remove it entirely. Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-util.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c index a4334a98..37caab45 100644 --- a/lib/trace-cmd/trace-util.c +++ b/lib/trace-cmd/trace-util.c @@ -135,23 +135,6 @@ bool tracecmd_get_notimeout(void) return notimeout || debug; } -void tracecmd_parse_cmdlines(struct tep_handle *pevent, - char *file, int size __maybe_unused) -{ - char *comm; - char *line; - char *next = NULL; - int pid; - - line = strtok_r(file, "\n", &next); - while (line) { - sscanf(line, "%d %m[^\n]s", &pid, &comm); - tep_register_comm(pevent, comm, pid); - free(comm); - line = strtok_r(NULL, "\n", &next); - } -} - void tracecmd_parse_proc_kallsyms(struct tep_handle *pevent, char *file, unsigned int size __maybe_unused) { From patchwork Wed Jun 5 13:40:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686976 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D2741957FB for ; Wed, 5 Jun 2024 13:42:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594968; cv=none; b=oRFPDojwqNcL7qqSXvSYQg/4614g2fIamsceFjSNEFAme9J3FGCqgL767ILqGAK5Yvy62d3Z2dXfNG/F2OT4zB8/792/QEZCEt6qTAjA6wpERj8VTb79nOwvjB1MD+G7KiXuKAmLT0arDmMGjHekQe9xo+A8ZrL/6R4YewHKqTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594968; c=relaxed/simple; bh=IpJEsPfL6voeh40QFqUj2D2un4yosns91vcjCNhEpBI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d33KqMyloS0PKHNCzsOs3srF8JyTHC/P19wiY6a4BpSNKbg54B2DxQrQu0fdDiJm5IMTUfpt6T2IMxv4vPjVQt11ZxqRTAzHyzgy76Oyjl0NLQVQKFwW5V4acl6z91ctq+TidjcpelyDduG52V8ikeIDI3cn/7r3vlKgTdlqptE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dvsWO201; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dvsWO201" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594966; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IhONIFqBSJgjIozMPT1SV7swMmlk5UlMBJUPr+Lpo2g=; b=dvsWO201+6Tw//IRdJk4BNCQ+tQEIM4OxE7GEMRHAqNhOPPmsQ3BrTRtOChYTCcg6Kphtf dK7gAB/cVm7Uczd/XbRt/LL5UXN/k9CNxWp4FLkLyu1l8JfsteCGrySx4FgPKrgCnIo5po 2GB4iiDW+5KP8kIqDog2TScnPUffVj4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-chB8zVvvOriXjaLVW4H1pw-1; Wed, 05 Jun 2024 09:42:45 -0400 X-MC-Unique: chB8zVvvOriXjaLVW4H1pw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F11943806700; Wed, 5 Jun 2024 13:42:44 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id 24EE51C0005E; Wed, 5 Jun 2024 13:42:42 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:42 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 29/38] trace-cmd record: prevent memory leak in setup_network() Date: Wed, 5 Jun 2024 15:40:44 +0200 Message-ID: <20240605134054.2626953-30-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 Because of the again label, msg_handle can be already allocated if we exit after we got a negative socket file descriptor. Free it there. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- tracecmd/trace-record.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index b4cbd438..770e775b 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -3903,6 +3903,7 @@ static struct tracecmd_msg_handle *setup_network(struct buffer_instance *instanc if (sfd < 0) { free(thost); + free(msg_handle); return NULL; } From patchwork Wed Jun 5 13:40:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686977 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BA95195801 for ; Wed, 5 Jun 2024 13:42:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594973; cv=none; b=ftXOq2SczInfDp7zpScNhrEAC6rV4gbH/Z4tU/yG+3EDEAfc6DraS/o13wn1kH8ycN0Uz/M5HNlk6uId8TNYiQ3Wu7BkVTHkRrO5OeY8BqZOtulv18bt9PKlr/+i7QHBu9+4XnZUcmPGyujuM4FtP/kjiXO8rTKNWwvOt9giRls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594973; c=relaxed/simple; bh=IddH5VtVmvkF9+h14ZgSD+y64cvsrR3U+Kh8AdBd3QU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cpC2O3Pn0S9tQ14i3Ocxb1oiAD8is438oUMyDjYpqNlirk6ljWyuTGXG9cpC7vedNwaY7bwIeeJBFud/+xu2D2rCvaXdKthoUm9dwpDLcwrON+UWTn//k6H1MXeZp+j/xlR86hnSyd8gKeyRK/U7dF1R6Gd2ZS2XIVO4IAL9xH0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=GWI0PlZY; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GWI0PlZY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594971; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sz3KpoJEylgwtJY8UMmhe/3SgGccN+iYPKn3fXCgayQ=; b=GWI0PlZY25KAvSHl6IZGVWKEZvBDao9RAFqWrJRMfMC+H7EflwQ/RcXKfIH/FYdlhuuM8B kBt4hVBhGW9Ik9TXerSO5WIGSZZc3Ktrz7Xx9jCeFq7O+wnCXXPWYlyg4oSFuTHkhdofPx lSuyY26R/daGJHgfo/vfgD7ERTwBZ18= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-683-BGuQ5SVhMwSoF-n0dZ41Ow-1; Wed, 05 Jun 2024 09:42:48 -0400 X-MC-Unique: BGuQ5SVhMwSoF-n0dZ41Ow-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D38491C05122; Wed, 5 Jun 2024 13:42:47 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id 047EC2166AF6; Wed, 5 Jun 2024 13:42:45 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:45 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 30/38] trace-cmd listen: prevent memory leak in communicate_with_client() Date: Wed, 5 Jun 2024 15:40:45 +0200 Message-ID: <20240605134054.2626953-31-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Free option in the error path. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- tracecmd/trace-listen.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tracecmd/trace-listen.c b/tracecmd/trace-listen.c index 09f442c7..da46d09e 100644 --- a/tracecmd/trace-listen.c +++ b/tracecmd/trace-listen.c @@ -456,8 +456,10 @@ static int communicate_with_client(struct tracecmd_msg_handle *msg_handle) t = size; s = 0; s = read(fd, option+s, t); - if (s <= 0) + if (s <= 0) { + free(option); goto out; + } t -= s; s = size - t; } while (t); From patchwork Wed Jun 5 13:40:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686978 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F6B618FDBA for ; Wed, 5 Jun 2024 13:42:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594975; cv=none; b=D5w4qla1nkKdl7uBA7uCbVTkRu2grzU9ylZpAtEWTZCIQ3TMjgeMgC0iGdewTF/muBxWRGKUrrIyPhTET8hgAnV7PdbtwDJDd21a3FGtUkCEJtd3b50zoeTb9nsGX+oYtFvpFtNbCZ4SusFKOfd0bpgdcj5EHCGcwwOpR80Ycho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594975; c=relaxed/simple; bh=Xes2ybIkZgsj+NnwJNMkAip/PMVL8bCr9f+jGB7b1hY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jt/N1QWwvzW9bVvA01J3p4T/GHAzqPZYZHgN/DFnGGrSzWoX0vgpq9yWIgujdz/eKNs23l9YQSg2dMIxfz8XxG6OFfroNRC5lKgikdWu92kQOsYMPn9BNqJiL1+9ezrIpA8hcuTL6zQbVFvCYKlu2JV7J6XsGtxh6VgAlf/00OM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Tn2Dl9hB; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Tn2Dl9hB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594973; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Iy5yOFXB2vt1uQZoVw3SEYUuTWvHIcOS6gpRrBq2MzI=; b=Tn2Dl9hBV1KzbRmDxtTfzyZ4478/SAttFjXDOFDcUonxleHeMTAalAoJ++9o+lab2bFw0S 9BaG5liVFfMTPO3JdksemqRseFncn0vX4AwPbDPk/YM4LT3C5NkysqtVLj/+5qXi7DDPBh uZ2RR9SqJ89zFlf1dSNatfkLLvpjanE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-459-C-Q0WMOyPiubciJl1jFlJg-1; Wed, 05 Jun 2024 09:42:51 -0400 X-MC-Unique: C-Q0WMOyPiubciJl1jFlJg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A844F800076; Wed, 5 Jun 2024 13:42:50 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id D7989C15971; Wed, 5 Jun 2024 13:42:48 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:48 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 31/38] trace-cmd listen: prevent a infinite loop in communicate_with_client() Date: Wed, 5 Jun 2024 15:40:46 +0200 Message-ID: <20240605134054.2626953-32-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 The loop used to read the option is obviously wrong. If the option isn't read with one call to read(), it will loop indefinitely. Move the setting of the initial values out of the loop. Signed-off-by: Jerome Marchand --- tracecmd/trace-listen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tracecmd/trace-listen.c b/tracecmd/trace-listen.c index da46d09e..af9e3454 100644 --- a/tracecmd/trace-listen.c +++ b/tracecmd/trace-listen.c @@ -452,9 +452,9 @@ static int communicate_with_client(struct tracecmd_msg_handle *msg_handle) goto out; ret = -EIO; + t = size; + s = 0; do { - t = size; - s = 0; s = read(fd, option+s, t); if (s <= 0) { free(option); From patchwork Wed Jun 5 13:40:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686979 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 531D218FDDA for ; Wed, 5 Jun 2024 13:42:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594979; cv=none; b=RnIoCcx27vvkAX3XiXxXDpyOx8KQDqXF3c5eKoG8RRJB2MMp6IxThzgF4Azo2VZteft0hyjtAUTCHGMJrJhQJOhv0JfgTLUyNJ6JrwWq6S80fT/ApIUZtvMsOvZg+ot6InYAKPpZ45mEPwVRNue+KntbBwwZu/doKDtefdcOOQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594979; c=relaxed/simple; bh=F4TqmHUHiE6IxgZNl2NtmOZPGaBDqUjJvOq555Fk4D0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lS8KEFzEwu/oKXAQ7aOfL7/8HOKXDeLm71wJw5rPe0fIeGlApP/hMW+BSqIl+ajMvz2DmJehEcrDhlLehT9W8BsP3GJ/6OZnL5AjVOokaeo5a978EV7zpu+wMbQGtVa0tIg2yRgsAauX2sul6DZ7apeZRw4bWNkd/UtaFAc22T4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fVTdv0lO; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fVTdv0lO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594977; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d2VaQrQ2Zri57wNIs1QKqhla95JBoCevABvvUKYcrAM=; b=fVTdv0lOpn5EsaNfG8sfvvMsW2Wm2R0pBmwe3dLivrwhWF98IDR24Eh1w+gb3YJTOJN6Ma hpBgKKn+rKUqIaxj+CR6DSuRznti6Yfdg2fJIsZmr/l0HadBQs4DDsme6GUvBMFyZA7utv Ysbz01Nd3QLfuf839+fkZmiO+xktHEY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-310-DFz83D4cPzigpWKqmAaqdw-1; Wed, 05 Jun 2024 09:42:54 -0400 X-MC-Unique: DFz83D4cPzigpWKqmAaqdw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C21083806700; Wed, 5 Jun 2024 13:42:53 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id E9513492BE8; Wed, 5 Jun 2024 13:42:51 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:50 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 32/38] trace-cmd lib: prevent memory leak in tracecmd_create_event_hook() Date: Wed, 5 Jun 2024 15:40:47 +0200 Message-ID: <20240605134054.2626953-33-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 Free hook in the error path. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-hooks.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/trace-cmd/trace-hooks.c b/lib/trace-cmd/trace-hooks.c index a58b5356..47f25fb3 100644 --- a/lib/trace-cmd/trace-hooks.c +++ b/lib/trace-cmd/trace-hooks.c @@ -151,6 +151,7 @@ struct hook_list *tracecmd_create_event_hook(const char *arg) invalid_tok: tracecmd_warning("Invalid hook format '%s'", arg); + free(hook); return NULL; } From patchwork Wed Jun 5 13:40:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686980 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8535E194A74 for ; Wed, 5 Jun 2024 13:43:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594983; cv=none; b=g61dyna1QZFTRdGGONGFTVQlajghgMU+7QhkCDRIgK8w9uds2OmReQlHMamvDvHJjWagYm5Vcw4ZNH8StA2Eo9gkPhJgAsmI2J22UQdwfNG/owfMu9ZVJ7KKx0t7O9wSjlnEaTUEpvXC5T1vkgOBsFBYvwFIjnL/qPA/hHBDyc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594983; c=relaxed/simple; bh=Eo017dL4L2AQ3GQQ/r3v/2KABfrIzwaLjT2sHJzET+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lg8eMzk9s7HTqNgMXh9IzXoz9MUGKkCR4K4ezdy87l9r1wgSxZ5gOMpiPVgT9jWHGEbPFt0H0EXEXpLgQq4ZZgn3rvyh0V+5I9tAK6ZnBXvdaxL6uGlOoob4JZp8Rq3ByBqAqTN5MyKSla94c3UBLs2LoJReakoT/fqv7LtnM+Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=UPf8+JC1; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UPf8+JC1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594981; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TJJIQYuOmgru39ZnQ9/hAIKnRVP1qntNsnJQsmydn6E=; b=UPf8+JC1UesexES8G2XDaX2XdO28TC2a+yfSB21q0PcHQ9G7lkGhA0f7OzeXxyboC3zVTA Zb6Flq2rAI++DqZfJ+cMbmDHHo2L6ws8A/+cvLRTvjFIbcVw6c69w429uw9apujRe2qlRB +s6+eMpyJit72SevjpJJKBd+289lItE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-471-sbLPJPVwPTOSAkgTveL2bQ-1; Wed, 05 Jun 2024 09:42:57 -0400 X-MC-Unique: sbLPJPVwPTOSAkgTveL2bQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D45DD85A58B; Wed, 5 Jun 2024 13:42:56 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id 07107201EAC2; Wed, 5 Jun 2024 13:42:54 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:54 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 33/38] trace-cmd record: prevent memory corruption in parse_record_options() Date: Wed, 5 Jun 2024 15:40:48 +0200 Message-ID: <20240605134054.2626953-34-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 In parse_record_options() we can end up using a deleted instance after options have been parsed. This can be triggered by the following command: $ trace-cmd record -v -e block -B foo ls We probably need a proper to avoid to end up in this situation, but in the mean time, check that the current instance isn't marked for deletion before calling remove_instances(). That at least prevent an hard to debug memory corruption bug. Fixes a USE_AFTER_FREE error (CWE-416) Signed-off-by: Jerome Marchand --- tracecmd/trace-record.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 770e775b..dc3e5285 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -6909,6 +6909,8 @@ static void parse_record_options(int argc, } } + if (ctx->instance->delete) + die("Instance to be deleted is still used"); remove_instances(del_list); /* If --date is specified, prepend it to all guest VM flags */ From patchwork Wed Jun 5 13:40:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686981 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00DA3194AE6 for ; Wed, 5 Jun 2024 13:43:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594985; cv=none; b=ULTYvWf8SfzuGnJhEJNSJ9qj9n81ISPzDJqYUFRAYHWqzF0yUVCdt/INP3lgM2lE3bALJFada7awmUWAc1HLL5zd6HDT8PUwPm7S1ByHSJ2220qWKC8KAuEwQRher68v0NgFtu4AGI7wmwGpl4PIG81w9f4t1WTAbafNs1+JuJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594985; c=relaxed/simple; bh=GhXtEryC61CCkkDU92YZJQn78OmrvY5P2X4BtGkR59g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WWBPyaOQxcE+B42lHFTDt95fwoxs+MlPmeat2nilDCTB3U9MP0u2AuhQd0B08AaBpkM+wTh3WmLPd4bx8tmJK1l4ci9B+FPecKdX16wxB0OuDdHx7uGheXQunF2H+5QjtaraJ46Yn8Y/yTPiWYGFh3DoiVm8XIkjTyd27jh3zAk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZUMkSlGm; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZUMkSlGm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594983; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SAZB7cnHFODqMtTyoJ2Qs+FqL4Vc0PY8arBpGJhp0TE=; b=ZUMkSlGm7MQCjib5WPOQNePbtUeirrDOoLC456RROJT7YZThkwuJzFnksY37jNrvxWVpLh hsqutOkrv/mTeWnw+np3FiLgAWdFfxG5Yhf+B+xlQRUrI1tITYs2zxX9uQ/jc6KFHZlvn2 9SwwrzWN+NSpbM5pIpD6W8Hr0zCV9M0= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-427-AvOchIw5PTi97jT2urUTSw-1; Wed, 05 Jun 2024 09:43:01 -0400 X-MC-Unique: AvOchIw5PTi97jT2urUTSw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 00621195DBB1; Wed, 5 Jun 2024 13:43:01 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id A4196300061F; Wed, 5 Jun 2024 13:42:58 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:57 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 34/38] trace-cmd mem: prevent a memory leak in trace_mem() Date: Wed, 5 Jun 2024 15:40:49 +0200 Message-ID: <20240605134054.2626953-35-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Close the tracecmd handle in the error path. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- tracecmd/trace-mem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tracecmd/trace-mem.c b/tracecmd/trace-mem.c index 3e1ac9f3..6182b096 100644 --- a/tracecmd/trace-mem.c +++ b/tracecmd/trace-mem.c @@ -555,9 +555,10 @@ void trace_mem(int argc, char **argv) ret = tracecmd_read_headers(handle, 0); if (ret) - return; + goto out; do_trace_mem(handle); +out: tracecmd_close(handle); } From patchwork Wed Jun 5 13:40:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686982 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0299188CBB for ; Wed, 5 Jun 2024 13:43:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594991; cv=none; b=iWGsJ+YQl71FlFTShNXJQ1dNGmGxwDouyx+CLlBIUhr7cDkPfANSUbkjM5H9VrfNrArwdabpGU3hGkud8kjXyIX8uYOkfBMX7SGNQknzKFqGyFY+VtkkFqdJ3Y6avRCJU499CF7Lb3aR9HHbSRDzSLqWCth1SAPKogSRQACRx7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594991; c=relaxed/simple; bh=6tu4FkQ3DU5OKr7OvHVZobHUi3BHWNIdlU1nx1zfyCM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RBeQxku3fcCCmBJ0cjHtQJe+YhUg/E0s+tz3yjyvG2PLBnkZJpdFhDh5VMPsUXznxHzF4erehmhxRccs9bumxuSo/Y9vluWl1lyIZO6iXcrnXr+v2hVT+YyydXC7iGDr2X3l3SzUidQtG5huOnng4xQ/T1VeTJm+30czpVtMAxc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TIBPDeIr; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TIBPDeIr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594988; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2e9zTjsfiJG5NUlNHdCZ0vFLzJc61iEI+GPcBf69u9A=; b=TIBPDeIrfVqRjnobj/i841Qt7qYn9VKUrFjYEcHSlvEWL1PuR8AxJAFG5XfDz0SfK5fz23 e+BkU13jueP9Qf/hOlm2v/REVefS+ibTFhmAwlviVzxynDckFpsdmFEh2wWQ55QaksrCUd bDRnDeejr4ZpSbmvgmgg1PuyYek1ah0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-ff_ddLcnNy-R7hL-OHckjA-1; Wed, 05 Jun 2024 09:43:04 -0400 X-MC-Unique: ff_ddLcnNy-R7hL-OHckjA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2104E185B920; Wed, 5 Jun 2024 13:43:04 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id 6246A1C0005E; Wed, 5 Jun 2024 13:43:02 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:43:01 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 35/38] trace-cmd: move the initialization of found_pid at the beginning of stop_trace_connect() Date: Wed, 5 Jun 2024 15:40:50 +0200 Message-ID: <20240605134054.2626953-36-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 In stop_trace_connect(), trace_fields.found_pid is used in the error path before it has been initialized. Move the initialization at the beginning of the function. Fixes a UNINIT error (CWE-457) Signed-off-by: Jerome Marchand --- tracecmd/trace-vm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracecmd/trace-vm.c b/tracecmd/trace-vm.c index f78f1d83..960ed5d5 100644 --- a/tracecmd/trace-vm.c +++ b/tracecmd/trace-vm.c @@ -280,6 +280,7 @@ static int stop_trace_connect(struct tracefs_instance *open_instance) tep = tracefs_local_events_system(NULL, systems); + trace_fields.found_pid = -1; trace_fields.sched_waking = tep_find_event_by_name(tep, "sched", "sched_waking"); if (!trace_fields.sched_waking) goto out; @@ -295,7 +296,6 @@ static int stop_trace_connect(struct tracefs_instance *open_instance) if (!trace_fields.sched_next) goto out; - trace_fields.found_pid = -1; trace_fields.pids = NULL; add_pid(&trace_fields.pids, getpid()); tracefs_iterate_raw_events(tep, open_instance, NULL, 0, callback, &trace_fields); From patchwork Wed Jun 5 13:40:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686983 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE43D188CB6 for ; Wed, 5 Jun 2024 13:43:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594991; cv=none; b=YIbom+ynlUq5ALShryoPjWJG+2fAcmiG2rJzNcIIAkJ7+XjbNgqVUNVEJgyRJFpiYfGDrj5wdYdG5LD4+PfmMD0xatJks2z5FMW5tUmObgaqKq0K73eBptur/FNFGO85k7hjl/qCYi4kMIzPY2kDAIXh8JeecG/E4rt+xz642y8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594991; c=relaxed/simple; bh=N8dbMdqcDgov9/BcKzO62yaI50kLOOyCgucWaNmZgsQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C1u81cgGpwP7IcxZDZj4vczn7bxhqx2Fa4lqBHAwndu+jw0GnAy3zKeLDFrYtRL+t9XbDQ48GS0pIqVoja6a3VGKMPEzaskAH5MoNcC4DI1OmC3oY1IYJIVC+FEkh5zLNiGmhDnnKFHqQRL4H3SYA72YfuFMv2nb4aC2oNSby0o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gveHiy6n; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gveHiy6n" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594989; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XivCqcxxbi9XGMRzeca5GIKT3G1BGoqqUwYOM3H//eM=; b=gveHiy6nLh6yeJ+FmauudWakUy7slgxoi+7Qn9+9sNkhEUOlzWumRbh+WjzGpLYkD4a1DB aazcHi3Zz3I6Vzm+CE+B3Tq8MoyvUZLodl6Fgzr2kW6TRQlAOh3rjICCGNS1q1fkiZchs8 Uqusrsh5Y6KPL2MWwUAZm7JWEdafkBw= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-369-nH-WPatIMfWuKYv9YA6iSw-1; Wed, 05 Jun 2024 09:43:07 -0400 X-MC-Unique: nH-WPatIMfWuKYv9YA6iSw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 64D9F3C025B2; Wed, 5 Jun 2024 13:43:07 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id 441D437D0; Wed, 5 Jun 2024 13:43:05 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:43:04 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 36/38] trace-cmd record: check the length of the protocol version received Date: Wed, 5 Jun 2024 15:40:51 +0200 Message-ID: <20240605134054.2626953-37-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 In check_protocol_version we compare the protocol version string with the expected one ("V3") with memcmp(). The received string could be longer than the constant string used for the comparison. That could lead to out of range access. Check that the received protocol version is not too long. Fixes a OVERRUN error (CWE-119) Signed-off-by: Jerome Marchand --- tracecmd/trace-record.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index dc3e5285..c3118546 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -3810,7 +3810,7 @@ static void check_protocol_version(struct tracecmd_msg_handle *msg_handle) msg_handle->version = V1_PROTOCOL; tracecmd_plog("Use the v1 protocol\n"); } else { - if (memcmp(buf, "V3", n) != 0) + if (n > 3 || memcmp(buf, "V3", n) != 0) die("Cannot handle the protocol %s", buf); /* OK, let's use v3 protocol */ write(fd, V3_MAGIC, sizeof(V3_MAGIC)); From patchwork Wed Jun 5 13:40:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686984 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D30219D88A for ; Wed, 5 Jun 2024 13:43:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594994; cv=none; b=Fxx7MZawVSU5Ecq91ODfMWgOoMf4D0THOfCXVuQZh/wt+egOUEeJ6wlWZLM67aAslgPHFVNtFLwiz/mALBvJMNLvpZp/vNAnF5MWAVAcdA8+NIvSmZrdK+TUuDfDY2pwSJDzdTD+SHrLrpXIFrOPd9imf6YnNr559JOn/U8/yWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594994; c=relaxed/simple; bh=tnUAQLSunvSeG8aBGa3CGilT35rBrOsf4QGUJfybdo8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EnDk/OWUWBW8NyPKOiY2z8v4B23zCYHFJXIj4uu4PklDSuIRj2tHK8STDgipWejoKw5NQWSzXSVvch7v4UVk8nopGVvxg06Ix48NwDqi0JruD7KKtfW3QuTW2/znZnjDZfZMBHR49k9Jw032pBp5BGGMs5xgmtGEdHBNApJt66c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=I27hCfqc; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="I27hCfqc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594992; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8be4saJdvBkg6gVYmHyNRCfhIOF9e2QAi0g6dAhTxJA=; b=I27hCfqcEqvj4TKIinCetv2uJdhlZFnyHNu/JiPk+yzIvwLL/Z7PO02tKucx8bod7vj1JG hCbAw/Il9c3AqRne5kkn+0I2wC46wYQBnTtS9NZNEGawm1+JTIpV/QRreMK/sXuaRAWo8P spI9lHzMOt/0mCkd2ZQm9kxG9bN2xF0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-21-bG6eJtFVMbmIZmCAr3AJ0w-1; Wed, 05 Jun 2024 09:43:10 -0400 X-MC-Unique: bG6eJtFVMbmIZmCAr3AJ0w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4792785A588; Wed, 5 Jun 2024 13:43:10 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id 6BF58201EAC2; Wed, 5 Jun 2024 13:43:08 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:43:07 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 37/38] trace-cmd record: close socket fd before retrying to connect Date: Wed, 5 Jun 2024 15:40:52 +0200 Message-ID: <20240605134054.2626953-38-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 In create_record(), if the client whose conection it just accepted doesn't match, it tries to call get another connection without releasing the socket file descriptor. Close the file descriptor before retrying to connect. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- tracecmd/trace-record.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index c3118546..0191ef2a 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -3651,6 +3651,7 @@ static int create_recorder(struct buffer_instance *instance, int cpu, !trace_net_cmp_connection_fd(fd, instance->host)) { dprint("Client does not match '%s' for cpu:%d\n", instance->host, cpu); + close(fd); goto again; } } From patchwork Wed Jun 5 13:40:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686985 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EE6F19D88A for ; Wed, 5 Jun 2024 13:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594998; cv=none; b=g98gyUMW1MtAptd1+dVJzXnC6m+XuUw5AIVOs6b2rPZmimjoPdWWur62Qooc0BDVbDgArgeD/6icUPvQfvRMpjbeBpZDsd/V2mjMh8zMbn6KM75+AuqDBeSnjnHG/0M6hG9kag391KF+/7vAXI8nTm8n/E0WiAyrOIw6nKUqXM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594998; c=relaxed/simple; bh=GshlXoLvgs3LqsXB0UcryDH0wG5o1SjC0PRxd9e8o3c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i2rPkvi05SnQaczqxDOdHyBGMncERc+ZZ+r224ss38r3nPiLhlr+5+77xDlCVxlF5+w3bIq/o5k+776rl7GAS9900+ISDG/5/qIAR9xaDkes28yk5P9vElcNzheoislxwgd4p9FA0B7RZJsJNb5NtchMermVvZRmIp6x5iACAuY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=UFHRP0m/; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UFHRP0m/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594996; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=66vbToxndl15+Gxix4n8gRCK2LAv2WWolhq0YpK+KLk=; b=UFHRP0m/5/UEQugyFCek3lElbxtPrkumXsf47fBQ4fsk84IYyWmThLTqiZW0pT89geRdxw ZqpmBdk6/sAMd9lCpp/mKQ5MRT+TTuk+xOXBy1v+vWPHvkAh9XYEHPwiOrF9ZpQPdbTVBv nTBJSagIE41+2e6UwNhoBneQG1Mat34= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-683-41KTdpjoN32ymJTRWTzv5A-1; Wed, 05 Jun 2024 09:43:14 -0400 X-MC-Unique: 41KTdpjoN32ymJTRWTzv5A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5714C85A588; Wed, 5 Jun 2024 13:43:13 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by smtp.corp.redhat.com (Postfix) with SMTP id 7DD6F37D0; Wed, 5 Jun 2024 13:43:11 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:43:10 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 38/38] trace-cmd lib: prevent a memory leak in tracecmd_tsync_proto_getall() Date: Wed, 5 Jun 2024 15:40:53 +0200 Message-ID: <20240605134054.2626953-39-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 In tracecmd_tsync_proto_getall() if the allocation plist succeeded but the allocation of plist->names didn't, the function just returns without freeing plist. There is already a proper exit path that free allocated ressource: just use it. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-timesync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c index 75c27bab..6ee4e643 100644 --- a/lib/trace-cmd/trace-timesync.c +++ b/lib/trace-cmd/trace-timesync.c @@ -290,7 +290,7 @@ int tracecmd_tsync_proto_getall(struct tracecmd_tsync_protos **protos, const cha goto error; plist->names = calloc(count, sizeof(char *)); if (!plist->names) - return -1; + goto error; for (i = 0, proto = tsync_proto_list; proto && i < (count - 1); proto = proto->next) { if (!(proto->roles & role))