Blame SOURCES/rhbz2039207.patch

045c8b
commit 5abded54b
045c8b
Author: Stan Cox <scox@redhat.com>
045c8b
Date:   Fri Jan 28 15:28:27 2022 -0500
045c8b
045c8b
    Attempt to access string in userspace if kernel access fails
045c8b
    
045c8b
    Add kernel_or_user_string_quoted(_utf16 _utf32) tapsets to handle
045c8b
    situations where a kernelspace access was assumed but string is in
045c8b
    userspace.
045c8b
045c8b
diff --git a/tapset/linux/conversions.stp b/tapset/linux/conversions.stp
045c8b
index 82f535f6c..d3d3a0b5a 100644
045c8b
--- a/tapset/linux/conversions.stp
045c8b
+++ b/tapset/linux/conversions.stp
045c8b
@@ -72,6 +72,17 @@ function kernel_string_quoted:string (addr:long)
045c8b
 		    (unsigned long)(uintptr_t)STAP_ARG_addr);
045c8b
 %}
045c8b
 
045c8b
+/**
045c8b
+ * sfunction kernel_or_user_string_quoted - Retrieves and quotes string from kernel or user memory
045c8b
+ *
045c8b
+ * @addr: the kernel or user memory address to retrieve the string from
045c8b
+ *
045c8b
+ * Similar to kernel_string_quoted except user memory is a fallback method
045c8b
+ */
045c8b
+function kernel_or_user_string_quoted:string (addr:long) {
045c8b
+  try { return string_quoted(kernel_string(addr)) } catch { return string_quoted(user_string(addr)) }
045c8b
+}
045c8b
+
045c8b
 /**
045c8b
  * sfunction kernel_string_n - Retrieves string of given length from kernel memory
045c8b
  * @addr: The kernel address to retrieve the string from
045c8b
@@ -160,6 +171,16 @@ function kernel_string_quoted_utf32:string (addr:long) {
045c8b
   try { return string_quoted(kernel_string_utf32(addr)) } catch { return sprintf("0x%x", addr) }
045c8b
 }
045c8b
 
045c8b
+/**
045c8b
+ * sfunction kernel_or_user_string_quoted_utf32 - Retrieves and quotes UTF-32 string from kernel or user memory
045c8b
+ *
045c8b
+ * @addr: the kernel or user memory address to retrieve the string from
045c8b
+ *
045c8b
+ * Similar to kernel_string_quoted_utf32 except user memory is a fallback method
045c8b
+ */
045c8b
+function kernel_or_user_string_quoted_utf32:string (addr:long) {
045c8b
+ try { return string_quoted(kernel_string_utf32(addr)) } catch { return string_quoted(user_string_utf32(addr)) }
045c8b
+}
045c8b
 
045c8b
 /**
045c8b
  * sfunction kernel_string_utf16 - Retrieves UTF-16 string from kernel memory
045c8b
@@ -242,6 +263,17 @@ function kernel_string_quoted_utf16:string (addr:long) {
045c8b
   try { return string_quoted(kernel_string_utf16(addr)) } catch { return sprintf("0x%x", addr) }
045c8b
 }
045c8b
 
045c8b
+/**
045c8b
+ * sfunction kernel_or_user_string_quoted_utf16 - Retrieves and quotes UTF-16 string from kernel or user memory
045c8b
+ *
045c8b
+ * @addr: the kernel or user memory address to retrieve the string from
045c8b
+ *
045c8b
+ * Similar to kernel_string_quoted_utf16 except uses user memory as a fallback method
045c8b
+ */
045c8b
+function kernel_or_user_string_quoted_utf16:string (addr:long) {
045c8b
+ try { return string_quoted(kernel_string_utf16(addr)) } catch { return string_quoted(user_string_utf16(addr)) }
045c8b
+}
045c8b
+
045c8b
 
045c8b
 /**
045c8b
  * sfunction kernel_long - Retrieves a long value stored in kernel memory
045c8b
diff --git a/tapsets.cxx b/tapsets.cxx
045c8b
index 8fc5146e2..8b8f1cad5 100644
045c8b
--- a/tapsets.cxx
045c8b
+++ b/tapsets.cxx
045c8b
@@ -3757,7 +3757,7 @@ dwarf_pretty_print::print_chars (Dwarf_Die* start_type, target_symbol* e,
045c8b
       return false;
045c8b
     }
045c8b
 
045c8b
-  string function = userspace_p ? "user_string_quoted" : "kernel_string_quoted";
045c8b
+  string function = userspace_p ? "user_string_quoted" : "kernel_or_user_string_quoted";
045c8b
   Dwarf_Word size = (Dwarf_Word) -1;
045c8b
   dwarf_formudata (dwarf_attr_integrate (&type, DW_AT_byte_size, &attr), &size);
045c8b
   switch (size)