From patchwork Fri Aug 19 02:03:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 12948239 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 488DEC32774 for ; Fri, 19 Aug 2022 02:03:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236015AbiHSCDo (ORCPT ); Thu, 18 Aug 2022 22:03:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243176AbiHSCDn (ORCPT ); Thu, 18 Aug 2022 22:03:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B5735AC71 for ; Thu, 18 Aug 2022 19:03:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0D7BFB82557 for ; Fri, 19 Aug 2022 02:03:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB47DC433B5; Fri, 19 Aug 2022 02:03:38 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oOrMU-0038Ro-04; Thu, 18 Aug 2022 22:03:50 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: "Steven Rostedt (Google)" Subject: [PATCH 1/3] libtracefs: Fix use after free in tracefs_synth_alloc() Date: Thu, 18 Aug 2022 22:03:47 -0400 Message-Id: <20220819020349.747429-2-rostedt@goodmis.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220819020349.747429-1-rostedt@goodmis.org> References: <20220819020349.747429-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (Google)" The synth new_format is set after the error condition is checked and the synth is freed (on error), causing a SIGSEV when that occurs. Fixes: 74a6754b9e67b ("libtracefs: Check README to know if we should do old onmatch format") Signed-off-by: Steven Rostedt (Google) --- src/tracefs-hist.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index 2f12cc471294..6f7d657bd404 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -1091,9 +1091,8 @@ struct tracefs_synth *tracefs_synth_alloc(struct tep_handle *tep, if (!synth->name || !synth->start_keys || !synth->end_keys || ret) { tracefs_synth_free(synth); synth = NULL; - } - - synth->new_format = has_new_format(); + } else + synth->new_format = has_new_format(); return synth; } From patchwork Fri Aug 19 02:03:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 12948237 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB75CC28B2B for ; Fri, 19 Aug 2022 02:03:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240319AbiHSCDn (ORCPT ); Thu, 18 Aug 2022 22:03:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241413AbiHSCDk (ORCPT ); Thu, 18 Aug 2022 22:03:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A37E75723B for ; Thu, 18 Aug 2022 19:03:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3EF8D6143D for ; Fri, 19 Aug 2022 02:03:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9211C433D7; Fri, 19 Aug 2022 02:03:38 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oOrMU-0038Rr-08; Thu, 18 Aug 2022 22:03:50 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: "Steven Rostedt (Google)" Subject: [PATCH 2/3] libtracefs: Remove double free attempt of new_event in tracefs_synth_echo_cmd() Date: Thu, 18 Aug 2022 22:03:48 -0400 Message-Id: <20220819020349.747429-3-rostedt@goodmis.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220819020349.747429-1-rostedt@goodmis.org> References: <20220819020349.747429-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (Google)" The "out_free" path frees the synth->dyn_event if new_event is set, but it is also freed in the success path (that falls through into the out_free path). The only reason this did not crash is because both cases set the "synth->dyn_event" to NULL, where the second attempt to free it does nothing. But this is still a bug. Fixes: d7c5dbb7a231e ("libtracefs: Use the internal dynamic events API when creating synthetic events") Signed-off-by: Steven Rostedt (Google) --- src/tracefs-hist.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index 6f7d657bd404..302b9a75e6ee 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -2311,11 +2311,6 @@ int tracefs_synth_echo_cmd(struct trace_seq *seq, hist, path, synth->end_event->system, synth->end_event->name); - if (new_event) { - tracefs_dynevent_free(synth->dyn_event); - synth->dyn_event = NULL; - } - ret = 0; out_free: free(hist); From patchwork Fri Aug 19 02:03:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 12948236 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31F8EC00140 for ; Fri, 19 Aug 2022 02:03:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242524AbiHSCDm (ORCPT ); Thu, 18 Aug 2022 22:03:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240319AbiHSCDk (ORCPT ); Thu, 18 Aug 2022 22:03:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A402D5727B for ; Thu, 18 Aug 2022 19:03:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3EF5C6142D for ; Fri, 19 Aug 2022 02:03:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6793C433D6; Fri, 19 Aug 2022 02:03:38 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oOrMU-0038Ru-0C; Thu, 18 Aug 2022 22:03:50 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: "Steven Rostedt (Google)" Subject: [PATCH 3/3] libtracefs sqlhist: Allow pointers to match longs Date: Thu, 18 Aug 2022 22:03:49 -0400 Message-Id: <20220819020349.747429-4-rostedt@goodmis.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220819020349.747429-1-rostedt@goodmis.org> References: <20220819020349.747429-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (Google)" Currently, if a field that is a long tries to match a field that is a pointer, tracefs_sqlhist() will fail with incompatible fields. But the kernel will still allow it to match, do not fail here. Signed-off-by: Steven Rostedt (Google) --- src/tracefs-hist.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index 302b9a75e6ee..14988d8dc185 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -796,6 +796,7 @@ static bool verify_event_fields(struct tep_event *start_event, { const struct tep_format_field *start_field; const struct tep_format_field *end_field; + int start_flags, end_flags; if (!trace_verify_event_field(start_event, start_field_name, &start_field)) @@ -806,7 +807,11 @@ static bool verify_event_fields(struct tep_event *start_event, &end_field)) return false; - if (start_field->flags != end_field->flags || + /* A pointer can still match a long */ + start_flags = start_field->flags & ~TEP_FIELD_IS_POINTER; + end_flags = end_field->flags & ~TEP_FIELD_IS_POINTER; + + if (start_flags != end_flags || start_field->size != end_field->size) { errno = EBADE; return false;