From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793207165; b=agOw1SPErw5O0Esq3cOUz8etU+wT/cQSNhxutbhIsiEipT2EKW5VfGRc5jZ8lJoDCy4L BAghD3VPPWY+EIpcdEe7GUTmo23u3QPY54ImayZzjonVVAGn1yK8VQSHqE+/US4e8+elZ by/v6KUM0Sl78+MdAtvnn3Ww7eTLIOwN9Syt3BFix7YODz7X9sBfD9hK6rvnYUb5POpvp +BVwWy03tq6VBJHza2ARKwrn6SHArh8xO60ppCAqGjvVDZcG3u693p86zD2QdB5I92zwD SqL40H2wrekSvhuPpWvHXxXBUiV89my5+vW/yulGY1Tw2Q61XoqZyInbxRZXHXyHaLA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793207165; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=bfU3IXUNXOhjRaAj7gO3yM36sZbFWIC68bNdOyMthqQ=; b=NHv8sGJr+pibEL+9BrYWrHVD77KysvqNw5KiFySG7i0WTDulWwgWpwaFhDltOtJM24Lh OMc/3GAfKRt4gCb5VqEnuazvewK0ISirPMlP0x1Y7/3hHzykAZ9+IPJ3hgz4vI/FDb4oB cUvGWFn/eO6DCWkJ5HE3XRllVzwTMQIjzmR37G5Tuf21sB/Ht8t+VW+4DHPFGtNjtkmfY 9irh5vu/5/0fIJW7vXJoVRK3XbFbi2uX+ykIqn04nfULEzh38kzvsxmt61lFqi8raXCAJ s6SbckSvhckXDanjo6JUHk5p2ub8xmgEsxPh8CuyOm6/2pt5Rl6mnJurjkFc7gAAR6w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=cYdLU+74; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DE9A606A31C; Wed, 28 Oct 2026 17:06:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=cYdLU+74 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26EB41F01828; Wed, 28 Oct 2026 17:06:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793207164; bh=bfU3IXUNXOhjRaAj7gO3yM36sZbFWIC68bNdOyMthqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cYdLU+7454NQcg0B4qSbHBn3r43VsenW+l9/x+O4kzWYztunVPVItsiC5G3WGA9IB GMaVLgQPC5MA+/+J0dVA9Kjl/l7M6YzKfRt0/hM3yXDmJ7SB1MIxfi+Bhzg7atL+QI VsWh7ICP737kDO4xKZaF/U/xSjKqscbZ50fs/bO4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Masami Hiramatsu (Google)" , "JongHyuk Kim(MalHyuk)" , Kyle Zeng , Steven Rostedt Subject: [PATCH 7.2 10/88] tracing: Reject incomplete event filter expressions Date: Wed, 28 Oct 2026 17:59:18 +0100 Message-ID: <20261028165942.356429813@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028165942.107695352@linuxfoundation.org> References: <20261028165942.107695352@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kyle Zeng commit 1fdc4164e488916402badddbb1f51e9380dabb91 upstream. A non-empty expression normally finishes in predicate_parse()'s inner loop, which resolves the pending logical operators before jumping to finalization. If the input ends after an operator, possibly followed by unary '!' tokens, the outer loop instead falls through with unresolved operator state. For example, "common_pid == 1 || common_pid == 2 &&" leaves prog[0].target equal to -1. The second pass then reads prog[-1] before the forward-jump check can reject it. Depending on adjacent slab contents, it can also copy an out-of-bounds word into a branch target that passes the forward-only check. A self-targeted perf tracepoint counting event can reach this path through PERF_EVENT_IOC_SET_FILTER. Reject the outer-loop fallthrough when a predicate has already been parsed. This ensures that non-empty expressions only reach finalization after the inner loop has resolved their operators. Keep the existing no-filter error for input that has no predicates. Add a regression test for trailing logical operators and unary negations. Fixes: 80765597bc587 ("tracing: Rewrite filter logic to be simpler and faster") Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261023174620.91969-1-kylebot@openai.com Assisted-by: Codex:gpt-6-astra Acked-by: Masami Hiramatsu (Google) Tested-by: JongHyuk Kim(MalHyuk) Signed-off-by: Kyle Zeng Signed-off-by: Steven Rostedt Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_events_filter.c | 6 ++ tools/testing/selftests/ftrace/test.d/filter/event-filter-incomplete.tc | 24 ++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tools/testing/selftests/ftrace/test.d/filter/event-filter-incomplete.tc --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -595,6 +595,12 @@ predicate_parse(const char *str, int nr_ top--; /* #12 */ } } + /* Only the inner loop can complete a non-empty expression. */ + if (N) { + ret = -EINVAL; + parse_error(pe, FILT_ERR_INVALID_FILTER, ptr - str); + goto out_free; + } out: if (top != op_stack) { /* Too many '(' */ --- /dev/null +++ b/tools/testing/selftests/ftrace/test.d/filter/event-filter-incomplete.tc @@ -0,0 +1,24 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# description: event filter - reject incomplete logical expressions +# requires: events/sched/sched_switch/filter +# flags: instance + +filter=events/sched/sched_switch/filter + +for base in \ + 'common_pid == 1' \ + 'common_pid == 1 || common_pid == 2' \ + 'common_pid == 1 && common_pid == 2' \ + '!(common_pid == 1 || common_pid == 2)' +do + printf '%s' "$base" > "$filter" + for tail in '&&' '||' '&& !' '|| !' '&& !! ' '|| !! '; do + if printf '%s' "$base $tail" > "$filter" 2>/dev/null; then + echo "Accepted incomplete filter: $base $tail" + exit_fail + fi + done +done + +echo 0 > "$filter"