|
8 | 8 | * of Tennessee Research Foundation. All rights
|
9 | 9 | * reserved.
|
10 | 10 | * Copyright (c) 2021 Google, Inc. All rights reserved.
|
| 11 | + * Copyright (c) 2022 IBM Corporation. All rights reserved. |
11 | 12 | * $COPYRIGHT$
|
12 | 13 | *
|
13 | 14 | * Additional copyrights may follow
|
|
20 | 21 | #include "opal/mca/smsc/base/base.h"
|
21 | 22 | #include "opal/mca/smsc/cma/smsc_cma_internal.h"
|
22 | 23 |
|
| 24 | +#if HAVE_LINUX_KCMP_H |
| 25 | +# include <linux/kcmp.h> /* kcmp: Definition of KCMP_* constants */ |
| 26 | +#endif /* HAVE_LINUX_KCMP_H */ |
| 27 | +#if HAVE_SYS_SYSCALL_H |
| 28 | +# include <sys/syscall.h> /* kcmp: Definition of SYS_* constants */ |
| 29 | +#endif /* HAVE_SYS_SYSCALL_H */ |
| 30 | + |
23 | 31 | #if OPAL_CMA_NEED_SYSCALL_DEFS
|
24 | 32 | # include "opal/sys/cma.h"
|
25 | 33 | #else
|
@@ -58,6 +66,26 @@ mca_smsc_endpoint_t *mca_smsc_cma_get_endpoint(opal_proc_t *peer_proc)
|
58 | 66 | return NULL;
|
59 | 67 | }
|
60 | 68 |
|
| 69 | +#if OPAL_CMA_KCMP_AVAIL |
| 70 | + /* Check if CAP_SYS_PTRACE capability is allowed between these two processes |
| 71 | + * Calling process_vm_readv/writev requires CAP_SYS_PTRACE. We can use kcmp |
| 72 | + * to check if these two processes share a kernel resource. Since kcmp |
| 73 | + * also requires CAP_SYS_PTRACE it is a good proxy for process_vm_readv/writev. |
| 74 | + */ |
| 75 | + rc = syscall(SYS_kcmp, getpid(), modex->pid, KCMP_VM, 0, 0); |
| 76 | + if(rc < 0) { |
| 77 | + opal_output_verbose(MCA_BASE_VERBOSE_ERROR, opal_smsc_base_framework.framework_output, |
| 78 | + "mca_smsc_cma_module_get_endpoint: can not proceed. processes do not have " |
| 79 | + "the necessary permissions (i.e., CAP_SYS_PTRACE). " |
| 80 | + "PID %d <-> %d (rc = %d) (errno: %d: %s)", |
| 81 | + getpid(), modex->pid, rc, errno, strerror(errno)); |
| 82 | + /* can't use CMA with this peer */ |
| 83 | + OBJ_RELEASE(endpoint); |
| 84 | + free(modex); |
| 85 | + return NULL; |
| 86 | + } |
| 87 | +#endif /* OPAL_CMA_KCMP_AVAIL */ |
| 88 | + |
61 | 89 | endpoint->pid = modex->pid;
|
62 | 90 | return &endpoint->super;
|
63 | 91 | }
|
|
0 commit comments