Patch "s390/stacktrace: Improve detection of invalid instruction pointers" has been added to the 6.9-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    s390/stacktrace: Improve detection of invalid instruction pointers

to the 6.9-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     s390-stacktrace-improve-detection-of-invalid-instruc.patch
and it can be found in the queue-6.9 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 5659aeb1e9aba0c0543f9ff3a9e16d58cf27deaa
Author: Heiko Carstens <hca@xxxxxxxxxxxxx>
Date:   Mon Apr 29 14:28:46 2024 +0200

    s390/stacktrace: Improve detection of invalid instruction pointers
    
    [ Upstream commit cd58109283944ea8bdcd0a8211a86cbd2450716a ]
    
    Add basic checks to identify invalid instruction pointers when walking
    stack frames:
    
    Instruction pointers must
    
    - have even addresses
    - be larger than mmap_min_addr
    - lower than the asce_limit of the process
    
    Alternatively it would also be possible to walk page tables similar to fast
    GUP and verify that the mapping of the corresponding page is executable,
    however that seems to be overkill.
    
    Fixes: aa44433ac4ee ("s390: add USER_STACKTRACE support")
    Reviewed-by: Jens Remus <jremus@xxxxxxxxxxxxx>
    Signed-off-by: Heiko Carstens <hca@xxxxxxxxxxxxx>
    Signed-off-by: Alexander Gordeev <agordeev@xxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/arch/s390/kernel/stacktrace.c b/arch/s390/kernel/stacktrace.c
index 1c9e3b7739a22..b4485b0c7f06b 100644
--- a/arch/s390/kernel/stacktrace.c
+++ b/arch/s390/kernel/stacktrace.c
@@ -77,6 +77,21 @@ static inline bool store_ip(stack_trace_consume_fn consume_entry, void *cookie,
 	return consume_entry(cookie, ip);
 }
 
+static inline bool ip_invalid(unsigned long ip)
+{
+	/*
+	 * Perform some basic checks if an instruction address taken
+	 * from unreliable source is invalid.
+	 */
+	if (ip & 1)
+		return true;
+	if (ip < mmap_min_addr)
+		return true;
+	if (ip >= current->mm->context.asce_limit)
+		return true;
+	return false;
+}
+
 void arch_stack_walk_user_common(stack_trace_consume_fn consume_entry, void *cookie,
 				 struct perf_callchain_entry_ctx *entry,
 				 const struct pt_regs *regs, bool perf)
@@ -87,6 +102,8 @@ void arch_stack_walk_user_common(stack_trace_consume_fn consume_entry, void *coo
 
 	if (is_compat_task())
 		return;
+	if (!current->mm)
+		return;
 	ip = instruction_pointer(regs);
 	if (!store_ip(consume_entry, cookie, entry, perf, ip))
 		return;
@@ -101,15 +118,16 @@ void arch_stack_walk_user_common(stack_trace_consume_fn consume_entry, void *coo
 		sf = (void __user *)sp;
 		if (__get_user(ip, &sf->gprs[8]))
 			break;
-		if (ip & 0x1) {
+		if (ip_invalid(ip)) {
 			/*
 			 * If the instruction address is invalid, and this
 			 * is the first stack frame, assume r14 has not
 			 * been written to the stack yet. Otherwise exit.
 			 */
-			if (first && !(regs->gprs[14] & 0x1))
-				ip = regs->gprs[14];
-			else
+			if (!first)
+				break;
+			ip = regs->gprs[14];
+			if (ip_invalid(ip))
 				break;
 		}
 		if (!store_ip(consume_entry, cookie, entry, perf, ip))




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux