From patchwork Thu Dec 5 14:44: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: 13895450 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 C571721A425 for ; Thu, 5 Dec 2024 14:44: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=1733409893; cv=none; b=P3iJ34DuZRB25v3I7lRC5CzHIPVxJVxNcq/gDXFHL1DE62fRZQ6GIapIpOqODNejXMAMmkaEUDSeDoj9ybrbI70BX5gv0sjWYucWGlzK5hxhv5AMw8hNhk13trJRmXzU45QYd3/CaPEdqMuZYjwj3roapaREI+QTuXXi+tRAevI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733409893; c=relaxed/simple; bh=LNTBPI4qhZjU247NBs/Kawm8d26TEV5IZFt+9m4gldw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bEsOqkAVPZx6a9I7BARt8fX+YPya5J9DHCBdgoCwVpcxBsR6nYUybZBHB2LnPVSpY/RzFyCoFwejN5HhZDW7Luxw+V3Ce/vdTSKUID8nq3+y/I9x/51IgmxymUzNe5Kpa8U2iExX3pRa7qfRNXOAq5ITzhuVJLapQ3q1d3YPAU4= 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=euL0KLqi; 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="euL0KLqi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733409890; 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=CO7Y3KtmbPPvuAQClnYv6sWy/tOG1wP6roOxWjVl7jc=; b=euL0KLqiLSmHl7WOe8Ibt4fMez2J0a0O+GTZVNflDvmwejyUBS4nSgk17ukrZq0JE/1yW9 H23+q8UMtbBtaRrYqYqDSEcv5u0qinj30U+miai5IOWh/Ww24EhedSFJNx5KKrgQSkLPsf fE+muYpUlMQwXtgQOPm9QAAU/6r0ncs= 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-110-EcwohR0YMqWnYvd1sgoorQ-1; Thu, 05 Dec 2024 09:44:47 -0500 X-MC-Unique: EcwohR0YMqWnYvd1sgoorQ-1 X-Mimecast-MFC-AGG-ID: EcwohR0YMqWnYvd1sgoorQ 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 C8CDD1955F2D; Thu, 5 Dec 2024 14:44:46 +0000 (UTC) Received: from fedora (unknown [10.43.17.16]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id AF654195609F; Thu, 5 Dec 2024 14:44:44 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Thu, 05 Dec 2024 15:44:43 +0100 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 1/7] trace-cmd lib: Close FDs in create_buffer_recorder_fd2 it allocation fails Date: Thu, 5 Dec 2024 15:44:33 +0100 Message-ID: <20241205144439.127564-2-jmarchan@redhat.com> In-Reply-To: <20241205144439.127564-1-jmarchan@redhat.com> References: <20241205144439.127564-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 The behavior of create_buffer_recorder_fd2() wrt closing the file descriptors is inconsistent. They aren't close if the function fails early when allocating recorder, but they are closed in tracecmd_free_recorder() if it fails later. This cause use-after-free access when the caller tries to close the FDs afterwards. Always close the FDs in create_buffer_recorder_fd2() when it fails and stop the caller to close them themselves. Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-recorder.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/trace-cmd/trace-recorder.c b/lib/trace-cmd/trace-recorder.c index 44f245d5..0413e529 100644 --- a/lib/trace-cmd/trace-recorder.c +++ b/lib/trace-cmd/trace-recorder.c @@ -114,8 +114,12 @@ create_buffer_recorder_fd2(int fd, int fd2, int cpu, unsigned flags, bool nonblock = false; recorder = malloc(sizeof(*recorder)); - if (!recorder) + if (!recorder) { + close(fd); + if (fd2 != -1) + close(fd2); return NULL; + } recorder->flags = flags; @@ -204,12 +208,8 @@ __tracecmd_create_buffer_recorder(const char *file, int cpu, unsigned flags, } recorder = create_buffer_recorder_fd2(fd, fd2, cpu, flags, instance, maxkb, tfd); - if (!recorder) { - close(fd); + if (!recorder) unlink(file); - if (fd2 != -1) - close(fd2); - } if (fd2 != -1) { /* Unlink file2, we need to add everything to file at the end */ @@ -257,10 +257,9 @@ tracecmd_create_buffer_recorder_maxkb(const char *file, int cpu, unsigned flags, free(file2); return recorder; - err2: - close(fd2); err: close(fd); + err2: unlink(file); goto out; } From patchwork Thu Dec 5 14:44: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: 13895451 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 F094421A448 for ; Thu, 5 Dec 2024 14:44:55 +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=1733409897; cv=none; b=AjYES8+xvUEZ8uV3gjtETZMNS2pLUye4IkZoJizFSzLzOzaFwgpJZ9GHYYzbVERuArWoWPwBWAgDdooidA0dSd0NnzOxvTpKQfVz77J+W5fG+hSRCGNRNeETheNOScpubAjffwxQ7rSQmJAoklCXvs2Pv2/etEIgO5VBYO9ADnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733409897; c=relaxed/simple; bh=j19Ng+jsX5NhnjzAk4phoQuCNtxGrdXqD5FSiiUN5p8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b4MNqIvH4UKuqKPhN239iRAhkw2ukrG61NW2sDqKCkEMNc+7NeR3w030thGrg0sbjyJQkGtsQ5xTedxDwtw3EJZ9lCMGKHiP4WwtgF6WJbecUnnMuOenrBUX2NfR3dtrBAU4eSWZ+CgxPV9dVrTcoiMwB0SIMhwP14hSW6iaxEg= 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=TezHZmr2; 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="TezHZmr2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733409894; 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=0e7gaiVl/TiW/eEI1WvYfc5LbK5oPuoiQGFibJZIWqU=; b=TezHZmr29nkb81A71NcjkAAq24Yg0QnP1Bgvvhl3Tm7k2+vqg01cCihQ4G7lZgL+xnHb7S XukRUcz9D2bd3/SLMYutX25m0/tH5h8kd0x1X8dWH5iQdBF32BM4NRzSdfFg/FFULMTWJK qg0yDBDCj169yZsKAMP+W3IDIh/9Acs= 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-671-2qYg7Vz3PYOH04VU4h8Jdg-1; Thu, 05 Dec 2024 09:44:51 -0500 X-MC-Unique: 2qYg7Vz3PYOH04VU4h8Jdg-1 X-Mimecast-MFC-AGG-ID: 2qYg7Vz3PYOH04VU4h8Jdg 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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8287B19560A7; Thu, 5 Dec 2024 14:44:50 +0000 (UTC) Received: from fedora (unknown [10.43.17.16]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 5209830001A1; Thu, 5 Dec 2024 14:44:48 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Thu, 05 Dec 2024 15:44:47 +0100 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 2/7] trace-cmd lib: Prevent a memory leak in tracecmd_tsync_with_guest() Date: Thu, 5 Dec 2024 15:44:34 +0100 Message-ID: <20241205144439.127564-3-jmarchan@redhat.com> In-Reply-To: <20241205144439.127564-1-jmarchan@redhat.com> References: <20241205144439.127564-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 tsync->proto_name in tracecmd_tsync_with_guest() error path. Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-timesync.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c index 6ee4e643..94f31bcd 100644 --- a/lib/trace-cmd/trace-timesync.c +++ b/lib/trace-cmd/trace-timesync.c @@ -805,6 +805,7 @@ tracecmd_tsync_with_guest(unsigned long long trace_id, int loop_interval, tracecmd_msg_handle_close(tsync->msg_handle); else if (fd >= 0) close(fd); + free(tsync->proto_name); free(tsync); return NULL; From patchwork Thu Dec 5 14:44: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: 13895452 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 CA5A7218E83 for ; Thu, 5 Dec 2024 14:44:58 +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=1733409900; cv=none; b=IeY0q3nUxxuA69XyqeMPrYcNTQ3CTWyHI/fvVbDHAL8DBdE+tehlGFyPHJ1VA3H+2E0HNLnDH0v8g9LZhBd/fRDXW0vNwGkDI/YYm6OmtRRDUNIf5TnDw/bkk0JcDAHMlzsxjaRyrkiezmZ0sTrN59oH41r5WP1kykw6r0QrcB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733409900; c=relaxed/simple; bh=72ZcV2vNkfHw/o2TG8iWu5XdMzxOsDla7tdDpPFkGf8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NGNIo9SZznG8gjwp4boeflecCQFN+nr0ln+mGJ9Ku1JoDC5EfY4AYrWdnPTwoT641tvU/4EDYQJbwsz8sXNqC70UbBryHCYPHzJMdZBTJHtyUNvCyDA1sctXZJsBpnFa+WnTPOInc+0ZXZZxHLY3paLFw0nQOy2vNKMuEkA0kcQ= 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=h7C70N1K; 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="h7C70N1K" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733409897; 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=Oe49G6cQeFFSE/V3PIb+RPJRO8lyhkyG8DwutMFAqyE=; b=h7C70N1KGh6RfVKRgzpce8yRCIbv9m9wIAEd9KoQaSx3T7rNUrWJctsnZROeN5k004hnX+ Yy/nwUh0GE/fvJhkFHIIU0ITz3AU5Rbxc8oTe6RGuyS6RDfQVSjbkLAsaJi64O7gxFRc7H V0TZF4GFXiMGWfZk2TkoHHiGhLPz638= 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-611-004PoHg4PJ-rr505Sdiz9A-1; Thu, 05 Dec 2024 09:44:54 -0500 X-MC-Unique: 004PoHg4PJ-rr505Sdiz9A-1 X-Mimecast-MFC-AGG-ID: 004PoHg4PJ-rr505Sdiz9A 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 E9B8219560B5; Thu, 5 Dec 2024 14:44:53 +0000 (UTC) Received: from fedora (unknown [10.43.17.16]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 030FC1955F3E; Thu, 5 Dec 2024 14:44:51 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Thu, 05 Dec 2024 15:44:50 +0100 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 3/7] trace-cmd lib: Prevent a leaked FD in __tracecmd_create_buffer_recorder() Date: Thu, 5 Dec 2024 15:44:35 +0100 Message-ID: <20241205144439.127564-4-jmarchan@redhat.com> In-Reply-To: <20241205144439.127564-1-jmarchan@redhat.com> References: <20241205144439.127564-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 Close fd if the allocation of file2 fails in __tracecmd_create_buffer_recorder(). Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-recorder.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/trace-cmd/trace-recorder.c b/lib/trace-cmd/trace-recorder.c index 0413e529..f02c3a55 100644 --- a/lib/trace-cmd/trace-recorder.c +++ b/lib/trace-cmd/trace-recorder.c @@ -193,8 +193,10 @@ __tracecmd_create_buffer_recorder(const char *file, int cpu, unsigned flags, int len = strlen(file); file2 = malloc(len + 3); - if (!file2) + if (!file2) { + close(fd); return NULL; + } sprintf(file2, "%s.1", file); From patchwork Thu Dec 5 14:44: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: 13895453 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 6F6A121A457 for ; Thu, 5 Dec 2024 14:45:01 +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=1733409903; cv=none; b=IkFgDv4SR3GT9HkfH5eiuPNr6axJ7S1omwK5foEpA6ctcNkicW6B5I/herkuY3SHHf08B9CI+DcIURfEc5FyMV9880IkFAO6rnwkXTCPdyKrhs1xDg6eHSfQ/sf6ED/IKuuAdE5jJNDWx5IBp7j/tEKYIEGpPei9OzRofNmg2J4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733409903; c=relaxed/simple; bh=mbzTd4y9YDx+l1EnE7cDJk8E2anvda6MgqF5xwXQ9sI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rds7ZkH43BjQ6f7J0uYOSHwciDZOs6SJCzUPYXW7ffEQqgQuH575dRqftJnfDosPtA7TEryU8hEF8wBwGbMHtiJdcFOnLJqRX4IFVMpm/BVCcGoZH7OXoLw3Vmp63sfdQ4UJeaXEcucUy8A+9zuU5soOG19fFM+Qy8Ni5NfvDlg= 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=HGDS3b4D; 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="HGDS3b4D" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733409900; 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=fySU8jnFnJGArxdAEK/S+WQ8TjVtRt5sb+mKjcLKtZQ=; b=HGDS3b4D/PvSaIF/Q+CFmzrFmqJfkQxBg6sDhWNE79FV0t5UnVLLNIUv9KAaVck0ggSfvV vT3/tGyGEWlt3NZJ9Xrzf/XrTwsOJA/kW6q0I9Dj7TC3R1SS0HvWZCFPZB7X1BCkqE7SNw 0RWpzMSgaBBwaZ2uTs1ifouIhXkFHr4= 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-503-3tA5WZCvMW6MCFbhwQlZHw-1; Thu, 05 Dec 2024 09:44:58 -0500 X-MC-Unique: 3tA5WZCvMW6MCFbhwQlZHw-1 X-Mimecast-MFC-AGG-ID: 3tA5WZCvMW6MCFbhwQlZHw 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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5EBF01954213; Thu, 5 Dec 2024 14:44:57 +0000 (UTC) Received: from fedora (unknown [10.43.17.16]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 6CB431956052; Thu, 5 Dec 2024 14:44:55 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Thu, 05 Dec 2024 15:44:54 +0100 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 4/7] trace-cmd lib: Prevent memory leak in tracecmd_msg_wait_for_cmd() Date: Thu, 5 Dec 2024 15:44:36 +0100 Message-ID: <20241205144439.127564-5-jmarchan@redhat.com> In-Reply-To: <20241205144439.127564-1-jmarchan@redhat.com> References: <20241205144439.127564-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 When tracecmd_msg_wait_for_cmd() returns successfully, msg->buf isn't freed. Call msg_free() to free it. Signed-off-by: Jerome Marchand --- lib/trace-cmd/trace-msg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/trace-cmd/trace-msg.c b/lib/trace-cmd/trace-msg.c index f5c604f1..c7583587 100644 --- a/lib/trace-cmd/trace-msg.c +++ b/lib/trace-cmd/trace-msg.c @@ -1034,8 +1034,10 @@ static int tracecmd_msg_wait_for_cmd(struct tracecmd_msg_handle *msg_handle, enu if (ret < 0) goto error; - if (ntohl(msg.hdr.cmd) == cmd) + if (ntohl(msg.hdr.cmd) == cmd) { + msg_free(&msg); return 0; + } error_operation(&msg); ret = handle_unexpected_msg(msg_handle, &msg); From patchwork Thu Dec 5 14:44: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: 13895454 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 20F0F21C16A for ; Thu, 5 Dec 2024 14:45: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=1733409905; cv=none; b=G/oN//ZpDrqVXYuRKpuDeIOV12E4Uc2SzyMb0YI9jaXVSus6CjABz2UKBmyxSK6e4Bqgl2l5Q+tNc4cxjh/CKAkWbbrh0XZ26+XcH+jt/oQQGEXl0KK/T/WknBLdZcApl3M6I3WyHsYPOe77kFaiY1RvsJdOs+jom5oFBw5HS6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733409905; c=relaxed/simple; bh=9n8MepsfEpgC+Q2Ao71oWt0RJtIcsLou+Md6/GRYBaE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jMjXvuhjabZEuLzWvgmSQw74kv1oFy0RmIQtnNrOsyEpub+4zrJSwQJcvcZqkArxceC4IPKhtVSdcoqBY/wgUsXaIv4vQ4FCX1DpRvEOgdxD7serhADURnJAnK9vWX5T6OgkGihajxYgyXKHQTRydGc4TtsPx0nZrFX2Ujz7oxM= 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=OYrQVKtL; 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="OYrQVKtL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733409903; 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=kaLfmf+1Pqv1toM33JaeNFldY8BsGn96nwdrikhDtew=; b=OYrQVKtL/ufM62+dvU6GoAi23/YlbtDeZ6u27PEBJrSIgeVK64l5X8mfBjFzMBh5zBBhh3 wEDks2RBHLSJSXJZp3igiKkX5e4IHYlR4/dChnrlW55kvkspNDVO/FJOGzi0WFXMRRHNko ZU/HXtW1v2Z51pXr1vZEqES6W3zN5aM= 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-356-lIt3Kc8bNJSnxyTs34QQIg-1; Thu, 05 Dec 2024 09:45:02 -0500 X-MC-Unique: lIt3Kc8bNJSnxyTs34QQIg-1 X-Mimecast-MFC-AGG-ID: lIt3Kc8bNJSnxyTs34QQIg 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 10BA31956057; Thu, 5 Dec 2024 14:45:01 +0000 (UTC) Received: from fedora (unknown [10.43.17.16]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id F1BCC1956094; Thu, 5 Dec 2024 14:44:58 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Thu, 05 Dec 2024 15:44:57 +0100 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 5/7] trace-cmd sqlhist: Initialize name in trace_sqlhist() Date: Thu, 5 Dec 2024 15:44:37 +0100 Message-ID: <20241205144439.127564-6-jmarchan@redhat.com> In-Reply-To: <20241205144439.127564-1-jmarchan@redhat.com> References: <20241205144439.127564-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 The variable name in trace_sqlhist() can be used uninitialized in do_sql() if it's not set with -n option. Initialize it to NULL like the other strings. Signed-off-by: Jerome Marchand --- tracecmd/trace-sqlhist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracecmd/trace-sqlhist.c b/tracecmd/trace-sqlhist.c index 9e304e43..9f2b94e6 100644 --- a/tracecmd/trace-sqlhist.c +++ b/tracecmd/trace-sqlhist.c @@ -136,7 +136,7 @@ void trace_sqlhist (int argc, char **argv) const char *instance = NULL; bool execute = false; char **save_fields = NULL; - const char *name; + const char *name = NULL; const char *var = NULL; char **save_argv; int action = 0; From patchwork Thu Dec 5 14:44: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: 13895455 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 AACEC21A44D for ; Thu, 5 Dec 2024 14:45:08 +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=1733409910; cv=none; b=kJUE/Du6hPWAO2b0sIC44ZfUTMXAhdMcaSqA4gZBaCZRl9fVBJKS+u5I/1YT4QUJfe/9Cg+vGULmBkZlhARYNfvDVm5xW306iO+MDbho1aJM5QQmfkfhQQKRZmzWog5Rk3tsSLHyYkIsfvz0F2r/PtYiYqMzyy1kkxhZAhU/puM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733409910; c=relaxed/simple; bh=IAYw2DWVn99YShE8yki5wZokd8EYANRZFVmYTdA7FfA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hykCqqOpwvTC6sUSXrOJkvPJiMZqj/jP8BOmlxa8Wqf8qsHtB6QRWu3YRADKLZXp5LDbjGqC4dRUgYdtPGC1ax7DAYmjq9k4lFL2PqbPfywDzTuF48t/HPgeM21OYeGsFzKujNoXsQNUK0I1xoIVxqsby395AtBbRnW0XfpED2s= 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=A8hUZLks; 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="A8hUZLks" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733409907; 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=kRQQh58nAPA9dFbGMMGQ/G0/HFqr8fR/rn6VMKxj+00=; b=A8hUZLksOFcMxH85568nigK0euV+zFIpfQvKfyjHoainKJ2qvOTOx56RYVfEyqfmIPIQvL N9CEQ8GSCGZM5zAWQp8EDCPXgExwPNzXmkxJ9ZHkp74I8QniLMFVC6KX7G85eGXRYgvXKk EOK02QAS5c/N5PeyOCHga6gDY3nRohA= 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-491-HmJdrXHjMEiCkKNBPY2ykg-1; Thu, 05 Dec 2024 09:45:06 -0500 X-MC-Unique: HmJdrXHjMEiCkKNBPY2ykg-1 X-Mimecast-MFC-AGG-ID: HmJdrXHjMEiCkKNBPY2ykg 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 9B6CA1956048; Thu, 5 Dec 2024 14:45:04 +0000 (UTC) Received: from fedora (unknown [10.43.17.16]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 89DA11956094; Thu, 5 Dec 2024 14:45:02 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Thu, 05 Dec 2024 15:45:01 +0100 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 6/7] trace-cmd: Fix memory leak in stop_mapping_vcpus() Date: Thu, 5 Dec 2024 15:44:38 +0100 Message-ID: <20241205144439.127564-7-jmarchan@redhat.com> In-Reply-To: <20241205144439.127564-1-jmarchan@redhat.com> References: <20241205144439.127564-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 stop_mapping_vcpus(), tmap.vcpu is allocated in map_kvm_vcpus() but not freed in the error path. Signed-off-by: Jerome Marchand --- tracecmd/trace-tsync.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tracecmd/trace-tsync.c b/tracecmd/trace-tsync.c index 57baff39..834b4da4 100644 --- a/tracecmd/trace-tsync.c +++ b/tracecmd/trace-tsync.c @@ -258,6 +258,7 @@ static void stop_mapping_vcpus(int cpu_count, struct trace_guest *guest) out_free: tep_free(tep); out: + free(tmap.vcpu); free(tmap.map); tracefs_instance_destroy(guest->instance); tracefs_instance_free(guest->instance); From patchwork Thu Dec 5 14:44: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: 13895456 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 178B41401C for ; Thu, 5 Dec 2024 14:45: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=1733409914; cv=none; b=rV8rrpXcNtDK1QUIcaRJDRQfS/0KpXD7auErjF8CxA0mi4f2kIDftWFedzEz1Vj7UwjQthciFMKFWfeMqP9PAjMmcLpcYEZ9yNft5mhem4S8Wadhl+/CI3aw14x4aIxFRbzymsqm5jrjFzMUB/eSUdZyqfmJ6C8sXKY2zFxxYR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733409914; c=relaxed/simple; bh=LNpOsTTQsy+sMzrNAXn2s/SJbQJMVL2n0YF3za1Mbfk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WUMbih1tDe3Lo0MB3bhi4wiPlBzqmc7dS2cOnQPvQNcMITnfM492egO2swK2u5fz2qVP1Xr10b2NTAQ88F49nZyUKzL8K0I/dL/5mmCPUzuCskU7Rh6mabNXGCsAMJTLVIqIZPp2BTr7lA1mpGihzdFqfX1O8NgksS1If40HeSc= 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=BhUQlwpO; 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="BhUQlwpO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733409912; 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=ck1+zShcNyFzXD+JlRIKbTR6NQsQ4a5lOa5thmAmLjI=; b=BhUQlwpOYOWE4KKTAY6e7QcGJ1UNjlVCyd2KCPukWBBOEvdCzXFwVambR48yNINLXzdBvM +KwGdT9wQmfMSE3szWo7ALDrgSmWBhekoB3D/pGen7EzyJ/Y1dfbDZDHbQioVRQr+xxPIk L3/H2Y8MYBFK9un5C1evfIncrgTS4aI= 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-373-CiyzIqiEOCe2CqwolXo_QQ-1; Thu, 05 Dec 2024 09:45:09 -0500 X-MC-Unique: CiyzIqiEOCe2CqwolXo_QQ-1 X-Mimecast-MFC-AGG-ID: CiyzIqiEOCe2CqwolXo_QQ 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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3C2CF1956095; Thu, 5 Dec 2024 14:45:08 +0000 (UTC) Received: from fedora (unknown [10.43.17.16]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 3E6BE3000197; Thu, 5 Dec 2024 14:45:06 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Thu, 05 Dec 2024 15:45:04 +0100 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 7/7] trace-cmd record: Fix stdin redirection to /dev/null Date: Thu, 5 Dec 2024 15:44:39 +0100 Message-ID: <20241205144439.127564-8-jmarchan@redhat.com> In-Reply-To: <20241205144439.127564-1-jmarchan@redhat.com> References: <20241205144439.127564-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 daemonize_start(), stdin file descriptor is closed after the call to dup2. This doesn't make sense and could lead to FD zero being reused. I assume the original intend was to close the devnull FD which in the current code remains opened while the devnull variable goes out of scope. Close devnull instead of 0. 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 6e9b4535..fe9ceaa8 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -1677,7 +1677,7 @@ static void daemonize_start(void) if (devnull > 0) { if (dup2(devnull, 0) == -1) die("daemonize: dup2"); - close(0); + close(devnull); } return;