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=1792774068; b=wTPM+LH4ux+0YZtWxKy4fdS1M85CChxCc3VK/9HmMyFPJTVkChrsiS94/iMz9n/2/zys WgRxygIJ776H1QL5zzUyAqP4MKLe8RWAQzdVxG191BBEE4+02lCoWd8wD0b9dN5IFVnRW NOouuQXnf9qxcpEsoyY7lL8wXT9fuKOObrO8+l9c7Q/mIYpzwDhXMX1z8ciEhJWO5MEc3 CV1ERiMPkku4fiEkKyGMcePbH/FkhCwIpV/gYeWI57w6vcMOkybrnOfqNtlCuvmhTAU7G SwWjdeNxVo//ZBYvUCMSJ6dm/WUM31CyhfTbZe7BA/no+cXbyGO1zMopZm2dMpwcm+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792774068; 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=WkiarrDc+iG75qK2XfNJK3I8g2GU7k2VJdQQ0w5BkCE=; b=l8z64VsFeyn69CnfNruHoP8eLRI/kr8UlxjBdTBhPgVsNAHFUyQH9Z5XWkdNzGsbPGin g5jVP4/68XhKJ00n7yN/bTvl929SD8Mz+Ud5JSaPStVu2kSKJL64A3weCQeJuSscj2rgG HD+3apmF0sNB7kt1LXDCYRSwp0WUuIYQMiSaAsMX64mr3NCpac24nt14i57WirbjkDfoO 4R0k25RjgvxL8wTG9OjKUDupu/uWGkTRYM7qloTB7renRolvVbyL5nlFZBwo8r/JRWPg6 WLLk+0a2LHCXuU4KCf4ZUObl8Erg2Jipfjk1Pthp6cr2Dt3yFBXHJuOn01QyPlZEIkA== 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=bfB3iZ8W; 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 87015606A328; Fri, 23 Oct 2026 16:47:48 +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=bfB3iZ8W Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3E721F01828; Fri, 23 Oct 2026 16:47:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792774068; bh=WkiarrDc+iG75qK2XfNJK3I8g2GU7k2VJdQQ0w5BkCE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bfB3iZ8WKpsX6QKytaMpmAYryshWQmpzTRHRCOOAC4FDdaOeQp6ZNqdQ7NwBb8h6n DAR0fbIgMHFRp0W2WTUBP6IfYgnQDTqx5E0NT7/AjJIZRGvk0HUAgLHSJmfOyPmIdH pt6Xj6rXACV3GZm3IFePSC9IAKn3U2sekWL//CVQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Donggeun Yoo , Steven Rostedt Subject: [PATCH 6.18 111/193] tracing: Fix the shift out of bounds in the log2 histogram modifier Date: Fri, 23 Oct 2026 18:36:28 +0200 Message-ID: <20261023163716.834783199@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261023163714.201276352@linuxfoundation.org> References: <20261023163714.201276352@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 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Donggeun Yoo commit 647c2f97fcb94bc642cefe6db004999974563f06 upstream. The .log2 key modifier files a value under its base-2 order: # echo 'hist:keys=bytes_req.log2' > events/kmem/kmalloc/trigger hist_field_log2() computes that as ilog2(roundup_pow_of_two(val)). The out-of-line form of roundup_pow_of_two() is return 1UL << fls_long(n - 1); which shifts by 64 on a 64-bit kernel both when n is 0, where n - 1 wraps to ULONG_MAX, and when n is above 2^63. Both are ordinary keys, because the field fetch hands every value over as a u64: a syscall argument of 0 reaches the first, and one above 2^63 reaches the second. Keying sys_enter_lseek on offset.log2 and passing 0, 1, 2, 3, 1000, 2^63+1 and U64_MAX gives { offset: ~ 2^1 } hitcount: 1 { offset: ~ 2^10 } hitcount: 1 { offset: ~ 2^2 } hitcount: 1 { offset: ~ 2^0 } hitcount: 4 Keys above 2^63 land in the lowest bucket. With CONFIG_UBSAN_SHIFT=y the shift is also reported: UBSAN: shift-out-of-bounds in include/linux/log2.h:57:13 shift exponent 64 is too large for 64-bit type 'long unsigned int' __ubsan_handle_shift_out_of_bounds.cold+0xdd/0x1cb hist_fn_call.cold+0x8b/0xd9 event_hist_trigger+0x1cc/0x790 ftrace_syscall_enter+0x197/0x360 do_syscall_64+0x402/0x4b0 Use order_base_2(), which is ilog2(n - 1) + 1 for n > 1 and 0 below that. It returns what the old expression returned on every input the old one was defined for. Where it was not, 0 stays in bucket 0, which is where x86_64 had been putting it, and the keys above 2^63 move into bucket 64. Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260916002735.808520-1-donggeunyoo.kernel@gmail.com Fixes: 4b94f5b7b4a5 ("tracing: Add hist trigger 'log2' modifier") Signed-off-by: Donggeun Yoo Assisted-by: Claude:claude-fable-5 Signed-off-by: Steven Rostedt Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_events_hist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -284,7 +284,7 @@ static u64 hist_field_log2(struct hist_f u64 val = hist_fn_call(operand, elt, buffer, rbe, event); - return (u64) ilog2(roundup_pow_of_two(val)); + return order_base_2(val); } static u64 hist_field_bucket(struct hist_field *hist_field,