mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] profiling: fix sampling step on 64-bit big-endian systems
@ 2026-10-20 10:12 Avi Weiss
  0 siblings, 0 replies; only message in thread
From: Avi Weiss @ 2026-10-20 10:12 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Avi Weiss

read_profile() stores the sampling step in an unsigned long
but copies only four bytes to userspace. On 64-bit
big-endian systems (not common obviously), this copies
the upper 32 bits and discards teh rest, causing
/proc/profile to report zero for normal shift values.

Cast to unsigned int so we get the correct 4 bytes, while
keeping the shift calculation in unsigned long.

A small C reproducer under qemu-s390x reproduced this and
proved the fix works for prof_shift=2.

Fixes: 2d186afd04d6 ("profiling: fix shift-out-of-bounds bugs")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---

 kernel/profile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/profile.c b/kernel/profile.c
index 1fcf1adcf4eb0..e7defa90a34c9 100644
--- a/kernel/profile.c
+++ b/kernel/profile.c
@@ -156,7 +156,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 	unsigned long p = *ppos;
 	ssize_t read;
 	char *pnt;
-	unsigned long sample_step = 1UL << prof_shift;
+	unsigned int sample_step = (unsigned int)(1UL << prof_shift);
 
 	if (p >= (prof_len+1)*sizeof(unsigned int))
 		return 0;
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-20 10:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-20 10:12 [PATCH] profiling: fix sampling step on 64-bit big-endian systems Avi Weiss

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®