From 95250804999858593f9febf2e85b51463f17a5df Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 13 Jun 2022 15:25:40 -0400 Subject: [PATCH 01/16] Custom upgrade: wire up configure --enable-custom-upgrade-conflicting-symbols This custom configure switch allows selecting between those two behaviors for symbols which clash between lttng-ust 2.12 and 2.13: Disabled (default): only emit and use symbols with "1" suffix. This is meant to be used alonside lttng-ust 2.12. Enabled: emit both symbols with and without "1" suffix, and use the symbol without suffix. This is meant to be used after there are no more users of lttng-ust 2.12 to gradually transition back to an upstream lttng-ust 2.13 as applications are rebuilt. Signed-off-by: Mathieu Desnoyers Change-Id: I7ed02b2f0f9bd8c7b7b24fce28d2f23d61c970a3 --- configure.ac | 10 ++++++++++ include/lttng/ust-config.h.in | 3 +++ 2 files changed, 13 insertions(+) diff --git a/configure.ac b/configure.ac index e0d6c163..4dfc011a 100644 --- a/configure.ac +++ b/configure.ac @@ -371,6 +371,11 @@ AE_FEATURE([examples],[Do not build and install examples]) AE_FEATURE_DEFAULT_ENABLE AE_FEATURE([man-pages],[Do not build and install man pages (already built in a distributed tarball)]) +# Custom upgrade conflicting symbols +# Disabled by default +AE_FEATURE_DEFAULT_DISABLE +AE_FEATURE([custom-upgrade-conflicting-symbols],[Emit and use original symbols for custom upgrade from 2.12 to 2.13]) + # Systemtap sdt.h integration # Disabled by default AC_ARG_WITH([sdt], @@ -508,6 +513,11 @@ they will not be installed. ]) ]) +# Emit and use original symbols for custom upgrade from 2.12 to 2.13 +AE_IF_FEATURE_ENABLED([custom-upgrade-conflicting-symbols], [ + AC_DEFINE([LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS], [1], [Emit and use original symbols for custom upgrade from 2.12 to 2.13]) +]) + AS_IF([test "x$with_sdt" = "xyes"], [ AC_MSG_CHECKING([STAP_PROBEV()]) AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ diff --git a/include/lttng/ust-config.h.in b/include/lttng/ust-config.h.in index fb6e371c..70ac4db7 100644 --- a/include/lttng/ust-config.h.in +++ b/include/lttng/ust-config.h.in @@ -10,4 +10,7 @@ /* DTrace/GDB/SystemTap integration via sdt.h */ #undef LTTNG_UST_HAVE_SDT_INTEGRATION +/* Emit and use original symbols for custom upgrade from 2.12 to 2.13 */ +#undef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS + #endif -- 2.34.1 From 1c36b0ff8793be6200b55eb08ce915b248b01111 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 13 Jun 2022 14:24:14 -0400 Subject: [PATCH 02/16] Custom upgrade: suffix lttng_ust_context_provider_{,un}register with 1 Signed-off-by: Mathieu Desnoyers Change-Id: Ib6adae1cab526f2407483223c8dcbb1ba79c263f --- src/common/ust-context-provider.h | 7 +++++++ src/lib/lttng-ust/lttng-context-provider.c | 21 +++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/common/ust-context-provider.h b/src/common/ust-context-provider.h index 43e75b4b..29f3d09b 100644 --- a/src/common/ust-context-provider.h +++ b/src/common/ust-context-provider.h @@ -12,6 +12,7 @@ #define _LTTNG_UST_CONTEXT_PROVIDER_H #include +#include #include #include "common/dynamic-type.h" @@ -88,6 +89,12 @@ struct lttng_ust_app_context { /* End of base ABI. Fields below should be used after checking struct_size. */ }; +/* Custom upgrade 2.12 to 2.13 */ +#ifndef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS +#define lttng_ust_context_provider_register lttng_ust_context_provider_register1 +#define lttng_ust_context_provider_unregister lttng_ust_context_provider_unregister1 +#endif + /* * Returns an opaque pointer on success, which must be passed to * lttng_ust_context_provider_unregister for unregistration. Returns diff --git a/src/lib/lttng-ust/lttng-context-provider.c b/src/lib/lttng-ust/lttng-context-provider.c index 4e7e429f..0626576b 100644 --- a/src/lib/lttng-ust/lttng-context-provider.c +++ b/src/lib/lttng-ust/lttng-context-provider.c @@ -60,7 +60,8 @@ static const struct lttng_ust_context_provider * return NULL; } -struct lttng_ust_registered_context_provider *lttng_ust_context_provider_register(struct lttng_ust_context_provider *provider) +static +struct lttng_ust_registered_context_provider *lttng_ust_context_provider_register_orig(struct lttng_ust_context_provider *provider) { struct lttng_ust_registered_context_provider *reg_provider = NULL; struct cds_hlist_head *head; @@ -99,7 +100,8 @@ end: return reg_provider; } -void lttng_ust_context_provider_unregister(struct lttng_ust_registered_context_provider *reg_provider) +static +void lttng_ust_context_provider_unregister_orig(struct lttng_ust_registered_context_provider *reg_provider) { lttng_ust_alloc_tls(); @@ -210,3 +212,18 @@ error_field_name_alloc: error_event_field_alloc: return ret; } + +/* Custom upgrade 2.12 to 2.13 */ +#undef lttng_ust_context_provider_register +#undef lttng_ust_context_provider_unregister +struct lttng_ust_registered_context_provider *lttng_ust_context_provider_register1(struct lttng_ust_context_provider *provider) + __attribute ((alias ("lttng_ust_context_provider_register_orig"))); +void lttng_ust_context_provider_unregister1(struct lttng_ust_registered_context_provider *reg_provider) + __attribute ((alias ("lttng_ust_context_provider_unregister_orig"))); + +#ifdef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS +struct lttng_ust_registered_context_provider *lttng_ust_context_provider_register(struct lttng_ust_context_provider *provider) + __attribute ((alias ("lttng_ust_context_provider_register_orig"))); +void lttng_ust_context_provider_unregister(struct lttng_ust_registered_context_provider *reg_provider) + __attribute ((alias ("lttng_ust_context_provider_unregister_orig"))); +#endif -- 2.34.1 From 39dac944d90a8c78d245038f31942b83277476cf Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 13 Jun 2022 14:27:06 -0400 Subject: [PATCH 03/16] Custom upgrade: suffix lttng_ust_dl_update with 1 Signed-off-by: Mathieu Desnoyers Change-Id: I42eb70f5d7a6336d64483af7a5293b882e2f6639 --- src/common/events.h | 5 +++++ src/lib/lttng-ust/lttng-ust-statedump.c | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/common/events.h b/src/common/events.h index 76062828..fe7f4ae3 100644 --- a/src/common/events.h +++ b/src/common/events.h @@ -13,6 +13,7 @@ #include #include +#include #include #include "common/macros.h" @@ -580,6 +581,10 @@ struct lttng_enabler *lttng_event_notifier_enabler_as_enabler( } +/* Custom upgrade 2.12 to 2.13 */ +#ifndef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS +#define lttng_ust_dl_update lttng_ust_dl_update1 +#endif /* This is ABI between liblttng-ust and liblttng-ust-dl */ void lttng_ust_dl_update(void *ip); diff --git a/src/lib/lttng-ust/lttng-ust-statedump.c b/src/lib/lttng-ust/lttng-ust-statedump.c index 309a98fa..6b0d0567 100644 --- a/src/lib/lttng-ust/lttng-ust-statedump.c +++ b/src/lib/lttng-ust/lttng-ust-statedump.c @@ -546,7 +546,8 @@ end: ust_unlock(); } -void lttng_ust_dl_update(void *ip) +static +void lttng_ust_dl_update_orig(void *ip) { struct dl_iterate_data data; @@ -660,3 +661,13 @@ void lttng_ust_statedump_destroy(void) lttng_ust__tracepoints__destroy(); ust_dl_state_destroy(); } + +/* Custom upgrade 2.12 to 2.13 */ +#undef lttng_ust_dl_update +void lttng_ust_dl_update1(void *ip) + __attribute__ ((alias ("lttng_ust_dl_update_orig"))); + +#ifdef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS +void lttng_ust_dl_update(void *ip) + __attribute__ ((alias ("lttng_ust_dl_update_orig"))); +#endif -- 2.34.1 From 3b350a5e947841be3274ee0f0469e73dbd45138e Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 13 Jun 2022 14:42:24 -0400 Subject: [PATCH 04/16] Custom upgrade: suffix lttng_ust_loaded with 1 Signed-off-by: Mathieu Desnoyers Change-Id: I8efb7b3e3b291b3716762a1a56c131263915ef4c --- doc/man/lttng-ust.3.txt | 8 ++++---- src/lib/lttng-ust/lttng-ust-comm.c | 14 +++++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/man/lttng-ust.3.txt b/doc/man/lttng-ust.3.txt index 0924a4de..bb52bfe9 100644 --- a/doc/man/lttng-ust.3.txt +++ b/doc/man/lttng-ust.3.txt @@ -1180,20 +1180,20 @@ Detect if LTTng-UST is loaded ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To detect if `liblttng-ust` is loaded from an application: -. Define the `lttng_ust_loaded` weak symbol globally: +. Define the `lttng_ust_loaded1` weak symbol globally: + ------------------------------------------------------------------------ -int lttng_ust_loaded __attribute__((weak)); +int lttng_ust_loaded1 __attribute__((weak)); ------------------------------------------------------------------------ + This weak symbol is set by the constructor of `liblttng-ust`. -. Test `lttng_ust_loaded` where needed: +. Test `lttng_ust_loaded1` where needed: + ------------------------------------------------------------------------ /* ... */ -if (lttng_ust_loaded) { +if (lttng_ust_loaded1) { /* LTTng-UST is loaded */ } else { /* LTTng-UST is NOT loaded */ diff --git a/src/lib/lttng-ust/lttng-ust-comm.c b/src/lib/lttng-ust/lttng-ust-comm.c index a07e1e12..cf819b80 100644 --- a/src/lib/lttng-ust/lttng-ust-comm.c +++ b/src/lib/lttng-ust/lttng-ust-comm.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -113,10 +114,10 @@ static int lttng_ust_comm_should_quit; /* * This variable can be tested by applications to check whether * lttng-ust is loaded. They simply have to define their own - * "lttng_ust_loaded" weak symbol, and test it. It is set to 1 by the + * "lttng_ust_loaded1" weak symbol, and test it. It is set to 1 by the * library constructor. */ -int lttng_ust_loaded __attribute__((weak)); +static int lttng_ust_loaded_orig; /* * Notes on async-signal-safety of ust lock: a few libc functions are used @@ -2185,7 +2186,7 @@ void lttng_ust_ctor(void) */ lttng_ust_alloc_tls(); - lttng_ust_loaded = 1; + lttng_ust_loaded_orig = 1; /* * Check if we find a symbol of the previous ABI in the current process @@ -2631,3 +2632,10 @@ void lttng_ust_sockinfo_session_enabled(void *owner) struct sock_info *sock_info = owner; sock_info->statedump_pending = 1; } + +/* Custom upgrade 2.12 to 2.13 */ +extern int lttng_ust_loaded1 __attribute__((weak, alias("lttng_ust_loaded_orig"))); + +#ifdef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS +extern int lttng_ust_loaded __attribute__((weak, alias("lttng_ust_loaded_orig"))); +#endif -- 2.34.1 From 4696b6ea6f4881f81f515b8f2eafbd9eeb84f10a Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 13 Jun 2022 14:48:44 -0400 Subject: [PATCH 05/16] Custom upgrade: suffix lttng_ust_strerror with 1 Signed-off-by: Mathieu Desnoyers Change-Id: I8a4a3017402fe7b9316b451b07bc86738576db91 --- include/lttng/ust-error.h | 6 ++++++ src/lib/lttng-ust/strerror.c | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/lttng/ust-error.h b/include/lttng/ust-error.h index 49045bab..46541c1b 100644 --- a/include/lttng/ust-error.h +++ b/include/lttng/ust-error.h @@ -10,6 +10,7 @@ #include #include +#include #include #ifdef __cplusplus @@ -39,6 +40,11 @@ enum lttng_ust_error_code { LTTNG_UST_ERR_NR, /* Last element */ }; +/* Custom upgrade 2.12 to 2.13 */ +#ifndef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS +#define lttng_ust_strerror lttng_ust_strerror1 +#endif + /* * lttng_ust_strerror * @code: must be a negative value of enum lttng_ust_error_code (or 0). diff --git a/src/lib/lttng-ust/strerror.c b/src/lib/lttng-ust/strerror.c index 5a671a07..46bfdb6b 100644 --- a/src/lib/lttng-ust/strerror.c +++ b/src/lib/lttng-ust/strerror.c @@ -37,7 +37,7 @@ static const char *ustcomm_readable_code[] = { * Returns a ptr to a string representing a human readable error code from the * ustcomm_return_code enum. */ -const char *lttng_ust_strerror(int code) +static const char *lttng_ust_strerror_orig(int code) { code = -code; @@ -46,3 +46,13 @@ const char *lttng_ust_strerror(int code) return ustcomm_readable_code[CODE_OFFSET(code)]; } + +/* Custom upgrade 2.12 to 2.13 */ +#undef lttng_ust_strerror +const char *lttng_ust_strerror1(int code) + __attribute__ ((alias ("lttng_ust_strerror_orig"))); + +#ifdef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS +const char *lttng_ust_strerror(int code) + __attribute__ ((alias ("lttng_ust_strerror_orig"))); +#endif -- 2.34.1 From f799b0b79a0389ff033c4812601fea512913fb7d Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 13 Jun 2022 14:54:35 -0400 Subject: [PATCH 06/16] Custom upgrade: fd tracker: suffix exported symbols with 1 Signed-off-by: Mathieu Desnoyers Change-Id: I465a926d741d5c7f5c6db2cc29d1fc84ab7e4aa2 --- src/common/ust-fd.h | 13 +++++++ src/lib/lttng-ust-common/fd-tracker.c | 56 +++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/common/ust-fd.h b/src/common/ust-fd.h index 4e6c4a5d..4d29d5eb 100644 --- a/src/common/ust-fd.h +++ b/src/common/ust-fd.h @@ -16,6 +16,19 @@ */ #include +#include + +/* Custom upgrade 2.12 to 2.13 */ + +#ifndef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS +#define lttng_ust_add_fd_to_tracker lttng_ust_add_fd_to_tracker1 +#define lttng_ust_delete_fd_from_tracker lttng_ust_delete_fd_from_tracker1 +#define lttng_ust_lock_fd_tracker lttng_ust_lock_fd_tracker1 +#define lttng_ust_unlock_fd_tracker lttng_ust_unlock_fd_tracker1 +#define lttng_ust_safe_close_fd lttng_ust_safe_close_fd1 +#define lttng_ust_safe_fclose_stream lttng_ust_safe_fclose_stream1 +#define lttng_ust_safe_closefrom_fd lttng_ust_safe_closefrom_fd1 +#endif int lttng_ust_add_fd_to_tracker(int fd); void lttng_ust_delete_fd_from_tracker(int fd); diff --git a/src/lib/lttng-ust-common/fd-tracker.c b/src/lib/lttng-ust-common/fd-tracker.c index 70539cab..12fcd9cb 100644 --- a/src/lib/lttng-ust-common/fd-tracker.c +++ b/src/lib/lttng-ust-common/fd-tracker.c @@ -118,7 +118,7 @@ void lttng_ust_fd_tracker_init(void) CMM_STORE_SHARED(init_done, 1); } -void lttng_ust_lock_fd_tracker(void) +static void lttng_ust_lock_fd_tracker_orig(void) { sigset_t sig_all_blocked, orig_mask; int ret; @@ -145,7 +145,7 @@ void lttng_ust_lock_fd_tracker(void) } } -void lttng_ust_unlock_fd_tracker(void) +static void lttng_ust_unlock_fd_tracker_orig(void) { sigset_t sig_all_blocked, orig_mask; int ret; @@ -251,7 +251,7 @@ error: * Return -1 on error. * */ -int lttng_ust_add_fd_to_tracker(int fd) +static int lttng_ust_add_fd_to_tracker_orig(int fd) { int ret; /* @@ -284,7 +284,7 @@ error: * Needs to be called with ust_safe_guard_fd_mutex held when opening the fd. * Has strict checking for fd validity. */ -void lttng_ust_delete_fd_from_tracker(int fd) +static void lttng_ust_delete_fd_from_tracker_orig(int fd) { /* * Ensure the tracker is initialized when called from @@ -306,7 +306,7 @@ void lttng_ust_delete_fd_from_tracker(int fd) * We check if it is owned by lttng-ust, and return -1, errno=EBADF * instead of closing it if it is the case. */ -int lttng_ust_safe_close_fd(int fd, int (*close_cb)(int fd)) +static int lttng_ust_safe_close_fd_orig(int fd, int (*close_cb)(int fd)) { int ret = 0; @@ -342,7 +342,7 @@ int lttng_ust_safe_close_fd(int fd, int (*close_cb)(int fd)) * We check if it is owned by lttng-ust, and return -1, errno=EBADF * instead of closing it if it is the case. */ -int lttng_ust_safe_fclose_stream(FILE *stream, int (*fclose_cb)(FILE *stream)) +static int lttng_ust_safe_fclose_stream_orig(FILE *stream, int (*fclose_cb)(FILE *stream)) { int ret = 0, fd; @@ -397,7 +397,7 @@ static int test_close_success(const int *p __attribute__((unused))) /* * Implement helper for closefrom() override. */ -int lttng_ust_safe_closefrom_fd(int lowfd, int (*close_cb)(int fd)) +static int lttng_ust_safe_closefrom_fd_orig(int lowfd, int (*close_cb)(int fd)) { int ret = 0, close_success = 0, i; @@ -466,3 +466,45 @@ int lttng_ust_safe_closefrom_fd(int lowfd, int (*close_cb)(int fd)) end: return ret; } + +/* Custom upgrade 2.12 to 2.13 */ + +#undef lttng_ust_add_fd_to_tracker +#undef lttng_ust_delete_fd_from_tracker +#undef lttng_ust_lock_fd_tracker +#undef lttng_ust_unlock_fd_tracker +#undef lttng_ust_safe_close_fd +#undef lttng_ust_safe_fclose_stream +#undef lttng_ust_safe_closefrom_fd + +int lttng_ust_add_fd_to_tracker1(int fd) + __attribute__ ((alias ("lttng_ust_add_fd_to_tracker_orig"))); +void lttng_ust_delete_fd_from_tracker1(int fd) + __attribute__ ((alias ("lttng_ust_delete_fd_from_tracker_orig"))); +void lttng_ust_lock_fd_tracker1(void) + __attribute__ ((alias ("lttng_ust_lock_fd_tracker_orig"))); +void lttng_ust_unlock_fd_tracker1(void) + __attribute__ ((alias ("lttng_ust_unlock_fd_tracker_orig"))); +int lttng_ust_safe_close_fd1(int fd, int (*close_cb)(int)) + __attribute__ ((alias ("lttng_ust_safe_close_fd_orig"))); +int lttng_ust_safe_fclose_stream1(FILE *stream, int (*fclose_cb)(FILE *stream)) + __attribute__ ((alias ("lttng_ust_safe_fclose_stream_orig"))); +int lttng_ust_safe_closefrom_fd1(int lowfd, int (*close_cb)(int)) + __attribute__ ((alias ("lttng_ust_safe_closefrom_fd_orig"))); + +#ifdef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS +int lttng_ust_add_fd_to_tracker(int fd) + __attribute__ ((alias ("lttng_ust_add_fd_to_tracker_orig"))); +void lttng_ust_delete_fd_from_tracker(int fd) + __attribute__ ((alias ("lttng_ust_delete_fd_from_tracker_orig"))); +void lttng_ust_lock_fd_tracker(void) + __attribute__ ((alias ("lttng_ust_lock_fd_tracker_orig"))); +void lttng_ust_unlock_fd_tracker(void) + __attribute__ ((alias ("lttng_ust_unlock_fd_tracker_orig"))); +int lttng_ust_safe_close_fd(int fd, int (*close_cb)(int)) + __attribute__ ((alias ("lttng_ust_safe_close_fd_orig"))); +int lttng_ust_safe_fclose_stream(FILE *stream, int (*fclose_cb)(FILE *stream)) + __attribute__ ((alias ("lttng_ust_safe_fclose_stream_orig"))); +int lttng_ust_safe_closefrom_fd(int lowfd, int (*close_cb)(int)) + __attribute__ ((alias ("lttng_ust_safe_closefrom_fd_orig"))); +#endif -- 2.34.1 From 606ca558590fb07b57791d2517a31e59b95e440f Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 13 Jun 2022 14:56:53 -0400 Subject: [PATCH 07/16] Custom upgrade: suffix cancelstate symbols with 1 Signed-off-by: Mathieu Desnoyers Change-Id: I107cd5c0a63c9b16498580baf9906520c39d4bfc --- include/lttng/ust-cancelstate.h | 9 +++++++++ src/lib/lttng-ust-common/ust-cancelstate.c | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/lttng/ust-cancelstate.h b/include/lttng/ust-cancelstate.h index efca9ac6..45cbfc58 100644 --- a/include/lttng/ust-cancelstate.h +++ b/include/lttng/ust-cancelstate.h @@ -7,6 +7,15 @@ #ifndef _LTTNG_UST_UST_CANCELSTATE_H #define _LTTNG_UST_UST_CANCELSTATE_H +#include + +/* Custom upgrade 2.12 to 2.13 */ + +#ifndef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS +#define lttng_ust_cancelstate_disable_push lttng_ust_cancelstate_disable_push1 +#define lttng_ust_cancelstate_disable_pop lttng_ust_cancelstate_disable_pop1 +#endif + int lttng_ust_cancelstate_disable_push(void); int lttng_ust_cancelstate_disable_pop(void); diff --git a/src/lib/lttng-ust-common/ust-cancelstate.c b/src/lib/lttng-ust-common/ust-cancelstate.c index e42c7b4e..4c7e24e0 100644 --- a/src/lib/lttng-ust-common/ust-cancelstate.c +++ b/src/lib/lttng-ust-common/ust-cancelstate.c @@ -19,7 +19,7 @@ struct ust_cancelstate { static DEFINE_URCU_TLS(struct ust_cancelstate, thread_state); -int lttng_ust_cancelstate_disable_push(void) +static int lttng_ust_cancelstate_disable_push_orig(void) { struct ust_cancelstate *state = &URCU_TLS(thread_state); int ret, oldstate; @@ -36,7 +36,7 @@ end: return 0; } -int lttng_ust_cancelstate_disable_pop(void) +static int lttng_ust_cancelstate_disable_pop_orig(void) { struct ust_cancelstate *state = &URCU_TLS(thread_state); int ret, oldstate; @@ -58,4 +58,19 @@ end: return 0; } +/* Custom upgrade 2.12 to 2.13 */ + +#undef lttng_ust_cancelstate_disable_push +#undef lttng_ust_cancelstate_disable_pop +int lttng_ust_cancelstate_disable_push1(void) + __attribute ((alias ("lttng_ust_cancelstate_disable_push_orig"))); +int lttng_ust_cancelstate_disable_pop1(void) + __attribute ((alias ("lttng_ust_cancelstate_disable_pop_orig"))); + +#ifdef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS +int lttng_ust_cancelstate_disable_push(void) + __attribute ((alias ("lttng_ust_cancelstate_disable_push_orig"))); +int lttng_ust_cancelstate_disable_pop(void) + __attribute ((alias ("lttng_ust_cancelstate_disable_pop_orig"))); +#endif -- 2.34.1 From 703362671b51300f938284ac50808dcc84c4e1da Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 13 Jun 2022 15:03:47 -0400 Subject: [PATCH 08/16] Custom upgrade: suffix clock plugin symbols with 1 Signed-off-by: Mathieu Desnoyers Change-Id: If197536aec2c555d92e210e8b44d68019c5ddceb --- include/lttng/ust-clock.h | 12 ++++++++ src/lib/lttng-ust-common/clock.c | 49 ++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/include/lttng/ust-clock.h b/include/lttng/ust-clock.h index a5b7176d..32f82ca5 100644 --- a/include/lttng/ust-clock.h +++ b/include/lttng/ust-clock.h @@ -9,6 +9,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -26,6 +27,17 @@ typedef int (*lttng_ust_clock_uuid_function)(char *uuid); typedef const char *(*lttng_ust_clock_name_function)(void); typedef const char *(*lttng_ust_clock_description_function)(void); +/* Custom upgrade 2.12 to 2.13 */ + +#ifndef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS +#define lttng_ust_trace_clock_set_read64_cb lttng_ust_trace_clock_set_read64_cb1 +#define lttng_ust_trace_clock_set_freq_cb lttng_ust_trace_clock_set_freq_cb1 +#define lttng_ust_trace_clock_set_uuid_cb lttng_ust_trace_clock_set_uuid_cb1 +#define lttng_ust_trace_clock_set_name_cb lttng_ust_trace_clock_set_name_cb1 +#define lttng_ust_trace_clock_set_description_cb lttng_ust_trace_clock_set_description_cb1 +#define lttng_ust_enable_trace_clock_override lttng_ust_enable_trace_clock_override1 +#endif + /* * Set/Get clock override read callback. This callback should return the * current clock time (a 64-bit monotonic counter). diff --git a/src/lib/lttng-ust-common/clock.c b/src/lib/lttng-ust-common/clock.c index bf11f262..37a7dc61 100644 --- a/src/lib/lttng-ust-common/clock.c +++ b/src/lib/lttng-ust-common/clock.c @@ -73,7 +73,7 @@ const char *trace_clock_description_monotonic(void) return "Monotonic Clock"; } -int lttng_ust_trace_clock_set_read64_cb(lttng_ust_clock_read64_function read64_cb) +static int lttng_ust_trace_clock_set_read64_cb_orig(lttng_ust_clock_read64_function read64_cb) { if (CMM_LOAD_SHARED(lttng_ust_trace_clock)) return -EBUSY; @@ -94,7 +94,7 @@ int lttng_ust_trace_clock_get_read64_cb(lttng_ust_clock_read64_function *read64_ return 0; } -int lttng_ust_trace_clock_set_freq_cb(lttng_ust_clock_freq_function freq_cb) +static int lttng_ust_trace_clock_set_freq_cb_orig(lttng_ust_clock_freq_function freq_cb) { if (CMM_LOAD_SHARED(lttng_ust_trace_clock)) return -EBUSY; @@ -115,7 +115,7 @@ int lttng_ust_trace_clock_get_freq_cb(lttng_ust_clock_freq_function *freq_cb) return 0; } -int lttng_ust_trace_clock_set_uuid_cb(lttng_ust_clock_uuid_function uuid_cb) +static int lttng_ust_trace_clock_set_uuid_cb_orig(lttng_ust_clock_uuid_function uuid_cb) { if (CMM_LOAD_SHARED(lttng_ust_trace_clock)) return -EBUSY; @@ -136,7 +136,7 @@ int lttng_ust_trace_clock_get_uuid_cb(lttng_ust_clock_uuid_function *uuid_cb) return 0; } -int lttng_ust_trace_clock_set_name_cb(lttng_ust_clock_name_function name_cb) +static int lttng_ust_trace_clock_set_name_cb_orig(lttng_ust_clock_name_function name_cb) { if (CMM_LOAD_SHARED(lttng_ust_trace_clock)) return -EBUSY; @@ -157,7 +157,7 @@ int lttng_ust_trace_clock_get_name_cb(lttng_ust_clock_name_function *name_cb) return 0; } -int lttng_ust_trace_clock_set_description_cb(lttng_ust_clock_description_function description_cb) +static int lttng_ust_trace_clock_set_description_cb_orig(lttng_ust_clock_description_function description_cb) { if (CMM_LOAD_SHARED(lttng_ust_trace_clock)) return -EBUSY; @@ -178,7 +178,7 @@ int lttng_ust_trace_clock_get_description_cb(lttng_ust_clock_description_functio return 0; } -int lttng_ust_enable_trace_clock_override(void) +static int lttng_ust_enable_trace_clock_override_orig(void) { if (CMM_LOAD_SHARED(lttng_ust_trace_clock)) return -EBUSY; @@ -222,3 +222,40 @@ void lttng_ust_clock_init(void) } libinit(); } + +/* Custom upgrade 2.12 to 2.13 */ + +#undef lttng_ust_trace_clock_set_read64_cb +#undef lttng_ust_trace_clock_set_freq_cb +#undef lttng_ust_trace_clock_set_uuid_cb +#undef lttng_ust_trace_clock_set_name_cb +#undef lttng_ust_trace_clock_set_description_cb +#undef lttng_ust_enable_trace_clock_override + +int lttng_ust_trace_clock_set_read64_cb1(lttng_ust_clock_read64_function read64_cb) + __attribute ((alias ("lttng_ust_trace_clock_set_read64_cb_orig"))); +int lttng_ust_trace_clock_set_freq_cb1(lttng_ust_clock_freq_function freq_cb) + __attribute ((alias ("lttng_ust_trace_clock_set_freq_cb_orig"))); +int lttng_ust_trace_clock_set_uuid_cb1(lttng_ust_clock_uuid_function uuid_cb) + __attribute ((alias ("lttng_ust_trace_clock_set_uuid_cb_orig"))); +int lttng_ust_trace_clock_set_name_cb1(lttng_ust_clock_name_function name_cb) + __attribute ((alias ("lttng_ust_trace_clock_set_name_cb_orig"))); +int lttng_ust_trace_clock_set_description_cb1(lttng_ust_clock_description_function description_cb) + __attribute ((alias ("lttng_ust_trace_clock_set_description_cb_orig"))); +int lttng_ust_enable_trace_clock_override1(void) + __attribute ((alias ("lttng_ust_enable_trace_clock_override_orig"))); + +#ifdef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS +int lttng_ust_trace_clock_set_read64_cb(lttng_ust_clock_read64_function read64_cb) + __attribute ((alias ("lttng_ust_trace_clock_set_read64_cb_orig"))); +int lttng_ust_trace_clock_set_freq_cb(lttng_ust_clock_freq_function freq_cb) + __attribute ((alias ("lttng_ust_trace_clock_set_freq_cb_orig"))); +int lttng_ust_trace_clock_set_uuid_cb(lttng_ust_clock_uuid_function uuid_cb) + __attribute ((alias ("lttng_ust_trace_clock_set_uuid_cb_orig"))); +int lttng_ust_trace_clock_set_name_cb(lttng_ust_clock_name_function name_cb) + __attribute ((alias ("lttng_ust_trace_clock_set_name_cb_orig"))); +int lttng_ust_trace_clock_set_description_cb(lttng_ust_clock_description_function description_cb) + __attribute ((alias ("lttng_ust_trace_clock_set_description_cb_orig"))); +int lttng_ust_enable_trace_clock_override(void) + __attribute ((alias ("lttng_ust_enable_trace_clock_override_orig"))); +#endif -- 2.34.1 From c1d5ecdf1a6dd50e6be3387f666c206976f517b4 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 13 Jun 2022 15:06:15 -0400 Subject: [PATCH 09/16] Custom upgrade: suffix getcpu plugin symbol with 1 Signed-off-by: Mathieu Desnoyers Change-Id: I44e451258ff1570bf5f6bbb40650a6059c72811b --- include/lttng/ust-getcpu.h | 7 +++++++ src/lib/lttng-ust-common/getcpu.c | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/lttng/ust-getcpu.h b/include/lttng/ust-getcpu.h index f5f08c6b..efd34f21 100644 --- a/include/lttng/ust-getcpu.h +++ b/include/lttng/ust-getcpu.h @@ -9,6 +9,13 @@ #include #include +#include + +/* Custom upgrade 2.12 to 2.13 */ + +#ifndef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS +#define lttng_ust_getcpu_override lttng_ust_getcpu_override1 +#endif /* * Set getcpu override read callback. This callback should return the diff --git a/src/lib/lttng-ust-common/getcpu.c b/src/lib/lttng-ust-common/getcpu.c index e80bcf1f..748ca391 100644 --- a/src/lib/lttng-ust-common/getcpu.c +++ b/src/lib/lttng-ust-common/getcpu.c @@ -25,7 +25,7 @@ void *getcpu_plugin_handle; /* * Override the user provided getcpu implementation. */ -int lttng_ust_getcpu_override(int (*getcpu)(void)) +static int lttng_ust_getcpu_override_orig(int (*getcpu)(void)) { CMM_STORE_SHARED(lttng_ust_get_cpu_sym, getcpu); return 0; @@ -75,3 +75,14 @@ void lttng_ust_getcpu_plugin_init(void) /* Run the user provided getcpu plugin init function. */ getcpu_plugin_init(); } + +/* Custom upgrade 2.12 to 2.13 */ + +#undef lttng_ust_getcpu_override +int lttng_ust_getcpu_override1(int (*getcpu)(void)) + __attribute__ ((alias ("lttng_ust_getcpu_override_orig"))); + +#ifdef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS +int lttng_ust_getcpu_override(int (*getcpu)(void)) + __attribute__ ((alias ("lttng_ust_getcpu_override_orig"))); +#endif -- 2.34.1 From 12685958a1575577c4e6523c3bad5059a72f1d0a Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 13 Jun 2022 15:54:48 -0400 Subject: [PATCH 10/16] Custom upgrade: remove canary symbols for builds without LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS When the symbols clashing with lttng-ust 2.12 are renamed to be suffixed with "1", it becomes possible to run lttng-ust 2.12 and 2.13 in the same process. Leave those sanity checks in place for builds with LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS defined. Signed-off-by: Mathieu Desnoyers Change-Id: I8664884bdc60043bf28b923786a16ee2ee3301a8 --- src/lib/lttng-ust-tracepoint/tracepoint.c | 5 +++++ src/lib/lttng-ust/lttng-ust-comm.c | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/lib/lttng-ust-tracepoint/tracepoint.c b/src/lib/lttng-ust-tracepoint/tracepoint.c index 12bc561c..47bbb125 100644 --- a/src/lib/lttng-ust-tracepoint/tracepoint.c +++ b/src/lib/lttng-ust-tracepoint/tracepoint.c @@ -21,6 +21,7 @@ #include #include +#include #include #include /* for LTTNG_UST_ABI_SYM_NAME_LEN */ #include @@ -608,6 +609,7 @@ static void tracepoint_release_queue_add_old_probes(void *old) } } +#ifdef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS /* * Use a symbol of the previous ABI to detect if liblttng-ust-tracepoint.so.0 * is loaded in the current process. @@ -640,6 +642,9 @@ int tracepoint_register_lib(void *arg0 __attribute__((unused)), int arg1 __attri return -1; } +#else +static void lttng_ust_tracepoint_check_soname_0(void) {} +#endif /** * lttng_ust_tracepoint_provider_register - Connect a probe to a tracepoint diff --git a/src/lib/lttng-ust/lttng-ust-comm.c b/src/lib/lttng-ust/lttng-ust-comm.c index cf819b80..adb159a3 100644 --- a/src/lib/lttng-ust/lttng-ust-comm.c +++ b/src/lib/lttng-ust/lttng-ust-comm.c @@ -2124,6 +2124,7 @@ void lttng_ust_libc_wrapper_malloc_ctor(void) { } +#ifdef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS /* * Use a symbol of the previous ABI to detect if liblttng-ust.so.0 is loaded in * the current process. @@ -2158,6 +2159,9 @@ void init_usterr(void) "The process is likely linked against different major soname of LTTng-UST which is unsupported. " "The detection was triggered by canary symbol \"%s\"\n", __func__); } +#else +static void lttng_ust_check_soname_0(void) {} +#endif /* * sessiond monitoring thread: monitor presence of global and per-user -- 2.34.1 From aaa692c825f7e9ae975427cd35400e4dd72dc773 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 15 Jun 2022 11:13:35 -0400 Subject: [PATCH 11/16] Custom upgrade: chain load liblttng-ust-{fd,fork}.so.0 with dlopen dlopen liblttng-ust.so.0 in the constructor of the interposer librairies and explicitly call the symbols from this library when appropriate. As a side-note, chain linking the interposer ld_preload librairies on their previous SONAME0 versions doesn't work as expected because the order of the symbol resolution with dlsym always favors the preloaded library symbols. This is why explicit use of dlopen/dlsym is favored instead. Change-Id: Ie8802134c3037cfd431a949f469d3e64e958888b Signed-off-by: Michael Jeanson --- configure.ac | 2 +- src/lib/lttng-ust-common/fd-tracker.c | 81 ++++++- src/lib/lttng-ust-fd/lttng-ust-fd.c | 13 ++ src/lib/lttng-ust-fork/ustfork.c | 314 ++++++++++++++++++++++++++ 4 files changed, 407 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 4dfc011a..4026155b 100644 --- a/configure.ac +++ b/configure.ac @@ -577,7 +577,7 @@ AM_CONDITIONAL([HAVE_CMAKE], [test "x$CMAKE" != "x"]) AM_CONDITIONAL([HAVE_CXX], [test "$HAVE_CXX11" = "1"]) AM_CONDITIONAL([HAVE_JAVAH], [test "x$JAVAH" != "x"]) AM_CONDITIONAL([HAVE_PERF_EVENT], [test "x$ac_cv_header_linux_perf_event_h" = "xyes"]) - +AM_CONDITIONAL([ENABLE_LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS], AE_IS_FEATURE_ENABLED([custom-upgrade-conflicting-symbols])) ## ## ## Substitute variables for use in Makefile.am ## diff --git a/src/lib/lttng-ust-common/fd-tracker.c b/src/lib/lttng-ust-common/fd-tracker.c index 12fcd9cb..d61cfbc9 100644 --- a/src/lib/lttng-ust-common/fd-tracker.c +++ b/src/lib/lttng-ust-common/fd-tracker.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -301,6 +302,35 @@ static void lttng_ust_delete_fd_from_tracker_orig(int fd) DEL_FD_FROM_SET(fd, lttng_fd_set); } +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) +static int (*__lttng_ust_safe_close_fd)(int fd, int (*close_cb)(int fd)) = NULL; + +static +void *_init_lttng_ust_safe_close_fd(void) +{ + if (__lttng_ust_safe_close_fd == NULL) { + __lttng_ust_safe_close_fd = dlsym(RTLD_DEFAULT, "lttng_ust_safe_close_fd"); + + if (__lttng_ust_safe_close_fd == NULL) { + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __lttng_ust_safe_close_fd; +} + +static int lttng_ust_safe_close_fd_chain(int fd, int (*close_cb)(int fd)) +{ + if (_init_lttng_ust_safe_close_fd()) { + /* Chain on ust-2.12 preload */ + return __lttng_ust_safe_close_fd(fd, close_cb); + } else { + /* Fallback to libc symbol */ + return close_cb(fd); + } +} +#endif + /* * Interface allowing applications to close arbitrary file descriptors. * We check if it is owned by lttng-ust, and return -1, errno=EBADF @@ -322,21 +352,59 @@ static int lttng_ust_safe_close_fd_orig(int fd, int (*close_cb)(int fd)) * If called from lttng-ust, we directly call close without * validating whether the FD is part of the tracked set. */ - if (URCU_TLS(ust_fd_mutex_nest)) + if (URCU_TLS(ust_fd_mutex_nest)) { +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + return lttng_ust_safe_close_fd_chain(fd, close_cb); +#else return close_cb(fd); +#endif + } lttng_ust_lock_fd_tracker(); if (IS_FD_VALID(fd) && IS_FD_SET(fd, lttng_fd_set)) { ret = -1; errno = EBADF; } else { +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + ret = lttng_ust_safe_close_fd_chain(fd, close_cb); +#else ret = close_cb(fd); +#endif } lttng_ust_unlock_fd_tracker(); return ret; } +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) +static int (*__lttng_ust_safe_fclose_stream)(FILE *stream, int (*fclose_cb)(FILE *stream)) = NULL; + +static +void *_init_lttng_ust_safe_fclose_stream(void) +{ + if (__lttng_ust_safe_fclose_stream == NULL) { + __lttng_ust_safe_fclose_stream = dlsym(RTLD_DEFAULT, "lttng_ust_safe_fclose_stream"); + + if (__lttng_ust_safe_fclose_stream == NULL) { + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __lttng_ust_safe_fclose_stream; +} + +static int lttng_ust_safe_fclose_stream_chain(FILE *stream, int (*fclose_cb)(FILE *stream)) +{ + if (_init_lttng_ust_safe_fclose_stream()) { + /* Chain on ust-2.12 preload */ + return __lttng_ust_safe_fclose_stream(stream, fclose_cb); + } else { + /* Fallback to libc symbol */ + return fclose_cb(stream); + } +} +#endif + /* * Interface allowing applications to close arbitrary streams. * We check if it is owned by lttng-ust, and return -1, errno=EBADF @@ -358,8 +426,13 @@ static int lttng_ust_safe_fclose_stream_orig(FILE *stream, int (*fclose_cb)(FILE * If called from lttng-ust, we directly call fclose without * validating whether the FD is part of the tracked set. */ - if (URCU_TLS(ust_fd_mutex_nest)) + if (URCU_TLS(ust_fd_mutex_nest)) { +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + return lttng_ust_safe_fclose_stream_chain(stream, fclose_cb); +#else return fclose_cb(stream); +#endif + } fd = fileno(stream); @@ -368,7 +441,11 @@ static int lttng_ust_safe_fclose_stream_orig(FILE *stream, int (*fclose_cb)(FILE ret = -1; errno = EBADF; } else { +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + ret = lttng_ust_safe_fclose_stream_chain(stream, fclose_cb); +#else ret = fclose_cb(stream); +#endif } lttng_ust_unlock_fd_tracker(); diff --git a/src/lib/lttng-ust-fd/lttng-ust-fd.c b/src/lib/lttng-ust-fd/lttng-ust-fd.c index d2ebcfbc..c58ebdb7 100644 --- a/src/lib/lttng-ust-fd/lttng-ust-fd.c +++ b/src/lib/lttng-ust-fd/lttng-ust-fd.c @@ -66,6 +66,19 @@ void _lttng_ust_fd_ctor(void) static void _lttng_ust_fd_ctor(void) { +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + void *handle = NULL; + + /* + * Load ust-2.12 in the global symbol namespace. + */ + handle = dlopen("liblttng-ust.so.0", RTLD_GLOBAL | RTLD_NOW); + if (!handle) { + fprintf(stderr, "liblttng-ust-fd.so.1: Failed to dlopen liblttng-ust.so.0: %s\n", dlerror()); + abort(); + } +#endif + lttng_ust_common_ctor(); /* diff --git a/src/lib/lttng-ust-fork/ustfork.c b/src/lib/lttng-ust-fork/ustfork.c index 321ffc30..ec6974b0 100644 --- a/src/lib/lttng-ust-fork/ustfork.c +++ b/src/lib/lttng-ust-fork/ustfork.c @@ -18,6 +18,223 @@ #include +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) +static int (*__ust_before_fork)(sigset_t *save_sigset) = NULL; +static int (*__ust_after_fork_child)(sigset_t *restore_sigset) = NULL; +static int (*__ust_after_fork_parent)(sigset_t *restore_sigset) = NULL; + +static void (*__ust_after_setns)(void) = NULL; +static void (*__ust_after_unshare)(void) = NULL; +static void (*__ust_after_setuid)(void) = NULL; +static void (*__ust_after_setgid)(void) = NULL; +static void (*__ust_after_seteuid)(void) = NULL; +static void (*__ust_after_setegid)(void) = NULL; +static void (*__ust_after_setreuid)(void) = NULL; +static void (*__ust_after_setregid)(void) = NULL; +static void (*__ust_after_setresuid)(void) = NULL; +static void (*__ust_after_setresgid)(void) = NULL; + +static +void *_init_ust_before_fork(void) +{ + if (__ust_before_fork == NULL) { + __ust_before_fork = dlsym(RTLD_DEFAULT, "ust_before_fork"); + + if (__ust_before_fork == NULL) { + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __ust_before_fork; +} + +static +void *_init_ust_after_fork_child(void) +{ + if (__ust_after_fork_child == NULL) { + __ust_after_fork_child = dlsym(RTLD_DEFAULT, "ust_after_fork_child"); + + if (__ust_after_fork_child == NULL) { + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __ust_after_fork_child; +} + +static +void *_init_ust_after_fork_parent(void) +{ + if (__ust_after_fork_parent == NULL) { + __ust_after_fork_parent = dlsym(RTLD_DEFAULT, "ust_after_fork_parent"); + + if (__ust_after_fork_parent == NULL) { + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __ust_after_fork_parent; +} + +static +void *_init_ust_after_setns(void) +{ + if (__ust_after_setns == NULL) { + __ust_after_setns = dlsym(RTLD_DEFAULT, "ust_after_setns"); + + if (__ust_after_setns == NULL) { + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __ust_after_setns; +} + +static +void *_init_ust_after_unshare(void) +{ + if (__ust_after_unshare == NULL) { + __ust_after_unshare = dlsym(RTLD_DEFAULT, "ust_after_unshare"); + + if (__ust_after_unshare == NULL) { + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __ust_after_unshare; +} + +static +void *_init_ust_after_setuid(void) +{ + if (__ust_after_setuid == NULL) { + __ust_after_setuid = dlsym(RTLD_DEFAULT, "ust_after_setuid"); + + if (__ust_after_setuid == NULL) { + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __ust_after_setuid; +} + +static +void *_init_ust_after_setgid(void) +{ + if (__ust_after_setgid == NULL) { + __ust_after_setgid = dlsym(RTLD_DEFAULT, "ust_after_setgid"); + + if (__ust_after_setgid == NULL) { + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __ust_after_setgid; +} + +static +void *_init_ust_after_seteuid(void) +{ + if (__ust_after_seteuid == NULL) { + __ust_after_seteuid = dlsym(RTLD_DEFAULT, "ust_after_seteuid"); + + if (__ust_after_seteuid == NULL) { + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __ust_after_seteuid; +} + +static +void *_init_ust_after_setegid(void) +{ + if (__ust_after_setegid == NULL) { + __ust_after_setegid = dlsym(RTLD_DEFAULT, "ust_after_setegid"); + + if (__ust_after_setegid == NULL) { + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __ust_after_setegid; +} + +static +void *_init_ust_after_setreuid(void) +{ + if (__ust_after_setreuid == NULL) { + __ust_after_setreuid = dlsym(RTLD_DEFAULT, "ust_after_setreuid"); + + if (__ust_after_setreuid == NULL) { + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __ust_after_setreuid; +} + +static +void *_init_ust_after_setregid(void) +{ + if (__ust_after_setregid == NULL) { + __ust_after_setregid = dlsym(RTLD_DEFAULT, "ust_after_setregid"); + + if (__ust_after_setregid == NULL) { + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __ust_after_setregid; +} + +static +void *_init_ust_after_setresuid(void) +{ + if (__ust_after_setresuid == NULL) { + __ust_after_setresuid = dlsym(RTLD_DEFAULT, "ust_after_setresuid"); + + if (__ust_after_setresuid == NULL) { + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __ust_after_setresuid; +} + +static +void *_init_ust_after_setresgid(void) +{ + if (__ust_after_setresgid == NULL) { + __ust_after_setresgid = dlsym(RTLD_DEFAULT, "ust_after_setresgid"); + + if (__ust_after_setresgid == NULL) { + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __ust_after_setresgid; +} + +static +void _lttng_ust_fork_ctor(void) + __attribute__((constructor)); +static +void _lttng_ust_fork_ctor(void) +{ + void *handle = NULL; + + /* + * Load ust-2.12 in the global symbol namespace. + */ + handle = dlopen("liblttng-ust.so.0", RTLD_GLOBAL | RTLD_NOW); + if (!handle) { + fprintf(stderr, "liblttng-ust-fork.so.1: Failed to dlopen liblttng-ust.so.0: %s\n", dlerror()); + abort(); + } +} +#endif + pid_t fork(void) { static pid_t (*plibc_func)(void) = NULL; @@ -35,14 +252,30 @@ pid_t fork(void) } lttng_ust_before_fork(&sigset); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_before_fork()) { + __ust_before_fork(&sigset); + } +#endif + /* Do the real fork */ retval = plibc_func(); saved_errno = errno; if (retval == 0) { /* child */ lttng_ust_after_fork_child(&sigset); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_fork_child()) { + __ust_after_fork_child(&sigset); + } +#endif } else { lttng_ust_after_fork_parent(&sigset); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_fork_parent()) { + __ust_after_fork_parent(&sigset); + } +#endif } errno = saved_errno; return retval; @@ -65,15 +298,31 @@ int daemon(int nochdir, int noclose) } lttng_ust_before_fork(&sigset); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_before_fork()) { + __ust_before_fork(&sigset); + } +#endif + /* Do the real daemon call */ retval = plibc_func(nochdir, noclose); saved_errno = errno; if (retval == 0) { /* child, parent called _exit() directly */ lttng_ust_after_fork_child(&sigset); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_fork_child()) { + __ust_after_fork_child(&sigset); + } +#endif } else { /* on error in the parent */ lttng_ust_after_fork_parent(&sigset); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_fork_parent()) { + __ust_after_fork_parent(&sigset); + } +#endif } errno = saved_errno; return retval; @@ -99,6 +348,11 @@ int setuid(uid_t uid) saved_errno = errno; lttng_ust_after_setuid(); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_setuid()) { + __ust_after_setuid(); + } +#endif errno = saved_errno; return retval; @@ -124,6 +378,11 @@ int setgid(gid_t gid) saved_errno = errno; lttng_ust_after_setgid(); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_setgid()) { + __ust_after_setgid(); + } +#endif errno = saved_errno; return retval; @@ -149,6 +408,11 @@ int seteuid(uid_t euid) saved_errno = errno; lttng_ust_after_seteuid(); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_seteuid()) { + __ust_after_seteuid(); + } +#endif errno = saved_errno; return retval; @@ -174,6 +438,11 @@ int setegid(gid_t egid) saved_errno = errno; lttng_ust_after_setegid(); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_setegid()) { + __ust_after_setegid(); + } +#endif errno = saved_errno; return retval; @@ -199,6 +468,11 @@ int setreuid(uid_t ruid, uid_t euid) saved_errno = errno; lttng_ust_after_setreuid(); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_setreuid()) { + __ust_after_setreuid(); + } +#endif errno = saved_errno; return retval; @@ -224,6 +498,11 @@ int setregid(gid_t rgid, gid_t egid) saved_errno = errno; lttng_ust_after_setregid(); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_setregid()) { + __ust_after_setregid(); + } +#endif errno = saved_errno; return retval; @@ -245,6 +524,11 @@ static int clone_fn(void *arg) /* clone is now done and we are in child */ lttng_ust_after_fork_child(&info->sigset); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_fork_child()) { + __ust_after_fork_child(&info->sigset); + } +#endif return info->fn(info->arg); } @@ -290,11 +574,21 @@ int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...) struct ustfork_clone_info info = { .fn = fn, .arg = arg }; lttng_ust_before_fork(&info.sigset); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_before_fork()) { + __ust_before_fork(&info.sigset); + } +#endif retval = plibc_func(clone_fn, child_stack, flags, &info, ptid, tls, ctid); saved_errno = errno; /* The child doesn't get here. */ lttng_ust_after_fork_parent(&info.sigset); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_fork_parent()) { + __ust_after_fork_parent(&info.sigset); + } +#endif } errno = saved_errno; return retval; @@ -320,6 +614,11 @@ int setns(int fd, int nstype) saved_errno = errno; lttng_ust_after_setns(); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_setns()) { + __ust_after_setns(); + } +#endif errno = saved_errno; return retval; @@ -345,6 +644,11 @@ int unshare(int flags) saved_errno = errno; lttng_ust_after_unshare(); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_unshare()) { + __ust_after_unshare(); + } +#endif errno = saved_errno; return retval; @@ -370,6 +674,11 @@ int setresuid(uid_t ruid, uid_t euid, uid_t suid) saved_errno = errno; lttng_ust_after_setresuid(); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_setresuid()) { + __ust_after_setresuid(); + } +#endif errno = saved_errno; return retval; @@ -395,6 +704,11 @@ int setresgid(gid_t rgid, gid_t egid, gid_t sgid) saved_errno = errno; lttng_ust_after_setresgid(); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) + if (_init_ust_after_setresgid()) { + __ust_after_setresgid(); + } +#endif errno = saved_errno; return retval; -- 2.34.1 From b9a2af20bf61fed1c72e1c7d9bcbe1938e3f7ecf Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Thu, 29 Sep 2022 16:05:55 +0000 Subject: [PATCH 12/16] Custom upgrade: disable ABI conflict tests This test is not appropriate for this custom upgrade branch. Change-Id: I1b97a9f52fb94a65a65db65f34a84abf8bb2a874 Signed-off-by: Michael Jeanson --- tests/Makefile.am | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index ac4d1cc9..e27da34e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -31,9 +31,6 @@ endif # Regression tests -TESTS += \ - regression/abi0-conflict/test_abi0_conflict - EXTRA_DIST = README check-loop: -- 2.34.1 From 5f748425825e61bb96d55a07bafbd3f3afe4e501 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 4 Oct 2022 13:04:38 -0400 Subject: [PATCH 13/16] Fix: lazily dlopen 2.12 lttng-ust from liblttng-ust-fd.so symbol overrides Fix warnings: /usr/lib64/liblttng-ust-common.so.1: undefined symbol: lttng_ust_safe_close_fd Lazily dlopen liblttng-ust.so.0 when close/fclose are used early before execution of liblttng-ust-fd.so's constructor, and use it to perform the perform the required dlsym() lookups to find the 2.12 LTTng-UST symbols. Also perform these dlopen/dlsym intialization operations from liblttng-ust-fd.so's contructor, so if close() is used from a signal handler, it does not have to invoke dlopen()/dlsym() which are not async-signal-safe. Add compiler #error around closefrom() which is only emitted on Solaris and BSDs, and not relevant to the 2.13 custom upgrade scope. Signed-off-by: Mathieu Desnoyers Change-Id: I292434328f512bbb284c97f6a6170edbeef7c222 --- src/lib/lttng-ust-common/fd-tracker.c | 138 ++++++++++++++------------ src/lib/lttng-ust-common/fd-tracker.h | 5 + src/lib/lttng-ust-fd/lttng-ust-fd.c | 51 ++++++++-- 3 files changed, 118 insertions(+), 76 deletions(-) diff --git a/src/lib/lttng-ust-common/fd-tracker.c b/src/lib/lttng-ust-common/fd-tracker.c index d61cfbc9..c47dc1fc 100644 --- a/src/lib/lttng-ust-common/fd-tracker.c +++ b/src/lib/lttng-ust-common/fd-tracker.c @@ -34,6 +34,8 @@ #include "lib/lttng-ust-common/fd-tracker.h" +#define LTTNG_UST_DLSYM_FAILED_PTR 0x1 + /* Operations on the fd set. */ #define IS_FD_VALID(fd) ((fd) >= 0 && (fd) < lttng_ust_max_fd) #define GET_FD_SET_FOR_FD(fd, fd_sets) (&((fd_sets)[(fd) / FD_SETSIZE])) @@ -80,6 +82,76 @@ void lttng_ust_fd_tracker_alloc_tls(void) asm volatile ("" : : "m" (URCU_TLS(ust_fd_mutex_nest))); } +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) +static int (*__lttng_ust_safe_close_fd)(int fd, int (*close_cb)(int fd)) = NULL; + +void *lttng_ust_safe_close_fd_init(void) +{ + if (__lttng_ust_safe_close_fd == NULL) { + __lttng_ust_safe_close_fd = dlsym(RTLD_DEFAULT, "lttng_ust_safe_close_fd"); + + if (__lttng_ust_safe_close_fd == NULL) { + __lttng_ust_safe_close_fd = (void *) LTTNG_UST_DLSYM_FAILED_PTR; + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __lttng_ust_safe_close_fd; +} + +static int lttng_ust_safe_close_fd_chain(int fd, int (*close_cb)(int fd)) +{ + assert(__lttng_ust_safe_close_fd != NULL); + if (__lttng_ust_safe_close_fd != (void *) LTTNG_UST_DLSYM_FAILED_PTR) { + /* Chain on ust-2.12 preload */ + return __lttng_ust_safe_close_fd(fd, close_cb); + } else { + /* Fallback to libc symbol */ + return close_cb(fd); + } +} +#else +static int lttng_ust_safe_close_fd_chain(int fd, int (*close_cb)(int fd)) +{ + return close_cb(fd); +} +#endif + +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) +static int (*__lttng_ust_safe_fclose_stream)(FILE *stream, int (*fclose_cb)(FILE *stream)) = NULL; + +void *lttng_ust_safe_fclose_stream_init(void) +{ + if (__lttng_ust_safe_fclose_stream == NULL) { + __lttng_ust_safe_fclose_stream = dlsym(RTLD_DEFAULT, "lttng_ust_safe_fclose_stream"); + + if (__lttng_ust_safe_fclose_stream == NULL) { + __lttng_ust_safe_fclose_stream = (void *) LTTNG_UST_DLSYM_FAILED_PTR; + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __lttng_ust_safe_fclose_stream; +} + +static int lttng_ust_safe_fclose_stream_chain(FILE *stream, int (*fclose_cb)(FILE *stream)) +{ + assert(__lttng_ust_safe_fclose_stream != NULL); + if (__lttng_ust_safe_fclose_stream != (void *) LTTNG_UST_DLSYM_FAILED_PTR) { + /* Chain on ust-2.12 preload */ + return __lttng_ust_safe_fclose_stream(stream, fclose_cb); + } else { + /* Fallback to libc symbol */ + return fclose_cb(stream); + } +} +#else +static int lttng_ust_safe_fclose_stream_chain(FILE *stream, int (*fclose_cb)(FILE *stream)) +{ + return fclose_cb(stream); +} +#endif + /* * Allocate the fd set array based on the hard limit set for this * process. This will be called during the constructor execution @@ -302,35 +374,6 @@ static void lttng_ust_delete_fd_from_tracker_orig(int fd) DEL_FD_FROM_SET(fd, lttng_fd_set); } -#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) -static int (*__lttng_ust_safe_close_fd)(int fd, int (*close_cb)(int fd)) = NULL; - -static -void *_init_lttng_ust_safe_close_fd(void) -{ - if (__lttng_ust_safe_close_fd == NULL) { - __lttng_ust_safe_close_fd = dlsym(RTLD_DEFAULT, "lttng_ust_safe_close_fd"); - - if (__lttng_ust_safe_close_fd == NULL) { - fprintf(stderr, "%s\n", dlerror()); - } - } - - return __lttng_ust_safe_close_fd; -} - -static int lttng_ust_safe_close_fd_chain(int fd, int (*close_cb)(int fd)) -{ - if (_init_lttng_ust_safe_close_fd()) { - /* Chain on ust-2.12 preload */ - return __lttng_ust_safe_close_fd(fd, close_cb); - } else { - /* Fallback to libc symbol */ - return close_cb(fd); - } -} -#endif - /* * Interface allowing applications to close arbitrary file descriptors. * We check if it is owned by lttng-ust, and return -1, errno=EBADF @@ -365,46 +408,13 @@ static int lttng_ust_safe_close_fd_orig(int fd, int (*close_cb)(int fd)) ret = -1; errno = EBADF; } else { -#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) ret = lttng_ust_safe_close_fd_chain(fd, close_cb); -#else - ret = close_cb(fd); -#endif } lttng_ust_unlock_fd_tracker(); return ret; } -#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) -static int (*__lttng_ust_safe_fclose_stream)(FILE *stream, int (*fclose_cb)(FILE *stream)) = NULL; - -static -void *_init_lttng_ust_safe_fclose_stream(void) -{ - if (__lttng_ust_safe_fclose_stream == NULL) { - __lttng_ust_safe_fclose_stream = dlsym(RTLD_DEFAULT, "lttng_ust_safe_fclose_stream"); - - if (__lttng_ust_safe_fclose_stream == NULL) { - fprintf(stderr, "%s\n", dlerror()); - } - } - - return __lttng_ust_safe_fclose_stream; -} - -static int lttng_ust_safe_fclose_stream_chain(FILE *stream, int (*fclose_cb)(FILE *stream)) -{ - if (_init_lttng_ust_safe_fclose_stream()) { - /* Chain on ust-2.12 preload */ - return __lttng_ust_safe_fclose_stream(stream, fclose_cb); - } else { - /* Fallback to libc symbol */ - return fclose_cb(stream); - } -} -#endif - /* * Interface allowing applications to close arbitrary streams. * We check if it is owned by lttng-ust, and return -1, errno=EBADF @@ -441,11 +451,7 @@ static int lttng_ust_safe_fclose_stream_orig(FILE *stream, int (*fclose_cb)(FILE ret = -1; errno = EBADF; } else { -#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) ret = lttng_ust_safe_fclose_stream_chain(stream, fclose_cb); -#else - ret = fclose_cb(stream); -#endif } lttng_ust_unlock_fd_tracker(); diff --git a/src/lib/lttng-ust-common/fd-tracker.h b/src/lib/lttng-ust-common/fd-tracker.h index 2432eaa4..657d99eb 100644 --- a/src/lib/lttng-ust-common/fd-tracker.h +++ b/src/lib/lttng-ust-common/fd-tracker.h @@ -13,4 +13,9 @@ void lttng_ust_fd_tracker_init(void) void lttng_ust_fd_tracker_alloc_tls(void) __attribute__((visibility("hidden"))); +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) +void *lttng_ust_safe_close_fd_init(void); +void *lttng_ust_safe_fclose_stream_init(void); +#endif + #endif diff --git a/src/lib/lttng-ust-fd/lttng-ust-fd.c b/src/lib/lttng-ust-fd/lttng-ust-fd.c index c58ebdb7..af208a98 100644 --- a/src/lib/lttng-ust-fd/lttng-ust-fd.c +++ b/src/lib/lttng-ust-fd/lttng-ust-fd.c @@ -16,6 +16,7 @@ #include "common/macros.h" #include "common/ust-fd.h" +#include "lib/lttng-ust-common/fd-tracker.h" #define LTTNG_UST_DLSYM_FAILED_PTR 0x1 @@ -60,25 +61,44 @@ void *_lttng_ust_fd_init_plibc_fclose(void) return __lttng_ust_fd_plibc_fclose; } -static -void _lttng_ust_fd_ctor(void) - __attribute__((constructor)); -static -void _lttng_ust_fd_ctor(void) -{ #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) - void *handle = NULL; +static void *lttng_ust_2_12_handle; + +static +void lttng_ust_init_close_chaining(void) +{ + if (lttng_ust_2_12_handle) + return; /* * Load ust-2.12 in the global symbol namespace. */ - handle = dlopen("liblttng-ust.so.0", RTLD_GLOBAL | RTLD_NOW); - if (!handle) { + lttng_ust_2_12_handle = dlopen("liblttng-ust.so.0", RTLD_GLOBAL | RTLD_NOW); + if (!lttng_ust_2_12_handle) { fprintf(stderr, "liblttng-ust-fd.so.1: Failed to dlopen liblttng-ust.so.0: %s\n", dlerror()); abort(); } + /* + * Initialize the function pointers to the ust 2.12 symbols in + * the constructor since close() has to stay async-signal-safe + * and as such, we can't call dlsym() in the override functions. + */ + (void) lttng_ust_safe_close_fd_init(); + (void) lttng_ust_safe_fclose_stream_init(); +} +#else +static +void lttng_ust_init_close_chaining(void) { } #endif +static +void _lttng_ust_fd_ctor(void) + __attribute__((constructor)); +static +void _lttng_ust_fd_ctor(void) +{ + lttng_ust_init_close_chaining(); + lttng_ust_common_ctor(); /* @@ -99,10 +119,13 @@ void _lttng_ust_fd_ctor(void) * errno=ENOSYS. * * There is a short window before the library constructor has executed where - * this wrapper could call dlsym() and thus not be async-signal-safe. + * this wrapper could call dlsym() and dlopen() and thus not be + * async-signal-safe. */ int close(int fd) { + lttng_ust_init_close_chaining(); + /* * We can't retry dlsym here since close is async-signal-safe. */ @@ -131,6 +154,8 @@ int close(int fd) */ int fclose(FILE *stream) { + lttng_ust_init_close_chaining(); + if (_lttng_ust_fd_init_plibc_fclose() == (void *) LTTNG_UST_DLSYM_FAILED_PTR) { errno = ENOSYS; return -1; @@ -141,6 +166,9 @@ int fclose(FILE *stream) } #if defined(__sun__) || defined(__FreeBSD__) + +#error "Custom upgrade branch does not support Solaris/FreeBSD closefrom" + /* Solaris and FreeBSD. */ void closefrom(int lowfd) { @@ -151,6 +179,9 @@ void closefrom(int lowfd) (void) lttng_ust_safe_closefrom_fd(lowfd, __lttng_ust_fd_plibc_close); } #elif defined(__NetBSD__) || defined(__OpenBSD__) + +#error "Custom upgrade branch does not support NetBSD/OpenBSD closefrom" + /* NetBSD and OpenBSD. */ int closefrom(int lowfd) { -- 2.34.1 From 0cab898d2e887eb164d4559efd82ab879e0c4062 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 4 Oct 2022 13:05:01 -0400 Subject: [PATCH 14/16] Fix: ust-fork: reverse order of "after" callbacks The "after" callbacks restore the pthread cancelstate to the prior state, and warn on the application console when LTTNG_UST_DEBUG=1 is set if the cancelstate restored does not match the cancelstate saved. It is therefore important that we keep the following order: - begin callback (2.13) - begin callback (2.12) ... - after callback (2.12) - after callback (2.13) to preserve the correct nesting of saved/restored pthread cancelstate. Signed-off-by: Mathieu Desnoyers Change-Id: Id95792654d514e0dcd09c00ff5dc0d220fb27f87 --- src/lib/lttng-ust-fork/ustfork.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/lib/lttng-ust-fork/ustfork.c b/src/lib/lttng-ust-fork/ustfork.c index ec6974b0..b3b182dd 100644 --- a/src/lib/lttng-ust-fork/ustfork.c +++ b/src/lib/lttng-ust-fork/ustfork.c @@ -263,19 +263,19 @@ pid_t fork(void) saved_errno = errno; if (retval == 0) { /* child */ - lttng_ust_after_fork_child(&sigset); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_fork_child()) { __ust_after_fork_child(&sigset); } #endif + lttng_ust_after_fork_child(&sigset); } else { - lttng_ust_after_fork_parent(&sigset); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_fork_parent()) { __ust_after_fork_parent(&sigset); } #endif + lttng_ust_after_fork_parent(&sigset); } errno = saved_errno; return retval; @@ -309,20 +309,20 @@ int daemon(int nochdir, int noclose) saved_errno = errno; if (retval == 0) { /* child, parent called _exit() directly */ - lttng_ust_after_fork_child(&sigset); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_fork_child()) { __ust_after_fork_child(&sigset); } #endif + lttng_ust_after_fork_child(&sigset); } else { /* on error in the parent */ - lttng_ust_after_fork_parent(&sigset); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_fork_parent()) { __ust_after_fork_parent(&sigset); } #endif + lttng_ust_after_fork_parent(&sigset); } errno = saved_errno; return retval; @@ -347,12 +347,12 @@ int setuid(uid_t uid) retval = plibc_func(uid); saved_errno = errno; - lttng_ust_after_setuid(); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_setuid()) { __ust_after_setuid(); } #endif + lttng_ust_after_setuid(); errno = saved_errno; return retval; @@ -377,12 +377,12 @@ int setgid(gid_t gid) retval = plibc_func(gid); saved_errno = errno; - lttng_ust_after_setgid(); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_setgid()) { __ust_after_setgid(); } #endif + lttng_ust_after_setgid(); errno = saved_errno; return retval; @@ -407,12 +407,12 @@ int seteuid(uid_t euid) retval = plibc_func(euid); saved_errno = errno; - lttng_ust_after_seteuid(); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_seteuid()) { __ust_after_seteuid(); } #endif + lttng_ust_after_seteuid(); errno = saved_errno; return retval; @@ -437,12 +437,12 @@ int setegid(gid_t egid) retval = plibc_func(egid); saved_errno = errno; - lttng_ust_after_setegid(); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_setegid()) { __ust_after_setegid(); } #endif + lttng_ust_after_setegid(); errno = saved_errno; return retval; @@ -467,12 +467,12 @@ int setreuid(uid_t ruid, uid_t euid) retval = plibc_func(ruid, euid); saved_errno = errno; - lttng_ust_after_setreuid(); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_setreuid()) { __ust_after_setreuid(); } #endif + lttng_ust_after_setreuid(); errno = saved_errno; return retval; @@ -497,12 +497,12 @@ int setregid(gid_t rgid, gid_t egid) retval = plibc_func(rgid, egid); saved_errno = errno; - lttng_ust_after_setregid(); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_setregid()) { __ust_after_setregid(); } #endif + lttng_ust_after_setregid(); errno = saved_errno; return retval; @@ -523,12 +523,12 @@ static int clone_fn(void *arg) struct ustfork_clone_info *info = (struct ustfork_clone_info *) arg; /* clone is now done and we are in child */ - lttng_ust_after_fork_child(&info->sigset); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_fork_child()) { __ust_after_fork_child(&info->sigset); } #endif + lttng_ust_after_fork_child(&info->sigset); return info->fn(info->arg); } @@ -583,12 +583,12 @@ int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...) ptid, tls, ctid); saved_errno = errno; /* The child doesn't get here. */ - lttng_ust_after_fork_parent(&info.sigset); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_fork_parent()) { __ust_after_fork_parent(&info.sigset); } #endif + lttng_ust_after_fork_parent(&info.sigset); } errno = saved_errno; return retval; @@ -613,12 +613,12 @@ int setns(int fd, int nstype) retval = plibc_func(fd, nstype); saved_errno = errno; - lttng_ust_after_setns(); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_setns()) { __ust_after_setns(); } #endif + lttng_ust_after_setns(); errno = saved_errno; return retval; @@ -643,12 +643,12 @@ int unshare(int flags) retval = plibc_func(flags); saved_errno = errno; - lttng_ust_after_unshare(); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_unshare()) { __ust_after_unshare(); } #endif + lttng_ust_after_unshare(); errno = saved_errno; return retval; @@ -673,12 +673,12 @@ int setresuid(uid_t ruid, uid_t euid, uid_t suid) retval = plibc_func(ruid, euid, suid); saved_errno = errno; - lttng_ust_after_setresuid(); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_setresuid()) { __ust_after_setresuid(); } #endif + lttng_ust_after_setresuid(); errno = saved_errno; return retval; @@ -703,12 +703,12 @@ int setresgid(gid_t rgid, gid_t egid, gid_t sgid) retval = plibc_func(rgid, egid, sgid); saved_errno = errno; - lttng_ust_after_setresgid(); #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) if (_init_ust_after_setresgid()) { __ust_after_setresgid(); } #endif + lttng_ust_after_setresgid(); errno = saved_errno; return retval; -- 2.34.1 From a1139084ed6e30dc39f717a58630df4d5e6cb615 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 4 Oct 2022 16:25:52 -0400 Subject: [PATCH 15/16] Fix: Use 2.12 custom mutex nest getter Eliminate the following deadlock by calling libc close directly when called from within the 2.12 fd tracker locking. The 2.13 locks always need to be taken outside of the 2.12 locks. In the scenario below, Thread 3 (lttng-ust 2.12 listener thread) takes the locks in the wrong order. This fix depends on custom commit "Add ust fd mutex nesting getter" in LTTng-UST 2.12. Thread 3 (Thread 0x7f7679247700 (LWP 621683) "hello-ust"): #0 __lll_lock_wait (futex=futex@entry=0x7f767a392b60 , private=0) at lowlevellock.c:52 #1 0x00007f767a39d843 in __GI___pthread_mutex_lock (mutex=0x7f767a392b60 ) at ../nptl/pthread_mutex_lock.c:80 -> 2.13 locks fd tracker 2.13 #2 0x00007f767a37ff82 in lttng_ust_lock_fd_tracker_orig () at fd-tracker.c:163 2.13 #3 0x00007f767a380b66 in lttng_ust_safe_close_fd_orig (fd=3, close_cb=0x7f767a56b070 <__GI___close>) at fd-tracker.c:385 2.13 #4 0x00007f767a6e5557 in close (fd=3) at lttng-ust-fd.c:101 2.12 #5 0x00007f767a297e7d in ustcomm_connect_unix_sock (pathname=0x7f767a32bc64 "/home/compudj/.lttng/lttng-ust-sock-8", timeout=3000) at lttng-ust-comm.c:157 -> 2.12 listener thread locks fd tracker -> 2.12 listener thread locks ust_lock 2.12 #6 0x00007f767a2a1f77 in ust_listener_thread (arg=0x7f767a32bc40 ) at lttng-ust-comm.c:1591 #7 0x00007f767a39aea7 in start_thread (arg=) at pthread_create.c:477 #8 0x00007f767a57aaef in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 Thread 2 (Thread 0x7f7678a46700 (LWP 621682) "hello-ust"): #0 __lll_lock_wait (futex=futex@entry=0x7f767a32f780 , private=0) at lowlevellock.c:52 #1 0x00007f767a39d843 in __GI___pthread_mutex_lock (mutex=0x7f767a32f780 ) at ../nptl/pthread_mutex_lock.c:80 2.12 #2 0x00007f767a29da59 in ust_lock () at lttng-ust-comm.c:167 2.12 #3 0x00007f767a2a1d95 in ust_listener_thread (arg=0x7f767a329be0 ) at lttng-ust-comm.c:1558 #4 0x00007f767a39aea7 in start_thread (arg=) at pthread_create.c:477 #5 0x00007f767a57aaef in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 Thread 1 (Thread 0x7f767a33a040 (LWP 621681) "hello"): #0 __lll_lock_wait (futex=futex@entry=0x7f767a32f720 , private=0) at lowlevellock.c:52 #1 0x00007f767a39d843 in __GI___pthread_mutex_lock (mutex=0x7f767a32f720 ) at ../nptl/pthread_mutex_lock.c:80 -> 2.12 lock fd tracker 2.12 #2 0x00007f767a29c37c in lttng_ust_lock_fd_tracker () at lttng-ust-fd-tracker.c:153 2.12 #3 0x00007f767a29ceba in lttng_ust_safe_close_fd (fd=4, close_cb=0x7f767a56b070 <__GI___close>) at lttng-ust-fd-tracker.c:341 2.13 #4 0x00007f767a380b06 in lttng_ust_safe_close_fd_chain (fd=4, close_cb=0x7f767a56b070 <__GI___close>) at fd-tracker.c:348 2.13 #5 0x00007f767a380b5c in lttng_ust_safe_close_fd_orig (fd=4, close_cb=0x7f767a56b070 <__GI___close>) at fd-tracker.c:379 2.13 #6 0x00007f767a6e5557 in close (fd=4) at lttng-ust-fd.c:101 -> 2.13 lock fd tracker 2.13 #7 0x00007f767a43b5e6 in lttng_ust_elf_destroy (elf=0x55b870f044c0) at elf.c:352 2.13 #8 0x00007f767a3f2797 in get_elf_info (bin_data=0x7ffd5481ef70) at lttng-ust-statedump.c:296 2.13 #9 0x00007f767a3f283f in extract_baddr (bin_data=0x7ffd5481ef70) at lttng-ust-statedump.c:319 2.13 #10 0x00007f767a3f3173 in extract_bin_info_events (info=0x7ffd5481fff0, size=64, _data=0x7ffd54820098) at lttng-ust-statedump.c:518 #11 0x00007f767a5b3ad5 in __GI___dl_iterate_phdr (callback=0x7f767a3f2f5a , data=0x7ffd54820098) at dl-iteratephdr.c:75 2.13 #12 0x00007f767a3f32c5 in lttng_ust_dl_update_orig (ip=0x7f767a3cb599 ) at lttng-ust-statedump.c:574 2.13 #13 0x00007f767a3f33f7 in lttng_ust_statedump_init () at lttng-ust-statedump.c:638 2.13 #14 0x00007f767a3cb599 in lttng_ust_ctor () at lttng-ust-comm.c:2246 2.13 #15 0x00007f767a3ccaad in lttng_ust_after_fork_child (restore_sigset=0x7ffd548207e0) at lttng-ust-comm.c:2577 2.13 #16 0x00007f767a6f687f in fork () at ustfork.c:271 #17 0x000055b8705f1034 in make_child () #18 0x000055b8705daacc in execute_command_internal () #19 0x000055b8705ddcf5 in execute_command () #20 0x000055b8705df951 in ?? () #21 0x000055b8705daf79 in execute_command_internal () #22 0x000055b8705ddcf5 in execute_command () #23 0x000055b8705c49db in reader_loop () #24 0x000055b8705c3668 in main () Signed-off-by: Mathieu Desnoyers Change-Id: Ife72c3532dde1357c6c7937aa4c5d8135fd52e84 --- src/lib/lttng-ust-common/fd-tracker.c | 48 +++++++++++++++++++-------- src/lib/lttng-ust-common/fd-tracker.h | 1 + src/lib/lttng-ust-fd/lttng-ust-fd.c | 1 + 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/lib/lttng-ust-common/fd-tracker.c b/src/lib/lttng-ust-common/fd-tracker.c index c47dc1fc..4a527ee5 100644 --- a/src/lib/lttng-ust-common/fd-tracker.c +++ b/src/lib/lttng-ust-common/fd-tracker.c @@ -374,6 +374,38 @@ static void lttng_ust_delete_fd_from_tracker_orig(int fd) DEL_FD_FROM_SET(fd, lttng_fd_set); } +#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) +/* lttng-ust 2.12 (custom branch) getter */ +static int (*__lttng_ust_get_fd_mutex_nest)(void) = NULL; + +void *lttng_ust_get_fd_mutex_nest_init(void) +{ + if (__lttng_ust_get_fd_mutex_nest == NULL) { + __lttng_ust_get_fd_mutex_nest = dlsym(RTLD_DEFAULT, "lttng_ust_get_fd_mutex_nest"); + + if (__lttng_ust_get_fd_mutex_nest == NULL) { + __lttng_ust_get_fd_mutex_nest = (void *) LTTNG_UST_DLSYM_FAILED_PTR; + fprintf(stderr, "%s\n", dlerror()); + } + } + + return __lttng_ust_get_fd_mutex_nest; +} + +static int lttng_ust_get_fd_mutex_nest_chain(void) +{ + assert(__lttng_ust_get_fd_mutex_nest != NULL); + if (__lttng_ust_get_fd_mutex_nest != (void *) LTTNG_UST_DLSYM_FAILED_PTR) + return __lttng_ust_get_fd_mutex_nest(); + return 0; +} +#else +static int lttng_ust_get_fd_mutex_nest_chain(void) +{ + return 0; +} +#endif + /* * Interface allowing applications to close arbitrary file descriptors. * We check if it is owned by lttng-ust, and return -1, errno=EBADF @@ -395,13 +427,8 @@ static int lttng_ust_safe_close_fd_orig(int fd, int (*close_cb)(int fd)) * If called from lttng-ust, we directly call close without * validating whether the FD is part of the tracked set. */ - if (URCU_TLS(ust_fd_mutex_nest)) { -#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) - return lttng_ust_safe_close_fd_chain(fd, close_cb); -#else + if (URCU_TLS(ust_fd_mutex_nest) || lttng_ust_get_fd_mutex_nest_chain()) return close_cb(fd); -#endif - } lttng_ust_lock_fd_tracker(); if (IS_FD_VALID(fd) && IS_FD_SET(fd, lttng_fd_set)) { @@ -436,13 +463,8 @@ static int lttng_ust_safe_fclose_stream_orig(FILE *stream, int (*fclose_cb)(FILE * If called from lttng-ust, we directly call fclose without * validating whether the FD is part of the tracked set. */ - if (URCU_TLS(ust_fd_mutex_nest)) { -#if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) - return lttng_ust_safe_fclose_stream_chain(stream, fclose_cb); -#else + if (URCU_TLS(ust_fd_mutex_nest) || lttng_ust_get_fd_mutex_nest_chain()) return fclose_cb(stream); -#endif - } fd = fileno(stream); @@ -504,7 +526,7 @@ static int lttng_ust_safe_closefrom_fd_orig(int lowfd, int (*close_cb)(int fd)) * If called from lttng-ust, we directly call close without * validating whether the FD is part of the tracked set. */ - if (URCU_TLS(ust_fd_mutex_nest)) { + if (URCU_TLS(ust_fd_mutex_nest) || lttng_ust_get_fd_mutex_nest_chain()) { for (i = lowfd; i < lttng_ust_max_fd; i++) { if (close_cb(i) < 0) { switch (errno) { diff --git a/src/lib/lttng-ust-common/fd-tracker.h b/src/lib/lttng-ust-common/fd-tracker.h index 657d99eb..4186f305 100644 --- a/src/lib/lttng-ust-common/fd-tracker.h +++ b/src/lib/lttng-ust-common/fd-tracker.h @@ -16,6 +16,7 @@ void lttng_ust_fd_tracker_alloc_tls(void) #if !defined(LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS) void *lttng_ust_safe_close_fd_init(void); void *lttng_ust_safe_fclose_stream_init(void); +void *lttng_ust_get_fd_mutex_nest_init(void); #endif #endif diff --git a/src/lib/lttng-ust-fd/lttng-ust-fd.c b/src/lib/lttng-ust-fd/lttng-ust-fd.c index af208a98..5071f659 100644 --- a/src/lib/lttng-ust-fd/lttng-ust-fd.c +++ b/src/lib/lttng-ust-fd/lttng-ust-fd.c @@ -85,6 +85,7 @@ void lttng_ust_init_close_chaining(void) */ (void) lttng_ust_safe_close_fd_init(); (void) lttng_ust_safe_fclose_stream_init(); + (void) lttng_ust_get_fd_mutex_nest_init(); } #else static -- 2.34.1 From ecec7684b4bbea9042e47afc9c443741b3a03f5b Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 10 Oct 2022 16:53:50 +0100 Subject: [PATCH 16/16] Fix: populate possible cpus array len cache with fd tracker lock get_possible_cpus_array_len internally opens and closes file descriptors. Initialize the cache with fd tracker lock held to prevent concurrent use of close/closeall/closefrom. Signed-off-by: Mathieu Desnoyers Change-Id: Ib16c73f11af0b0cb163b38b0b096a86f6ae86325 --- src/lib/lttng-ust/lttng-ust-comm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/lttng-ust/lttng-ust-comm.c b/src/lib/lttng-ust/lttng-ust-comm.c index adb159a3..90abc71f 100644 --- a/src/lib/lttng-ust/lttng-ust-comm.c +++ b/src/lib/lttng-ust/lttng-ust-comm.c @@ -44,6 +44,7 @@ #include "lib/lttng-ust/futex.h" #include "common/ustcomm.h" #include "common/ust-fd.h" +#include "common/smp.h" #include "common/logging.h" #include "common/macros.h" #include "common/tracepoint.h" @@ -2244,6 +2245,13 @@ void lttng_ust_ctor(void) lttng_ust_tp_init(); lttng_ust_statedump_init(); + /* + * Populate possible cpus array len cache with the fd tracker + * lock held. + */ + lttng_ust_lock_fd_tracker(); + (void) get_possible_cpus_array_len(); + lttng_ust_unlock_fd_tracker(); lttng_ust_ring_buffer_clients_init(); lttng_ust_counter_clients_init(); lttng_perf_counter_init(); -- 2.34.1