Fix rhbz2039207 - Attempt userspace string access if kernel access fails

This commit is contained in:
Martin Cermak 2022-02-03 08:40:17 +00:00
parent ddbfcee98b
commit d6aaf7cbe2
2 changed files with 86 additions and 1 deletions

80
rhbz2039207.patch Normal file
View File

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

View File

@ -118,7 +118,7 @@ m stapdev stapdev
Name: systemtap
Version: 4.6
Release: 10%{?release_override}%{?dist}
Release: 11%{?release_override}%{?dist}
# for version, see also configure.ac
@ -160,6 +160,7 @@ Patch3: sdt-asm-glibc.patch
Patch4: rhbz2041526.patch
Patch5: rhbz2027683.patch
Patch6: rhbz2047256.patch
Patch7: rhbz2039207.patch
# Build*
BuildRequires: make
@ -587,6 +588,7 @@ systemtap-runtime-virthost machine to execute systemtap scripts.
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%build
@ -1283,6 +1285,9 @@ exit 0
# PRERELEASE
%changelog
* Wed Feb 2 2022 Stan Cox <scox@redhat.com> - 4.6-11
- rhbz2039207: Attempt userspace string access if kernel access fails
* Tue Feb 1 2022 Martin Cermak <mcermak@redhat.com> - 4.6-10
- rhbz2047256: [ppc64le] Assertion `index >= 0' failed