From 3ecd4ce3548910033ed89e327be7615b03209583 Mon Sep 17 00:00:00 2001 From: Tad Date: Sat, 25 Nov 2023 17:30:26 -0500 Subject: [PATCH] Gracefully handle pkey unavailable All other pkey syscalls already handle errors gracefully. But in case of a seccomp filter that blocks pkey but doesn't terminate, this change is necessary to continue to function. Signed-off-by: Tad --- memory.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/memory.c b/memory.c index 5434060..1ddedf7 100644 --- a/memory.c +++ b/memory.c @@ -61,7 +61,12 @@ bool memory_unmap(void *ptr, size_t size) { static bool memory_protect_prot(void *ptr, size_t size, int prot, UNUSED int pkey) { #ifdef USE_PKEY - bool ret = pkey_mprotect(ptr, size, prot, pkey); + bool ret; + if (pkey > 0) { + ret = pkey_mprotect(ptr, size, prot, pkey); + } else { + ret = mprotect(ptr, size, prot); + } #else bool ret = mprotect(ptr, size, prot); #endif