Skip to content

Instantly share code, notes, and snippets.

@agentzh

agentzh/a.patch Secret

Created May 16, 2023 19:27
Show Gist options
  • Save agentzh/b712c10e859ef5cc08b8de48d3ab85c5 to your computer and use it in GitHub Desktop.
Save agentzh/b712c10e859ef5cc08b8de48d3ab85c5 to your computer and use it in GitHub Desktop.
commit 1bd7c8a2c4d02617f90c4523ca3450fb4645dd9b
Author: Yichun Zhang (agentzh) <yichun@openresty.com>
Date: Tue May 16 19:12:57 2023 +0000
PR30408: fixed excessive read faults when reading userland memory from within perf event/kprobes handlers
The user_addr_max() macro is gone since kernel 5.18, which broke stap's
userland reading routines.
diff --git a/runtime/linux/addr-map.c b/runtime/linux/addr-map.c
index 1cca14220..658147776 100644
--- a/runtime/linux/addr-map.c
+++ b/runtime/linux/addr-map.c
@@ -57,12 +57,20 @@ lookup_bad_addr_user(const int type, const unsigned long addr, const size_t size
if (size == 0 || ULONG_MAX - addr < size - 1
|| !stp_access_ok(type, (void *)addr, size))
return 1;
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(5,18,0)
+ /* NB access_ok() checks TASK_SIZE_MAX (used to be user_addr_max()) on
+ * all architectures since 5.18 */
+ if (size == 0 || ULONG_MAX - addr < size - 1
+ || !stp_access_ok(type, (void *)addr, size))
+ return 1;
#else
if (size == 0 || ULONG_MAX - addr < size - 1
|| (in_task() && !stp_access_ok(type, (void *)addr, size))
|| (!in_task()
#if defined(user_addr_max)
&& ((user_addr_max() - size) < addr)
+#elif defined(TASK_SIZE_MAX)
+ && ((TASK_SIZE_MAX - size) < addr)
#endif
))
return 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment