2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * SPDX-License-Identifier: GPL-2.0-only
22 #include <sys/types.h>
26 #include <common/lttng-kernel.h>
27 #include <common/common.h>
28 #include <common/utils.h>
29 #include <common/compat/getenv.h>
30 #include <common/compat/prctl.h>
31 #include <common/unix.h>
32 #include <common/defaults.h>
33 #include <common/lttng-elf.h>
35 #include <lttng/constant.h>
39 #define GETPW_BUFFER_FALLBACK_SIZE 4096
43 typedef int (*run_as_fct
)(struct run_as_data
*data
, struct run_as_ret
*ret_value
);
48 RUN_AS_MKDIR_RECURSIVE
,
49 RUN_AS_MKDIRAT_RECURSIVE
,
56 RUN_AS_RMDIR_RECURSIVE
,
57 RUN_AS_RMDIRAT_RECURSIVE
,
60 RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET
,
61 RUN_AS_EXTRACT_SDT_PROBE_OFFSETS
,
64 struct run_as_mkdir_data
{
66 char path
[LTTNG_PATH_MAX
];
70 struct run_as_open_data
{
72 char path
[LTTNG_PATH_MAX
];
77 struct run_as_unlink_data
{
79 char path
[LTTNG_PATH_MAX
];
82 struct run_as_rmdir_data
{
84 char path
[LTTNG_PATH_MAX
];
85 int flags
; /* enum lttng_directory_handle_rmdir_recursive_flags */
88 struct run_as_extract_elf_symbol_offset_data
{
90 char function
[LTTNG_SYMBOL_NAME_LEN
];
93 struct run_as_extract_sdt_probe_offsets_data
{
95 char probe_name
[LTTNG_SYMBOL_NAME_LEN
];
96 char provider_name
[LTTNG_SYMBOL_NAME_LEN
];
99 struct run_as_rename_data
{
105 char old_path
[LTTNG_PATH_MAX
];
106 char new_path
[LTTNG_PATH_MAX
];
109 struct run_as_open_ret
{
113 struct run_as_extract_elf_symbol_offset_ret
{
117 struct run_as_extract_sdt_probe_offsets_ret
{
119 uint64_t offsets
[LTTNG_KERNEL_MAX_UPROBE_NUM
];
125 struct run_as_mkdir_data mkdir
;
126 struct run_as_open_data open
;
127 struct run_as_unlink_data unlink
;
128 struct run_as_rmdir_data rmdir
;
129 struct run_as_rename_data rename
;
130 struct run_as_extract_elf_symbol_offset_data extract_elf_symbol_offset
;
131 struct run_as_extract_sdt_probe_offsets_data extract_sdt_probe_offsets
;
138 * The run_as_ret structure holds the returned value and status of the command.
140 * The `u` union field holds the return value of the command; in most cases it
141 * represents the success or the failure of the command. In more complex
142 * commands, it holds a computed value.
144 * The _errno field is the errno recorded after the execution of the command.
146 * The _error fields is used the signify that return status of the command. For
147 * simple commands returning `int` the _error field will be the same as the
148 * ret_int field. In complex commands, it signify the success or failure of the
155 struct run_as_open_ret open
;
156 struct run_as_extract_elf_symbol_offset_ret extract_elf_symbol_offset
;
157 struct run_as_extract_sdt_probe_offsets_ret extract_sdt_probe_offsets
;
163 #define COMMAND_IN_FDS(data_ptr) ({ \
165 if (command_properties[data_ptr->cmd].in_fds_offset != -1) { \
166 fds = (int *) ((char *) data_ptr + command_properties[data_ptr->cmd].in_fds_offset); \
171 #define COMMAND_OUT_FDS(cmd, ret_ptr) ({ \
173 if (command_properties[cmd].out_fds_offset != -1) { \
174 fds = (int *) ((char *) ret_ptr + command_properties[cmd].out_fds_offset); \
179 #define COMMAND_IN_FD_COUNT(data_ptr) ({ \
180 command_properties[data_ptr->cmd].in_fd_count; \
183 #define COMMAND_OUT_FD_COUNT(cmd) ({ \
184 command_properties[cmd].out_fd_count; \
187 #define COMMAND_USE_CWD_FD(data_ptr) command_properties[data_ptr->cmd].use_cwd_fd
189 struct run_as_command_properties
{
190 /* Set to -1 when not applicable. */
191 ptrdiff_t in_fds_offset
, out_fds_offset
;
192 unsigned int in_fd_count
, out_fd_count
;
196 static const struct run_as_command_properties command_properties
[] = {
198 .in_fds_offset
= offsetof(struct run_as_data
, u
.mkdir
.dirfd
),
200 .out_fds_offset
= -1,
205 .in_fds_offset
= offsetof(struct run_as_data
, u
.mkdir
.dirfd
),
207 .out_fds_offset
= -1,
211 [RUN_AS_MKDIR_RECURSIVE
] = {
212 .in_fds_offset
= offsetof(struct run_as_data
, u
.mkdir
.dirfd
),
214 .out_fds_offset
= -1,
218 [RUN_AS_MKDIRAT_RECURSIVE
] = {
219 .in_fds_offset
= offsetof(struct run_as_data
, u
.mkdir
.dirfd
),
221 .out_fds_offset
= -1,
226 .in_fds_offset
= offsetof(struct run_as_data
, u
.open
.dirfd
),
228 .out_fds_offset
= offsetof(struct run_as_ret
, u
.open
.fd
),
233 .in_fds_offset
= offsetof(struct run_as_data
, u
.open
.dirfd
),
235 .out_fds_offset
= offsetof(struct run_as_ret
, u
.open
.fd
),
240 .in_fds_offset
= offsetof(struct run_as_data
, u
.unlink
.dirfd
),
242 .out_fds_offset
= -1,
246 [RUN_AS_UNLINKAT
] = {
247 .in_fds_offset
= offsetof(struct run_as_data
, u
.unlink
.dirfd
),
249 .out_fds_offset
= -1,
253 [RUN_AS_RMDIR_RECURSIVE
] = {
254 .in_fds_offset
= offsetof(struct run_as_data
, u
.rmdir
.dirfd
),
256 .out_fds_offset
= -1,
260 [RUN_AS_RMDIRAT_RECURSIVE
] = {
261 .in_fds_offset
= offsetof(struct run_as_data
, u
.rmdir
.dirfd
),
263 .out_fds_offset
= -1,
268 .in_fds_offset
= offsetof(struct run_as_data
, u
.rmdir
.dirfd
),
270 .out_fds_offset
= -1,
275 .in_fds_offset
= offsetof(struct run_as_data
, u
.rmdir
.dirfd
),
277 .out_fds_offset
= -1,
282 .in_fds_offset
= offsetof(struct run_as_data
, u
.rename
.dirfds
),
284 .out_fds_offset
= -1,
288 [RUN_AS_RENAMEAT
] = {
289 .in_fds_offset
= offsetof(struct run_as_data
, u
.rename
.dirfds
),
291 .out_fds_offset
= -1,
295 [RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET
] = {
296 .in_fds_offset
= offsetof(struct run_as_data
,
297 u
.extract_elf_symbol_offset
.fd
),
299 .out_fds_offset
= -1,
303 [RUN_AS_EXTRACT_SDT_PROBE_OFFSETS
] = {
304 .in_fds_offset
= offsetof(struct run_as_data
,
305 u
.extract_sdt_probe_offsets
.fd
),
307 .out_fds_offset
= -1,
313 struct run_as_worker
{
314 pid_t pid
; /* Worker PID. */
319 /* Single global worker per process (for now). */
320 static struct run_as_worker
*global_worker
;
321 /* Lock protecting the worker. */
322 static pthread_mutex_t worker_lock
= PTHREAD_MUTEX_INITIALIZER
;
334 return !lttng_secure_getenv("LTTNG_DEBUG_NOCLONE");
339 * Create recursively directory using the FULL path.
342 int _mkdirat_recursive(struct run_as_data
*data
, struct run_as_ret
*ret_value
)
346 struct lttng_directory_handle
*handle
;
348 path
= data
->u
.mkdir
.path
;
349 mode
= data
->u
.mkdir
.mode
;
351 handle
= lttng_directory_handle_create_from_dirfd(data
->u
.mkdir
.dirfd
);
353 ret_value
->_errno
= errno
;
354 ret_value
->_error
= true;
355 ret_value
->u
.ret
= -1;
358 /* Ownership of dirfd is transferred to the handle. */
359 data
->u
.mkdir
.dirfd
= -1;
360 /* Safe to call as we have transitioned to the requested uid/gid. */
361 ret_value
->u
.ret
= lttng_directory_handle_create_subdirectory_recursive(
363 ret_value
->_errno
= errno
;
364 ret_value
->_error
= (ret_value
->u
.ret
) ? true : false;
365 lttng_directory_handle_put(handle
);
367 return ret_value
->u
.ret
;
371 int _mkdirat(struct run_as_data
*data
, struct run_as_ret
*ret_value
)
375 struct lttng_directory_handle
*handle
;
377 path
= data
->u
.mkdir
.path
;
378 mode
= data
->u
.mkdir
.mode
;
380 handle
= lttng_directory_handle_create_from_dirfd(data
->u
.mkdir
.dirfd
);
382 ret_value
->u
.ret
= -1;
383 ret_value
->_errno
= errno
;
384 ret_value
->_error
= true;
387 /* Ownership of dirfd is transferred to the handle. */
388 data
->u
.mkdir
.dirfd
= -1;
389 /* Safe to call as we have transitioned to the requested uid/gid. */
390 ret_value
->u
.ret
= lttng_directory_handle_create_subdirectory(
392 ret_value
->_errno
= errno
;
393 ret_value
->_error
= (ret_value
->u
.ret
) ? true : false;
394 lttng_directory_handle_put(handle
);
396 return ret_value
->u
.ret
;
400 int _open(struct run_as_data
*data
, struct run_as_ret
*ret_value
)
403 struct lttng_directory_handle
*handle
;
405 handle
= lttng_directory_handle_create_from_dirfd(data
->u
.open
.dirfd
);
407 ret_value
->_errno
= errno
;
408 ret_value
->_error
= true;
409 ret_value
->u
.ret
= -1;
412 /* Ownership of dirfd is transferred to the handle. */
413 data
->u
.open
.dirfd
= -1;
415 fd
= lttng_directory_handle_open_file(handle
,
416 data
->u
.open
.path
, data
->u
.open
.flags
,
419 ret_value
->u
.ret
= -1;
420 ret_value
->u
.open
.fd
= -1;
422 ret_value
->u
.ret
= 0;
423 ret_value
->u
.open
.fd
= fd
;
426 ret_value
->_errno
= errno
;
427 ret_value
->_error
= fd
< 0;
428 lttng_directory_handle_put(handle
);
430 return ret_value
->u
.ret
;
434 int _unlink(struct run_as_data
*data
, struct run_as_ret
*ret_value
)
436 struct lttng_directory_handle
*handle
;
438 handle
= lttng_directory_handle_create_from_dirfd(data
->u
.unlink
.dirfd
);
440 ret_value
->u
.ret
= -1;
441 ret_value
->_errno
= errno
;
442 ret_value
->_error
= true;
446 /* Ownership of dirfd is transferred to the handle. */
447 data
->u
.unlink
.dirfd
= -1;
449 ret_value
->u
.ret
= lttng_directory_handle_unlink_file(handle
,
450 data
->u
.unlink
.path
);
451 ret_value
->_errno
= errno
;
452 ret_value
->_error
= (ret_value
->u
.ret
) ? true : false;
453 lttng_directory_handle_put(handle
);
455 return ret_value
->u
.ret
;
459 int _rmdir(struct run_as_data
*data
, struct run_as_ret
*ret_value
)
461 struct lttng_directory_handle
*handle
;
463 handle
= lttng_directory_handle_create_from_dirfd(data
->u
.rmdir
.dirfd
);
465 ret_value
->u
.ret
= -1;
466 ret_value
->_errno
= errno
;
467 ret_value
->_error
= true;
471 /* Ownership of dirfd is transferred to the handle. */
472 data
->u
.rmdir
.dirfd
= -1;
474 ret_value
->u
.ret
= lttng_directory_handle_remove_subdirectory(
475 handle
, data
->u
.rmdir
.path
);
476 ret_value
->_errno
= errno
;
477 ret_value
->_error
= (ret_value
->u
.ret
) ? true : false;
478 lttng_directory_handle_put(handle
);
480 return ret_value
->u
.ret
;
484 int _rmdir_recursive(struct run_as_data
*data
, struct run_as_ret
*ret_value
)
486 struct lttng_directory_handle
*handle
;
488 handle
= lttng_directory_handle_create_from_dirfd(data
->u
.rmdir
.dirfd
);
490 ret_value
->u
.ret
= -1;
491 ret_value
->_errno
= errno
;
492 ret_value
->_error
= true;
496 /* Ownership of dirfd is transferred to the handle. */
497 data
->u
.rmdir
.dirfd
= -1;
499 ret_value
->u
.ret
= lttng_directory_handle_remove_subdirectory_recursive(
500 handle
, data
->u
.rmdir
.path
, data
->u
.rmdir
.flags
);
501 ret_value
->_errno
= errno
;
502 ret_value
->_error
= (ret_value
->u
.ret
) ? true : false;
503 lttng_directory_handle_put(handle
);
505 return ret_value
->u
.ret
;
509 int _rename(struct run_as_data
*data
, struct run_as_ret
*ret_value
)
511 const char *old_path
, *new_path
;
512 struct lttng_directory_handle
*old_handle
= NULL
, *new_handle
= NULL
;
514 old_path
= data
->u
.rename
.old_path
;
515 new_path
= data
->u
.rename
.new_path
;
517 old_handle
= lttng_directory_handle_create_from_dirfd(
518 data
->u
.rename
.dirfds
[0]);
520 ret_value
->u
.ret
= -1;
523 new_handle
= lttng_directory_handle_create_from_dirfd(
524 data
->u
.rename
.dirfds
[1]);
526 ret_value
->u
.ret
= -1;
530 /* Ownership of dirfds are transferred to the handles. */
531 data
->u
.rename
.dirfds
[0] = data
->u
.rename
.dirfds
[1] = -1;
533 /* Safe to call as we have transitioned to the requested uid/gid. */
534 ret_value
->u
.ret
= lttng_directory_handle_rename(
535 old_handle
, old_path
, new_handle
, new_path
);
537 lttng_directory_handle_put(old_handle
);
538 lttng_directory_handle_put(new_handle
);
539 ret_value
->_errno
= errno
;
540 ret_value
->_error
= (ret_value
->u
.ret
) ? true : false;
541 return ret_value
->u
.ret
;
546 int _extract_elf_symbol_offset(struct run_as_data
*data
,
547 struct run_as_ret
*ret_value
)
552 ret_value
->_error
= false;
553 ret
= lttng_elf_get_symbol_offset(data
->u
.extract_elf_symbol_offset
.fd
,
554 data
->u
.extract_elf_symbol_offset
.function
,
557 DBG("Failed to extract ELF function offset");
558 ret_value
->_error
= true;
560 ret_value
->u
.extract_elf_symbol_offset
.offset
= offset
;
566 int _extract_sdt_probe_offsets(struct run_as_data
*data
,
567 struct run_as_ret
*ret_value
)
570 uint64_t *offsets
= NULL
;
573 ret_value
->_error
= false;
575 /* On success, this call allocates the offsets paramater. */
576 ret
= lttng_elf_get_sdt_probe_offsets(
577 data
->u
.extract_sdt_probe_offsets
.fd
,
578 data
->u
.extract_sdt_probe_offsets
.provider_name
,
579 data
->u
.extract_sdt_probe_offsets
.probe_name
,
580 &offsets
, &num_offset
);
583 DBG("Failed to extract SDT probe offsets");
584 ret_value
->_error
= true;
588 if (num_offset
<= 0 || num_offset
> LTTNG_KERNEL_MAX_UPROBE_NUM
) {
589 DBG("Wrong number of probes.");
591 ret_value
->_error
= true;
595 /* Copy the content of the offsets array to the ret struct. */
596 memcpy(ret_value
->u
.extract_sdt_probe_offsets
.offsets
,
597 offsets
, num_offset
* sizeof(uint64_t));
599 ret_value
->u
.extract_sdt_probe_offsets
.num_offset
= num_offset
;
608 int _extract_elf_symbol_offset(struct run_as_data
*data
,
609 struct run_as_ret
*ret_value
)
611 ERR("Unimplemented runas command RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET");
616 int _extract_sdt_probe_offsets(struct run_as_data
*data
,
617 struct run_as_ret
*ret_value
)
619 ERR("Unimplemented runas command RUN_AS_EXTRACT_SDT_PROBE_OFFSETS");
625 run_as_fct
run_as_enum_to_fct(enum run_as_cmd cmd
)
631 case RUN_AS_MKDIR_RECURSIVE
:
632 case RUN_AS_MKDIRAT_RECURSIVE
:
633 return _mkdirat_recursive
;
638 case RUN_AS_UNLINKAT
:
643 case RUN_AS_RMDIR_RECURSIVE
:
644 case RUN_AS_RMDIRAT_RECURSIVE
:
645 return _rmdir_recursive
;
647 case RUN_AS_RENAMEAT
:
649 case RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET
:
650 return _extract_elf_symbol_offset
;
651 case RUN_AS_EXTRACT_SDT_PROBE_OFFSETS
:
652 return _extract_sdt_probe_offsets
;
654 ERR("Unknown command %d", (int) cmd
);
660 int do_send_fds(int sock
, const int *fds
, unsigned int fd_count
)
665 for (i
= 0; i
< fd_count
; i
++) {
667 ERR("Attempt to send invalid file descriptor to master (fd = %i)",
669 /* Return 0 as this is not a fatal error. */
674 len
= lttcomm_send_fds_unix_sock(sock
, fds
, fd_count
);
675 return len
< 0 ? -1 : 0;
679 int do_recv_fds(int sock
, int *fds
, unsigned int fd_count
)
685 len
= lttcomm_recv_fds_unix_sock(sock
, fds
, fd_count
);
689 } else if (len
< 0) {
690 PERROR("Failed to receive file descriptors from socket");
695 for (i
= 0; i
< fd_count
; i
++) {
697 ERR("Invalid file descriptor received from worker (fd = %i)", fds
[i
]);
698 /* Return 0 as this is not a fatal error. */
706 int send_fds_to_worker(const struct run_as_worker
*worker
,
707 const struct run_as_data
*data
)
712 if (COMMAND_USE_CWD_FD(data
) || COMMAND_IN_FD_COUNT(data
) == 0) {
716 for (i
= 0; i
< COMMAND_IN_FD_COUNT(data
); i
++) {
717 if (COMMAND_IN_FDS(data
)[i
] < 0) {
718 ERR("Refusing to send invalid fd to worker (fd = %i)",
719 COMMAND_IN_FDS(data
)[i
]);
725 ret
= do_send_fds(worker
->sockpair
[0], COMMAND_IN_FDS(data
),
726 COMMAND_IN_FD_COUNT(data
));
728 PERROR("Failed to send file descriptor to run-as worker");
737 int send_fds_to_master(struct run_as_worker
*worker
, enum run_as_cmd cmd
,
738 struct run_as_ret
*run_as_ret
)
743 if (COMMAND_OUT_FD_COUNT(cmd
) == 0) {
747 ret
= do_send_fds(worker
->sockpair
[1], COMMAND_OUT_FDS(cmd
, run_as_ret
),
748 COMMAND_OUT_FD_COUNT(cmd
));
750 PERROR("Failed to send file descriptor to master process");
754 for (i
= 0; i
< COMMAND_OUT_FD_COUNT(cmd
); i
++) {
755 int ret_close
= close(COMMAND_OUT_FDS(cmd
, run_as_ret
)[i
]);
758 PERROR("Failed to close result file descriptor");
766 int recv_fds_from_worker(const struct run_as_worker
*worker
, enum run_as_cmd cmd
,
767 struct run_as_ret
*run_as_ret
)
771 if (COMMAND_OUT_FD_COUNT(cmd
) == 0) {
775 ret
= do_recv_fds(worker
->sockpair
[0], COMMAND_OUT_FDS(cmd
, run_as_ret
),
776 COMMAND_OUT_FD_COUNT(cmd
));
778 PERROR("Failed to receive file descriptor from run-as worker");
786 int recv_fds_from_master(struct run_as_worker
*worker
, struct run_as_data
*data
)
790 if (COMMAND_USE_CWD_FD(data
)) {
793 for (i
= 0; i
< COMMAND_IN_FD_COUNT(data
); i
++) {
794 COMMAND_IN_FDS(data
)[i
] = AT_FDCWD
;
799 ret
= do_recv_fds(worker
->sockpair
[1], COMMAND_IN_FDS(data
),
800 COMMAND_IN_FD_COUNT(data
));
802 PERROR("Failed to receive file descriptors from master process");
810 int cleanup_received_fds(struct run_as_data
*data
)
814 for (i
= 0; i
< COMMAND_IN_FD_COUNT(data
); i
++) {
815 if (COMMAND_IN_FDS(data
)[i
] == -1) {
818 ret
= close(COMMAND_IN_FDS(data
)[i
]);
820 PERROR("Failed to close file descriptor received fd in run-as worker");
828 static int get_user_infos_from_uid(
829 uid_t uid
, char **username
, gid_t
*primary_gid
)
835 struct passwd
*result
= NULL
;
837 /* Fetch the max size for the temporary buffer. */
839 buf_size
= sysconf(_SC_GETPW_R_SIZE_MAX
);
842 PERROR("Failed to query _SC_GETPW_R_SIZE_MAX");
846 /* Limit is indeterminate. */
847 WARN("Failed to query _SC_GETPW_R_SIZE_MAX as it is "
848 "indeterminate; falling back to default buffer size");
849 buf_size
= GETPW_BUFFER_FALLBACK_SIZE
;
852 buf
= zmalloc(buf_size
);
854 PERROR("Failed to allocate buffer to get password file entries");
858 ret
= getpwuid_r(uid
, &pwd
, buf
, buf_size
, &result
);
860 PERROR("Failed to get user information for user: uid = %d",
865 if (result
== NULL
) {
866 ERR("Failed to find user information in password entries: uid = %d",
872 *username
= strdup(result
->pw_name
);
873 if (*username
== NULL
) {
874 PERROR("Failed to copy user name");
878 *primary_gid
= result
->pw_gid
;
890 static int demote_creds(
891 uid_t prev_uid
, gid_t prev_gid
, uid_t new_uid
, gid_t new_gid
)
895 char *username
= NULL
;
897 /* Change the group id. */
898 if (prev_gid
!= new_gid
) {
899 ret
= setegid(new_gid
);
901 PERROR("Failed to set effective group id: new_gid = %d",
907 /* Change the user id. */
908 if (prev_uid
!= new_uid
) {
909 ret
= get_user_infos_from_uid(new_uid
, &username
, &primary_gid
);
915 * Initialize the supplementary group access list.
917 * This is needed to handle cases where the supplementary groups
918 * of the user the process is demoting-to would give it access
919 * to a given file/folder, but not it's primary group.
923 * Primary Group: User1
924 * Secondary group: Disk, Network
926 * mkdir inside the following directory must work since User1
927 * is part of the Network group.
929 * drwxrwx--- 2 root Network 4096 Jul 23 17:17 /tmp/my_folder/
932 * The order of the following initgroups and seteuid calls is
934 * Only a root process or one with CAP_SETGID capability can
935 * call the the initgroups() function. We must initialize the
936 * supplementary groups before we change the effective
937 * UID to a less-privileged user.
939 ret
= initgroups(username
, primary_gid
);
941 PERROR("Failed to init the supplementary group access list: "
942 "username = `%s`, primary gid = %d", username
,
947 ret
= seteuid(new_uid
);
949 PERROR("Failed to set effective user id: new_uid = %d",
959 static int promote_creds(
960 uid_t prev_uid
, gid_t prev_gid
, uid_t new_uid
, gid_t new_gid
)
964 char *username
= NULL
;
966 /* Change the group id. */
967 if (prev_gid
!= new_gid
) {
968 ret
= setegid(new_gid
);
970 PERROR("Failed to set effective group id: new_gid = %d",
976 /* Change the user id. */
977 if (prev_uid
!= new_uid
) {
978 ret
= get_user_infos_from_uid(new_uid
, &username
, &primary_gid
);
984 * seteuid call must be done before the initgroups call because
985 * we need to be privileged (CAP_SETGID) to call initgroups().
987 ret
= seteuid(new_uid
);
989 PERROR("Failed to set effective user id: new_uid = %d",
995 * Initialize the supplementary group access list.
997 * There is a possibility the groups we set in the following
998 * initgroups() call are not exactly the same as the ones we
999 * had when we originally demoted. This can happen if the
1000 * /etc/group file is modified after the runas process is
1001 * forked. This is very unlikely.
1003 ret
= initgroups(username
, primary_gid
);
1005 PERROR("Failed to init the supplementary group access "
1006 "list: username = `%s`, primary gid = %d",
1007 username
, (int) primary_gid
)
1017 * Return < 0 on error, 0 if OK, 1 on hangup.
1020 int handle_one_cmd(struct run_as_worker
*worker
)
1022 int ret
= 0, promote_ret
;
1023 struct run_as_data data
= {};
1024 ssize_t readlen
, writelen
;
1025 struct run_as_ret sendret
= {};
1031 * Stage 1: Receive run_as_data struct from the master.
1032 * The structure contains the command type and all the parameters needed for
1035 readlen
= lttcomm_recv_unix_sock(worker
->sockpair
[1], &data
,
1042 if (readlen
< sizeof(data
)) {
1043 PERROR("lttcomm_recv_unix_sock error");
1048 cmd
= run_as_enum_to_fct(data
.cmd
);
1055 * Stage 2: Receive file descriptor from master.
1056 * Some commands need a file descriptor as input so if it's needed we
1057 * receive the fd using the Unix socket.
1059 ret
= recv_fds_from_master(worker
, &data
);
1061 PERROR("recv_fd_from_master error");
1066 prev_ruid
= getuid();
1067 prev_rgid
= getgid();
1069 ret
= demote_creds(prev_ruid
, prev_rgid
, data
.uid
, data
.gid
);
1075 * Also set umask to 0 for mkdir executable bit.
1080 * Stage 3: Execute the command
1082 ret
= (*cmd
)(&data
, &sendret
);
1084 DBG("Execution of command returned an error");
1088 ret
= cleanup_received_fds(&data
);
1090 ERR("Error cleaning up FD");
1095 * Stage 4: Send run_as_ret structure to the master.
1096 * This structure contain the return value of the command and the errno.
1098 writelen
= lttcomm_send_unix_sock(worker
->sockpair
[1], &sendret
,
1100 if (writelen
< sizeof(sendret
)) {
1101 PERROR("lttcomm_send_unix_sock error");
1107 * Stage 5: Send resulting file descriptors to the master.
1109 ret
= send_fds_to_master(worker
, data
.cmd
, &sendret
);
1111 DBG("Sending FD to master returned an error");
1117 /* Return to previous uid/gid. */
1118 promote_ret
= promote_creds(data
.uid
, data
.gid
, prev_ruid
, prev_rgid
);
1119 if (promote_ret
< 0) {
1120 ERR("Failed to promote back to the initial credentials");
1128 int run_as_worker(struct run_as_worker
*worker
)
1132 struct run_as_ret sendret
;
1133 size_t proc_orig_len
;
1136 * Initialize worker. Set a different process cmdline.
1138 proc_orig_len
= strlen(worker
->procname
);
1139 memset(worker
->procname
, 0, proc_orig_len
);
1140 strncpy(worker
->procname
, DEFAULT_RUN_AS_WORKER_NAME
, proc_orig_len
);
1142 ret
= lttng_prctl(PR_SET_NAME
,
1143 (unsigned long) DEFAULT_RUN_AS_WORKER_NAME
, 0, 0, 0);
1144 if (ret
&& ret
!= -ENOSYS
) {
1145 /* Don't fail as this is not essential. */
1146 PERROR("prctl PR_SET_NAME");
1149 memset(&sendret
, 0, sizeof(sendret
));
1151 writelen
= lttcomm_send_unix_sock(worker
->sockpair
[1], &sendret
,
1153 if (writelen
< sizeof(sendret
)) {
1154 PERROR("lttcomm_send_unix_sock error");
1160 ret
= handle_one_cmd(worker
);
1164 } else if (ret
> 0) {
1167 continue; /* Next command. */
1176 int run_as_cmd(struct run_as_worker
*worker
,
1177 enum run_as_cmd cmd
,
1178 struct run_as_data
*data
,
1179 struct run_as_ret
*ret_value
,
1180 uid_t uid
, gid_t gid
)
1183 ssize_t readlen
, writelen
;
1186 * If we are non-root, we can only deal with our own uid.
1188 if (geteuid() != 0) {
1189 if (uid
!= geteuid()) {
1191 ret_value
->_errno
= EPERM
;
1192 ERR("Client (%d)/Server (%d) UID mismatch (and sessiond is not root)",
1193 (int) uid
, (int) geteuid());
1203 * Stage 1: Send the run_as_data struct to the worker process
1205 writelen
= lttcomm_send_unix_sock(worker
->sockpair
[0], data
,
1207 if (writelen
< sizeof(*data
)) {
1208 PERROR("Error writing message to run_as");
1210 ret_value
->_errno
= EIO
;
1215 * Stage 2: Send file descriptor to the worker process if needed
1217 ret
= send_fds_to_worker(worker
, data
);
1219 PERROR("do_send_fd error");
1221 ret_value
->_errno
= EIO
;
1226 * Stage 3: Wait for the execution of the command
1230 * Stage 4: Receive the run_as_ret struct containing the return value and
1233 readlen
= lttcomm_recv_unix_sock(worker
->sockpair
[0], ret_value
,
1234 sizeof(*ret_value
));
1236 ERR("Run-as worker has hung-up during run_as_cmd");
1238 ret_value
->_errno
= EIO
;
1240 } else if (readlen
< sizeof(*ret_value
)) {
1241 PERROR("Error reading response from run_as");
1243 ret_value
->_errno
= errno
;
1247 if (ret_value
->_error
) {
1248 /* Skip stage 5 on error as there will be no fd to receive. */
1253 * Stage 5: Receive file descriptor if needed
1255 ret
= recv_fds_from_worker(worker
, cmd
, ret_value
);
1257 ERR("Error receiving fd");
1259 ret_value
->_errno
= EIO
;
1267 * This is for debugging ONLY and should not be considered secure.
1270 int run_as_noworker(enum run_as_cmd cmd
,
1271 struct run_as_data
*data
, struct run_as_ret
*ret_value
,
1272 uid_t uid
, gid_t gid
)
1274 int ret
, saved_errno
;
1278 fct
= run_as_enum_to_fct(cmd
);
1284 old_mask
= umask(0);
1285 ret
= fct(data
, ret_value
);
1286 saved_errno
= ret_value
->_errno
;
1288 errno
= saved_errno
;
1294 int reset_sighandler(void)
1298 DBG("Resetting run_as worker signal handlers to default");
1299 for (sig
= 1; sig
<= 31; sig
++) {
1300 (void) signal(sig
, SIG_DFL
);
1306 void worker_sighandler(int sig
)
1308 const char *signame
;
1311 * The worker will inherit its parent's signals since they are part of
1312 * the same process group. However, in the case of SIGINT and SIGTERM,
1313 * we want to give the worker a chance to teardown gracefully when its
1314 * parent closes the command socket.
1321 signame
= "SIGTERM";
1328 DBG("run_as worker received signal %s", signame
);
1330 DBG("run_as_worker received signal %d", sig
);
1335 int set_worker_sighandlers(void)
1339 struct sigaction sa
;
1341 if ((ret
= sigemptyset(&sigset
)) < 0) {
1342 PERROR("sigemptyset");
1346 sa
.sa_handler
= worker_sighandler
;
1347 sa
.sa_mask
= sigset
;
1349 if ((ret
= sigaction(SIGINT
, &sa
, NULL
)) < 0) {
1350 PERROR("sigaction SIGINT");
1354 if ((ret
= sigaction(SIGTERM
, &sa
, NULL
)) < 0) {
1355 PERROR("sigaction SIGTERM");
1359 DBG("run_as signal handler set for SIGTERM and SIGINT");
1365 int run_as_create_worker_no_lock(const char *procname
,
1366 post_fork_cleanup_cb clean_up_func
,
1367 void *clean_up_user_data
)
1372 struct run_as_ret recvret
;
1373 struct run_as_worker
*worker
;
1375 assert(!global_worker
);
1378 * Don't initialize a worker, all run_as tasks will be performed
1379 * in the current process.
1384 worker
= zmalloc(sizeof(*worker
));
1389 worker
->procname
= strdup(procname
);
1390 if (!worker
->procname
) {
1392 goto error_procname_alloc
;
1394 /* Create unix socket. */
1395 if (lttcomm_create_anon_unix_socketpair(worker
->sockpair
) < 0) {
1406 } else if (pid
== 0) {
1411 set_worker_sighandlers();
1412 if (clean_up_func
) {
1413 if (clean_up_func(clean_up_user_data
) < 0) {
1414 ERR("Run-as post-fork clean-up failed, exiting.");
1419 /* Just close, no shutdown. */
1420 if (close(worker
->sockpair
[0])) {
1426 * Close all FDs aside from STDIN, STDOUT, STDERR and sockpair[1]
1427 * Sockpair[1] is used as a control channel with the master
1429 for (i
= 3; i
< sysconf(_SC_OPEN_MAX
); i
++) {
1430 if (i
!= worker
->sockpair
[1]) {
1435 worker
->sockpair
[0] = -1;
1436 ret
= run_as_worker(worker
);
1437 if (lttcomm_close_unix_sock(worker
->sockpair
[1])) {
1441 worker
->sockpair
[1] = -1;
1442 free(worker
->procname
);
1444 LOG(ret
? PRINT_ERR
: PRINT_DBG
, "run_as worker exiting (ret = %d)", ret
);
1445 exit(ret
? EXIT_FAILURE
: EXIT_SUCCESS
);
1449 /* Just close, no shutdown. */
1450 if (close(worker
->sockpair
[1])) {
1455 worker
->sockpair
[1] = -1;
1457 /* Wait for worker to become ready. */
1458 readlen
= lttcomm_recv_unix_sock(worker
->sockpair
[0],
1459 &recvret
, sizeof(recvret
));
1460 if (readlen
< sizeof(recvret
)) {
1461 ERR("readlen: %zd", readlen
);
1462 PERROR("Error reading response from run_as at creation");
1466 global_worker
= worker
;
1471 /* Error handling. */
1473 for (i
= 0; i
< 2; i
++) {
1474 if (worker
->sockpair
[i
] < 0) {
1477 if (lttcomm_close_unix_sock(worker
->sockpair
[i
])) {
1480 worker
->sockpair
[i
] = -1;
1483 free(worker
->procname
);
1484 error_procname_alloc
:
1490 void run_as_destroy_worker_no_lock(void)
1492 struct run_as_worker
*worker
= global_worker
;
1494 DBG("Destroying run_as worker");
1498 /* Close unix socket */
1499 DBG("Closing run_as worker socket");
1500 if (lttcomm_close_unix_sock(worker
->sockpair
[0])) {
1503 worker
->sockpair
[0] = -1;
1504 /* Wait for worker. */
1509 wait_ret
= waitpid(worker
->pid
, &status
, 0);
1511 if (errno
== EINTR
) {
1518 if (WIFEXITED(status
)) {
1519 LOG(WEXITSTATUS(status
) == 0 ? PRINT_DBG
: PRINT_ERR
,
1520 DEFAULT_RUN_AS_WORKER_NAME
" terminated with status code %d",
1521 WEXITSTATUS(status
));
1523 } else if (WIFSIGNALED(status
)) {
1524 ERR(DEFAULT_RUN_AS_WORKER_NAME
" was killed by signal %d",
1529 free(worker
->procname
);
1531 global_worker
= NULL
;
1535 int run_as_restart_worker(struct run_as_worker
*worker
)
1538 char *procname
= NULL
;
1540 procname
= worker
->procname
;
1542 /* Close socket to run_as worker process and clean up the zombie process */
1543 run_as_destroy_worker_no_lock();
1545 /* Create a new run_as worker process*/
1546 ret
= run_as_create_worker_no_lock(procname
, NULL
, NULL
);
1548 ERR("Restarting the worker process failed");
1557 int run_as(enum run_as_cmd cmd
, struct run_as_data
*data
,
1558 struct run_as_ret
*ret_value
, uid_t uid
, gid_t gid
)
1560 int ret
, saved_errno
;
1562 pthread_mutex_lock(&worker_lock
);
1564 DBG("Using run_as worker");
1566 assert(global_worker
);
1568 ret
= run_as_cmd(global_worker
, cmd
, data
, ret_value
, uid
, gid
);
1569 saved_errno
= ret_value
->_errno
;
1572 * If the worker thread crashed the errno is set to EIO. we log
1573 * the error and start a new worker process.
1575 if (ret
== -1 && saved_errno
== EIO
) {
1576 DBG("Socket closed unexpectedly... "
1577 "Restarting the worker process");
1578 ret
= run_as_restart_worker(global_worker
);
1580 ERR("Failed to restart worker process.");
1585 DBG("Using run_as without worker");
1586 ret
= run_as_noworker(cmd
, data
, ret_value
, uid
, gid
);
1589 pthread_mutex_unlock(&worker_lock
);
1594 int run_as_mkdir_recursive(const char *path
, mode_t mode
, uid_t uid
, gid_t gid
)
1596 return run_as_mkdirat_recursive(AT_FDCWD
, path
, mode
, uid
, gid
);
1600 int run_as_mkdirat_recursive(int dirfd
, const char *path
, mode_t mode
,
1601 uid_t uid
, gid_t gid
)
1604 struct run_as_data data
= {};
1605 struct run_as_ret run_as_ret
= {};
1607 DBG3("mkdirat() recursive fd = %d%s, path = %s, mode = %d, uid = %d, gid = %d",
1608 dirfd
, dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1609 path
, (int) mode
, (int) uid
, (int) gid
);
1610 ret
= lttng_strncpy(data
.u
.mkdir
.path
, path
,
1611 sizeof(data
.u
.mkdir
.path
));
1613 ERR("Failed to copy path argument of mkdirat recursive command");
1616 data
.u
.mkdir
.path
[sizeof(data
.u
.mkdir
.path
) - 1] = '\0';
1617 data
.u
.mkdir
.mode
= mode
;
1618 data
.u
.mkdir
.dirfd
= dirfd
;
1619 run_as(dirfd
== AT_FDCWD
? RUN_AS_MKDIR_RECURSIVE
: RUN_AS_MKDIRAT_RECURSIVE
,
1620 &data
, &run_as_ret
, uid
, gid
);
1621 errno
= run_as_ret
._errno
;
1622 ret
= run_as_ret
.u
.ret
;
1628 int run_as_mkdir(const char *path
, mode_t mode
, uid_t uid
, gid_t gid
)
1630 return run_as_mkdirat(AT_FDCWD
, path
, mode
, uid
, gid
);
1634 int run_as_mkdirat(int dirfd
, const char *path
, mode_t mode
,
1635 uid_t uid
, gid_t gid
)
1638 struct run_as_data data
= {};
1639 struct run_as_ret run_as_ret
= {};
1641 DBG3("mkdirat() recursive fd = %d%s, path = %s, mode = %d, uid = %d, gid = %d",
1642 dirfd
, dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1643 path
, (int) mode
, (int) uid
, (int) gid
);
1644 ret
= lttng_strncpy(data
.u
.mkdir
.path
, path
,
1645 sizeof(data
.u
.mkdir
.path
));
1647 ERR("Failed to copy path argument of mkdirat command");
1650 data
.u
.mkdir
.path
[sizeof(data
.u
.mkdir
.path
) - 1] = '\0';
1651 data
.u
.mkdir
.mode
= mode
;
1652 data
.u
.mkdir
.dirfd
= dirfd
;
1653 run_as(dirfd
== AT_FDCWD
? RUN_AS_MKDIR
: RUN_AS_MKDIRAT
,
1654 &data
, &run_as_ret
, uid
, gid
);
1655 errno
= run_as_ret
._errno
;
1656 ret
= run_as_ret
.u
.ret
;
1662 int run_as_open(const char *path
, int flags
, mode_t mode
, uid_t uid
,
1665 return run_as_openat(AT_FDCWD
, path
, flags
, mode
, uid
, gid
);
1669 int run_as_openat(int dirfd
, const char *path
, int flags
, mode_t mode
,
1670 uid_t uid
, gid_t gid
)
1673 struct run_as_data data
= {};
1674 struct run_as_ret run_as_ret
= {};
1676 DBG3("openat() fd = %d%s, path = %s, flags = %X, mode = %d, uid %d, gid %d",
1677 dirfd
, dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1678 path
, flags
, (int) mode
, (int) uid
, (int) gid
);
1679 ret
= lttng_strncpy(data
.u
.open
.path
, path
, sizeof(data
.u
.open
.path
));
1681 ERR("Failed to copy path argument of open command");
1684 data
.u
.open
.flags
= flags
;
1685 data
.u
.open
.mode
= mode
;
1686 data
.u
.open
.dirfd
= dirfd
;
1687 run_as(dirfd
== AT_FDCWD
? RUN_AS_OPEN
: RUN_AS_OPENAT
,
1688 &data
, &run_as_ret
, uid
, gid
);
1689 errno
= run_as_ret
._errno
;
1690 ret
= run_as_ret
.u
.ret
< 0 ? run_as_ret
.u
.ret
:
1691 run_as_ret
.u
.open
.fd
;
1697 int run_as_unlink(const char *path
, uid_t uid
, gid_t gid
)
1699 return run_as_unlinkat(AT_FDCWD
, path
, uid
, gid
);
1703 int run_as_unlinkat(int dirfd
, const char *path
, uid_t uid
, gid_t gid
)
1706 struct run_as_data data
= {};
1707 struct run_as_ret run_as_ret
= {};
1709 DBG3("unlinkat() fd = %d%s, path = %s, uid = %d, gid = %d",
1710 dirfd
, dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1711 path
, (int) uid
, (int) gid
);
1712 ret
= lttng_strncpy(data
.u
.unlink
.path
, path
,
1713 sizeof(data
.u
.unlink
.path
));
1717 data
.u
.unlink
.dirfd
= dirfd
;
1718 run_as(dirfd
== AT_FDCWD
? RUN_AS_UNLINK
: RUN_AS_UNLINKAT
, &data
,
1719 &run_as_ret
, uid
, gid
);
1720 errno
= run_as_ret
._errno
;
1721 ret
= run_as_ret
.u
.ret
;
1727 int run_as_rmdir(const char *path
, uid_t uid
, gid_t gid
)
1729 return run_as_rmdirat(AT_FDCWD
, path
, uid
, gid
);
1733 int run_as_rmdirat(int dirfd
, const char *path
, uid_t uid
, gid_t gid
)
1736 struct run_as_data data
= {};
1737 struct run_as_ret run_as_ret
= {};
1739 DBG3("rmdirat() fd = %d%s, path = %s, uid = %d, gid = %d",
1740 dirfd
, dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1741 path
, (int) uid
, (int) gid
);
1742 ret
= lttng_strncpy(data
.u
.rmdir
.path
, path
,
1743 sizeof(data
.u
.rmdir
.path
));
1747 data
.u
.rmdir
.dirfd
= dirfd
;
1748 run_as(dirfd
== AT_FDCWD
? RUN_AS_RMDIR
: RUN_AS_RMDIRAT
, &data
,
1749 &run_as_ret
, uid
, gid
);
1750 errno
= run_as_ret
._errno
;
1751 ret
= run_as_ret
.u
.ret
;
1757 int run_as_rmdir_recursive(const char *path
, uid_t uid
, gid_t gid
, int flags
)
1759 return run_as_rmdirat_recursive(AT_FDCWD
, path
, uid
, gid
, flags
);
1763 int run_as_rmdirat_recursive(int dirfd
, const char *path
, uid_t uid
, gid_t gid
, int flags
)
1766 struct run_as_data data
= {};
1767 struct run_as_ret run_as_ret
= {};
1769 DBG3("rmdirat() recursive fd = %d%s, path = %s, uid = %d, gid = %d",
1770 dirfd
, dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1771 path
, (int) uid
, (int) gid
);
1772 ret
= lttng_strncpy(data
.u
.rmdir
.path
, path
,
1773 sizeof(data
.u
.rmdir
.path
));
1777 data
.u
.rmdir
.dirfd
= dirfd
;
1778 data
.u
.rmdir
.flags
= flags
;
1779 run_as(dirfd
== AT_FDCWD
? RUN_AS_RMDIR_RECURSIVE
: RUN_AS_RMDIRAT_RECURSIVE
,
1780 &data
, &run_as_ret
, uid
, gid
);
1781 errno
= run_as_ret
._errno
;
1782 ret
= run_as_ret
.u
.ret
;
1788 int run_as_rename(const char *old
, const char *new, uid_t uid
, gid_t gid
)
1790 return run_as_renameat(AT_FDCWD
, old
, AT_FDCWD
, new, uid
, gid
);
1794 int run_as_renameat(int old_dirfd
, const char *old_name
,
1795 int new_dirfd
, const char *new_name
, uid_t uid
, gid_t gid
)
1798 struct run_as_data data
= {};
1799 struct run_as_ret run_as_ret
= {};
1801 DBG3("renameat() old_dirfd = %d%s, old_name = %s, new_dirfd = %d%s, new_name = %s, uid = %d, gid = %d",
1802 old_dirfd
, old_dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1804 new_dirfd
, new_dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1805 new_name
, (int) uid
, (int) gid
);
1806 ret
= lttng_strncpy(data
.u
.rename
.old_path
, old_name
,
1807 sizeof(data
.u
.rename
.old_path
));
1811 ret
= lttng_strncpy(data
.u
.rename
.new_path
, new_name
,
1812 sizeof(data
.u
.rename
.new_path
));
1817 data
.u
.rename
.dirfds
[0] = old_dirfd
;
1818 data
.u
.rename
.dirfds
[1] = new_dirfd
;
1819 run_as(old_dirfd
== AT_FDCWD
&& new_dirfd
== AT_FDCWD
?
1820 RUN_AS_RENAME
: RUN_AS_RENAMEAT
,
1821 &data
, &run_as_ret
, uid
, gid
);
1822 errno
= run_as_ret
._errno
;
1823 ret
= run_as_ret
.u
.ret
;
1829 int run_as_extract_elf_symbol_offset(int fd
, const char* function
,
1830 uid_t uid
, gid_t gid
, uint64_t *offset
)
1833 struct run_as_data data
= {};
1834 struct run_as_ret run_as_ret
= {};
1836 DBG3("extract_elf_symbol_offset() on fd=%d and function=%s "
1837 "with for uid %d and gid %d", fd
, function
,
1838 (int) uid
, (int) gid
);
1840 data
.u
.extract_elf_symbol_offset
.fd
= fd
;
1842 strncpy(data
.u
.extract_elf_symbol_offset
.function
, function
, LTTNG_SYMBOL_NAME_LEN
- 1);
1843 data
.u
.extract_elf_symbol_offset
.function
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1844 ret
= lttng_strncpy(data
.u
.extract_elf_symbol_offset
.function
,
1846 sizeof(data
.u
.extract_elf_symbol_offset
.function
));
1851 run_as(RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET
, &data
, &run_as_ret
, uid
, gid
);
1852 errno
= run_as_ret
._errno
;
1853 if (run_as_ret
._error
) {
1858 *offset
= run_as_ret
.u
.extract_elf_symbol_offset
.offset
;
1864 int run_as_extract_sdt_probe_offsets(int fd
, const char* provider_name
,
1865 const char* probe_name
, uid_t uid
, gid_t gid
,
1866 uint64_t **offsets
, uint32_t *num_offset
)
1869 struct run_as_data data
= {};
1870 struct run_as_ret run_as_ret
= {};
1872 DBG3("extract_sdt_probe_offsets() on fd=%d, probe_name=%s and "
1873 "provider_name=%s with for uid %d and gid %d", fd
,
1874 probe_name
, provider_name
, (int) uid
, (int) gid
);
1876 data
.u
.extract_sdt_probe_offsets
.fd
= fd
;
1878 ret
= lttng_strncpy(data
.u
.extract_sdt_probe_offsets
.probe_name
, probe_name
,
1879 sizeof(data
.u
.extract_sdt_probe_offsets
.probe_name
));
1883 ret
= lttng_strncpy(data
.u
.extract_sdt_probe_offsets
.provider_name
,
1885 sizeof(data
.u
.extract_sdt_probe_offsets
.provider_name
));
1890 run_as(RUN_AS_EXTRACT_SDT_PROBE_OFFSETS
, &data
, &run_as_ret
, uid
, gid
);
1891 errno
= run_as_ret
._errno
;
1892 if (run_as_ret
._error
) {
1897 *num_offset
= run_as_ret
.u
.extract_sdt_probe_offsets
.num_offset
;
1898 *offsets
= zmalloc(*num_offset
* sizeof(uint64_t));
1904 memcpy(*offsets
, run_as_ret
.u
.extract_sdt_probe_offsets
.offsets
,
1905 *num_offset
* sizeof(uint64_t));
1911 int run_as_create_worker(const char *procname
,
1912 post_fork_cleanup_cb clean_up_func
,
1913 void *clean_up_user_data
)
1917 pthread_mutex_lock(&worker_lock
);
1918 ret
= run_as_create_worker_no_lock(procname
, clean_up_func
,
1919 clean_up_user_data
);
1920 pthread_mutex_unlock(&worker_lock
);
1925 void run_as_destroy_worker(void)
1927 pthread_mutex_lock(&worker_lock
);
1928 run_as_destroy_worker_no_lock();
1929 pthread_mutex_unlock(&worker_lock
);