-
Notifications
You must be signed in to change notification settings - Fork 35
Set ptracer permissions for IPC handle creation #1018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,11 @@ | |
*/ | ||
|
||
#include <arpa/inet.h> | ||
#include <errno.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/prctl.h> | ||
#include <sys/socket.h> | ||
#include <unistd.h> | ||
|
||
|
@@ -69,6 +71,23 @@ int main(int argc, char *argv[]) { | |
|
||
int port = atoi(argv[1]); | ||
|
||
// The prctl() function with PR_SET_PTRACER is used here to allow parent process and its children | ||
// to ptrace the current process. This is necessary because UMF's memory providers on Linux (except CUDA) | ||
// use the pidfd_getfd(2) system call to duplicate another process's file descriptor, which is | ||
// governed by ptrace permissions. By default on Ubuntu /proc/sys/kernel/yama/ptrace_scope is | ||
// set to 1 ("restricted ptrace"), which prevents pidfd_getfd from working unless ptrace_scope | ||
// is set to 0. | ||
// To overcome this limitation without requiring users to change the ptrace_scope | ||
// setting (which requires root privileges), we use prctl() to allow the consumer process | ||
// to copy producer's file descriptor, even when ptrace_scope is set to 1. | ||
ret = prctl(PR_SET_PTRACER, getppid()); | ||
if (ret == -1) { | ||
printf("prctl() call failed with errno %d (%s). This may indicate that " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perror? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
"PR_SET_PTRACER" | ||
" is not supported on this system.\n", | ||
errno, strerror(errno)); | ||
} | ||
|
||
umf_memory_provider_handle_t OS_memory_provider = NULL; | ||
umf_os_memory_provider_params_handle_t os_params = NULL; | ||
enum umf_result_t umf_result; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,11 @@ | |
*/ | ||
lukaszstolarczuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#include <arpa/inet.h> | ||
#include <errno.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/prctl.h> | ||
#include <sys/socket.h> | ||
#include <unistd.h> | ||
|
||
|
@@ -336,6 +338,14 @@ int run_producer(int port, umf_memory_pool_ops_t *pool_ops, void *pool_params, | |
int producer_socket = -1; | ||
char consumer_message[MSG_SIZE]; | ||
|
||
ret = prctl(PR_SET_PTRACER, getppid()); | ||
if (ret == -1) { | ||
printf("prctl() call failed with errno %d (%s). This may indicate that " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perror There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
"PR_SET_PTRACER" | ||
" is not supported on this system.\n", | ||
errno, strerror(errno)); | ||
} | ||
|
||
// create OS memory provider | ||
umf_result = | ||
umfMemoryProviderCreate(provider_ops, provider_params, &provider); | ||
|
Uh oh!
There was an error while loading. Please reload this page.