From nobody Fri Dec 19 12:21:33 2025 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 52FA8CA0FE6 for ; Fri, 1 Sep 2023 15:11:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350123AbjIAPMA (ORCPT ); Fri, 1 Sep 2023 11:12:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234542AbjIAPL7 (ORCPT ); Fri, 1 Sep 2023 11:11:59 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8869010CF for ; Fri, 1 Sep 2023 08:11:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693581065; 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=sDuTMVC2fItyk8TQyqI4vfFk/aqpQbO6zoYrXybc/Ys=; b=ffnyt1vYNVDV9dLCtu9N+0BxoSLrfoIolcgiKvh9K3KjobugHt6czMgQPK+eAZCJ93Ohar iYDMYrmod5HpINIMXGVQWkWCwSzB1SS/j1e4DDfk+CGCL9t93onUUn0P96xM5pq7du34+z 82NIOeQG798l8d28Os4wJXZ/q4u3QgI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-78-GMysWmSFMWOrbG21E5dJXg-1; Fri, 01 Sep 2023 11:11:02 -0400 X-MC-Unique: GMysWmSFMWOrbG21E5dJXg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E1C76923000; Fri, 1 Sep 2023 15:11:01 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.39.193.168]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8D960205B0BE; Fri, 1 Sep 2023 15:11:00 +0000 (UTC) From: Valentin Schneider To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Steven Rostedt , Josh Poimboeuf , Masami Hiramatsu Subject: [PATCH 1/4] tracing/filters: Fix error-handling of cpulist parsing buffer Date: Fri, 1 Sep 2023 17:10:36 +0200 Message-Id: <20230901151039.125186-2-vschneid@redhat.com> In-Reply-To: <20230901151039.125186-1-vschneid@redhat.com> References: <20230901151039.125186-1-vschneid@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" parse_pred() allocates a string buffer to parse the user-provided cpulist, but doesn't check the allocation result nor does it free the buffer once it is no longer needed. Add an allocation check, and free the buffer as soon as it is no longer needed. Reported-by: Steven Rostedt Reported-by: Josh Poimboeuf Signed-off-by: Valentin Schneider --- kernel/trace/trace_events_filter.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events= _filter.c index 3a529214a21b7..c06e1d596f4b9 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -1744,17 +1744,23 @@ static int parse_pred(const char *str, void *data, =20 /* Copy the cpulist between { and } */ tmp =3D kmalloc((i - maskstart) + 1, GFP_KERNEL); - strscpy(tmp, str + maskstart, (i - maskstart) + 1); + if (!tmp) + goto err_mem; =20 + strscpy(tmp, str + maskstart, (i - maskstart) + 1); pred->mask =3D kzalloc(cpumask_size(), GFP_KERNEL); - if (!pred->mask) + if (!pred->mask) { + kfree(tmp); goto err_mem; + } =20 /* Now parse it */ if (cpulist_parse(tmp, pred->mask)) { + kfree(tmp); parse_error(pe, FILT_ERR_INVALID_CPULIST, pos + i); goto err_free; } + kfree(tmp); =20 /* Move along */ i++; --=20 2.31.1 From nobody Fri Dec 19 12:21:33 2025 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 0243FCA0FE4 for ; Fri, 1 Sep 2023 15:12:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350134AbjIAPMk (ORCPT ); Fri, 1 Sep 2023 11:12:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350114AbjIAPMi (ORCPT ); Fri, 1 Sep 2023 11:12:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFC8010F0 for ; Fri, 1 Sep 2023 08:11:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693581067; 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=0WkSoySUBrZdyHF12ktpxBNhTKhwA2sIbutQLbHd7Fo=; b=WfsFhDZE0O3OLaivDFmHTY45qcafG8+zXe5fg95ivsRW4Tydor832QWWQ1PmDMrR5wyhUe SVeQojb1wO0HmxfQgtnCa0yHgMgcEKlLSvocTP0ywzzUJV0A2iisDTgZLOZzIk4kVCdNsx J27CmNz3eVeVmB6LrNyx7TQ9DDG0sGA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-128-aqVpX8ZPPA6Dv3QM9t5dSw-1; Fri, 01 Sep 2023 11:11:03 -0400 X-MC-Unique: aqVpX8ZPPA6Dv3QM9t5dSw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 29CC71817904; Fri, 1 Sep 2023 15:11:03 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.39.193.168]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2B0432012F37; Fri, 1 Sep 2023 15:11:02 +0000 (UTC) From: Valentin Schneider To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Steven Rostedt , Masami Hiramatsu Subject: [PATCH 2/4] tracing/filters: Fix double-free of struct filter_pred.mask Date: Fri, 1 Sep 2023 17:10:37 +0200 Message-Id: <20230901151039.125186-3-vschneid@redhat.com> In-Reply-To: <20230901151039.125186-1-vschneid@redhat.com> References: <20230901151039.125186-1-vschneid@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When a cpulist filter is found to contain a single CPU, that CPU is saved as a scalar and the backing cpumask storage is freed. Also NULL the mask to avoid a double-free once we get down to free_predicate(). Reported-by: Steven Rostedt Signed-off-by: Valentin Schneider --- kernel/trace/trace_events_filter.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events= _filter.c index c06e1d596f4b9..eb331e8b00b61 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -1773,6 +1773,7 @@ static int parse_pred(const char *str, void *data, if (single) { pred->val =3D cpumask_first(pred->mask); kfree(pred->mask); + pred->mask =3D NULL; } =20 if (field->filter_type =3D=3D FILTER_CPUMASK) { --=20 2.31.1 From nobody Fri Dec 19 12:21:33 2025 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 324F4CA0FEA for ; Fri, 1 Sep 2023 15:12:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350128AbjIAPMB (ORCPT ); Fri, 1 Sep 2023 11:12:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350116AbjIAPMA (ORCPT ); Fri, 1 Sep 2023 11:12:00 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F8BC10E5 for ; Fri, 1 Sep 2023 08:11:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693581066; 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=Z8YZj7U283/XjuckA+i8EXyp3nE30BsVfSwsfevewvQ=; b=C12UG4TW22NoRFflQNWNAAAqed8lx5cxbhXKoCN0LppatpN5aqqkZXO3/lHh37N7d6eaHo VziHy6kSGS0uw/yfGbjFN05ddcbk05+gLOB3cdChJAMm1cJjFP7xZ56M6M3C4a+1T9TzAm du4gnjYZEKPjXZmMwEl0wD/zCxcGlb4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-652-3uY_UUUjNK2Mc0YnL1wBTQ-1; Fri, 01 Sep 2023 11:11:04 -0400 X-MC-Unique: 3uY_UUUjNK2Mc0YnL1wBTQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7B8B23C025BD; Fri, 1 Sep 2023 15:11:04 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.39.193.168]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 66C442012F37; Fri, 1 Sep 2023 15:11:03 +0000 (UTC) From: Valentin Schneider To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Steven Rostedt , Masami Hiramatsu Subject: [PATCH 3/4] tracing/filters: Change parse_pred() cpulist ternary into an if block Date: Fri, 1 Sep 2023 17:10:38 +0200 Message-Id: <20230901151039.125186-4-vschneid@redhat.com> In-Reply-To: <20230901151039.125186-1-vschneid@redhat.com> References: <20230901151039.125186-1-vschneid@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Review comments noted that an if block would be clearer than a ternary, so swap it out. No change in behaviour intended Signed-off-by: Valentin Schneider --- kernel/trace/trace_events_filter.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events= _filter.c index eb331e8b00b61..09b4733a2933d 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -1782,13 +1782,17 @@ static int parse_pred(const char *str, void *data, FILTER_PRED_FN_CPUMASK; } else if (field->filter_type =3D=3D FILTER_CPU) { if (single) { - pred->op =3D pred->op =3D=3D OP_BAND ? OP_EQ : pred->op; + if (pred->op =3D=3D OP_BAND) + pred->op =3D OP_EQ; + pred->fn_num =3D FILTER_PRED_FN_CPU; } else { pred->fn_num =3D FILTER_PRED_FN_CPU_CPUMASK; } } else if (single) { - pred->op =3D pred->op =3D=3D OP_BAND ? OP_EQ : pred->op; + if (pred->op =3D=3D OP_BAND) + pred->op =3D OP_EQ; + pred->fn_num =3D select_comparison_fn(pred->op, field->size, false); if (pred->op =3D=3D OP_NE) pred->not =3D 1; --=20 2.31.1 From nobody Fri Dec 19 12:21:33 2025 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 548D6CA0FE4 for ; Fri, 1 Sep 2023 15:12:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350145AbjIAPMr (ORCPT ); Fri, 1 Sep 2023 11:12:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350138AbjIAPMq (ORCPT ); Fri, 1 Sep 2023 11:12:46 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE37D10F1 for ; Fri, 1 Sep 2023 08:11:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693581068; 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=6plOE05wtAOE2J15C66Bubu1b7lLRziMMVbmgfVPQXg=; b=EyR5Ll/Q5L+WwF5q6WKE0LO78Da02H7WoDAVGqmbspYrWM76oWCqissaEan2gQsLzYBIv0 fgNK4tfCZHFwsxcQKmh0R5VeyDG1io+uJIT0+i1Tkry/RIGFhsW/thNo0GUa3V4Bm1UEQD UPML2/kbaekDEDufJIeEv5mnsU+SViY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-475-BSsqkJlyMnaqU7tQ4Cxcdw-1; Fri, 01 Sep 2023 11:11:06 -0400 X-MC-Unique: BSsqkJlyMnaqU7tQ4Cxcdw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7C716381CC0B; Fri, 1 Sep 2023 15:11:05 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.39.193.168]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE7262012F37; Fri, 1 Sep 2023 15:11:04 +0000 (UTC) From: Valentin Schneider To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Steven Rostedt , Masami Hiramatsu Subject: [PATCH 4/4] tracing/filters: Fix coding style issues Date: Fri, 1 Sep 2023 17:10:39 +0200 Message-Id: <20230901151039.125186-5-vschneid@redhat.com> In-Reply-To: <20230901151039.125186-1-vschneid@redhat.com> References: <20230901151039.125186-1-vschneid@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Recent commits have introduced some coding style issues, fix those up. Signed-off-by: Valentin Schneider --- kernel/trace/trace_events_filter.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events= _filter.c index 09b4733a2933d..33264e510d161 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -1360,7 +1360,7 @@ int filter_assign_type(const char *type) return FILTER_DYN_STRING; if (strstr(type, "cpumask_t")) return FILTER_CPUMASK; - } + } =20 if (strstr(type, "__rel_loc") && strstr(type, "char")) return FILTER_RDYN_STRING; @@ -1731,7 +1731,9 @@ static int parse_pred(const char *str, void *data, maskstart =3D i; =20 /* Walk the cpulist until closing } */ - for (; str[i] && str[i] !=3D '}'; i++); + for (; str[i] && str[i] !=3D '}'; i++) + ; + if (str[i] !=3D '}') { parse_error(pe, FILT_ERR_MISSING_BRACE_CLOSE, pos + i); goto err_free; --=20 2.31.1