From nobody Thu Dec 18 11:09:22 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2D145BE49; Thu, 5 Dec 2024 02:41:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733366471; cv=none; b=ebpUjTkeUsmXyuzJmqtqN427lzEtedpKXlcFwVLTMu00CBHWHE30YKridc2E1ZSQKf4Tb9ClKa3VYtUGOms1D5DtED7tcm7m2olNJevNtvv5jQB5UvzNgqJ4yvpYtg4OB7Wu09YUGN/QDIqq2YSWFvVt4kbG7lm67XLf3gvvdmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733366471; c=relaxed/simple; bh=q0yv3RMHE7v9mV9K/pUaQrLNjAvfc2BMhOSEGrvlUXE=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Gr5nd1cKfjVgkIYCtu3ARnei/vDNbhlifonMO9zQ8DN+zn2hlPagjcjapXKCDFI9/tmezAHdk+GQ+GQlPc2c5od3DI+7lXIELG5IHRQmFEWRncWGb0bC7vLtw59TGDCt75JdAI4f2OYf6jmY13lv66ig06cNOX6z4Nyu2kj2ue8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17D21C4CED6; Thu, 5 Dec 2024 02:41:11 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tJ1nn-000000022en-2Nt1; Wed, 04 Dec 2024 21:41:15 -0500 Message-ID: <20241205024115.419087387@goodmis.org> User-Agent: quilt/0.68 Date: Wed, 04 Dec 2024 21:35:53 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Kuan-Wei Chiu Subject: [for-linus][PATCH 1/2] tracing: Fix cmp_entries_dup() to respect sort() comparison rules References: <20241205023552.609451828@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kuan-Wei Chiu The cmp_entries_dup() function used as the comparator for sort() violated the symmetry and transitivity properties required by the sorting algorithm. Specifically, it returned 1 whenever memcmp() was non-zero, which broke the following expectations: * Symmetry: If x < y, then y > x. * Transitivity: If x < y and y < z, then x < z. These violations could lead to incorrect sorting and failure to correctly identify duplicate elements. Fix the issue by directly returning the result of memcmp(), which adheres to the required comparison properties. Cc: stable@vger.kernel.org Fixes: 08d43a5fa063 ("tracing: Add lock-free tracing_map") Link: https://lore.kernel.org/20241203202228.1274403-1-visitorckw@gmail.com Signed-off-by: Kuan-Wei Chiu Signed-off-by: Steven Rostedt (Google) --- kernel/trace/tracing_map.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/kernel/trace/tracing_map.c b/kernel/trace/tracing_map.c index 3a56e7c8aa4f..1921ade45be3 100644 --- a/kernel/trace/tracing_map.c +++ b/kernel/trace/tracing_map.c @@ -845,15 +845,11 @@ int tracing_map_init(struct tracing_map *map) static int cmp_entries_dup(const void *A, const void *B) { const struct tracing_map_sort_entry *a, *b; - int ret =3D 0; =20 a =3D *(const struct tracing_map_sort_entry **)A; b =3D *(const struct tracing_map_sort_entry **)B; =20 - if (memcmp(a->key, b->key, a->elt->map->key_size)) - ret =3D 1; - - return ret; + return memcmp(a->key, b->key, a->elt->map->key_size); } =20 static int cmp_entries_sum(const void *A, const void *B) --=20 2.45.2