From 7bd95aee4660c6419a4a65429fc27754481e7e90 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 13 Oct 2020 14:55:33 -0400 Subject: [PATCH] Fix: lttng-ctl: erroneous uses of LTTNG_PACKED MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The LTTNG_PACKED macro uses gcc attributes to indicate that a structure should be packed. Hence, this macro obeys the same rules as the gcc attribute. Various mis-uses of the LTTNG_PACKED macros may result in structure not being packed: - The LTTNG_PACKED macro should always be placed _before_ an identifier when a structure is declared in-place. - Adding LTTNG_PACKED at the definition site has no effect if the structure was declared elsewhere. Those mis-uses cause issues when mixing the bitness (32/64) of the session daemon and liblttng-ctl. Outstanding issues include the following structures that are not tagged as LTTNG_PACKED: - struct lttng_event - struct lttng_channel - struct lttng_event_context Unfortunately, those structures are exposed by the public API and can't be tagged as being "packed". Doing so would break the ABI of liblttng-ctl. These structures should be packed/unpacked explicitly. Signed-off-by: Jérémie Galarneau Change-Id: I095dc0dffc6bf9e15dc7a7ec797958a5780ef150 --- include/lttng/session-internal.h | 2 +- include/lttng/snapshot-internal.h | 3 ++- src/common/sessiond-comm/sessiond-comm.h | 15 +++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/lttng/session-internal.h b/include/lttng/session-internal.h index b263377de..305c3f5f5 100644 --- a/include/lttng/session-internal.h +++ b/include/lttng/session-internal.h @@ -15,7 +15,7 @@ struct lttng_session_extended { struct { uint64_t value; uint8_t is_set; - } creation_time LTTNG_PACKED; + } LTTNG_PACKED creation_time; } LTTNG_PACKED; #endif /* LTTNG_SESSION_INTERNAL_H */ diff --git a/include/lttng/snapshot-internal.h b/include/lttng/snapshot-internal.h index 8012a1e4e..78c741349 100644 --- a/include/lttng/snapshot-internal.h +++ b/include/lttng/snapshot-internal.h @@ -11,6 +11,7 @@ #include #include #include +#include /* * Object used for the snapshot API. This is opaque to the public library. @@ -33,7 +34,7 @@ struct lttng_snapshot_output { char ctrl_url[PATH_MAX]; /* Destination of the output. See lttng(1) for URL format. */ char data_url[PATH_MAX]; -}; +} LTTNG_PACKED; /* * Snapshot output list object opaque to the user. diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index c15a26f88..fca331fe7 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -283,7 +283,7 @@ struct lttcomm_session_msg { /* Event data */ struct { char channel_name[LTTNG_SYMBOL_NAME_LEN]; - struct lttng_event event LTTNG_PACKED; + struct lttng_event event; /* Length of following filter expression. */ uint32_t expression_len; /* Length of following bytecode for filter. */ @@ -302,7 +302,7 @@ struct lttcomm_session_msg { } LTTNG_PACKED enable; struct { char channel_name[LTTNG_SYMBOL_NAME_LEN]; - struct lttng_event event LTTNG_PACKED; + struct lttng_event event; /* Length of following filter expression. */ uint32_t expression_len; /* Length of following bytecode for filter. */ @@ -316,14 +316,13 @@ struct lttcomm_session_msg { } LTTNG_PACKED disable; /* Create channel */ struct { - struct lttng_channel chan LTTNG_PACKED; - /* struct lttng_channel_extended is already packed. */ + struct lttng_channel chan; struct lttng_channel_extended extended; } LTTNG_PACKED channel; /* Context */ struct { char channel_name[LTTNG_SYMBOL_NAME_LEN]; - struct lttng_event_context ctx LTTNG_PACKED; + struct lttng_event_context ctx; uint32_t provider_name_len; uint32_t context_name_len; } LTTNG_PACKED context; @@ -342,18 +341,18 @@ struct lttcomm_session_msg { uint32_t size; } LTTNG_PACKED uri; struct { - struct lttng_snapshot_output output LTTNG_PACKED; + struct lttng_snapshot_output output; } LTTNG_PACKED snapshot_output; struct { uint32_t wait; - struct lttng_snapshot_output output LTTNG_PACKED; + struct lttng_snapshot_output output; } LTTNG_PACKED snapshot_record; struct { uint32_t nb_uri; unsigned int timer_interval; /* usec */ } LTTNG_PACKED session_live; struct { - struct lttng_save_session_attr attr; /* struct already packed */ + struct lttng_save_session_attr attr; } LTTNG_PACKED save_session; struct { char shm_path[PATH_MAX]; -- 2.34.1