Fix: lttng-ctl: erroneous uses of LTTNG_PACKED
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 13 Oct 2020 18:55:33 +0000 (14:55 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 13 Oct 2020 19:43:26 +0000 (15:43 -0400)
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 <jeremie.galarneau@efficios.com>
Change-Id: I095dc0dffc6bf9e15dc7a7ec797958a5780ef150

include/lttng/session-internal.h
include/lttng/snapshot-internal.h
src/common/sessiond-comm/sessiond-comm.h

index b263377de0c894653239efd9581202652d485a84..305c3f5f54ddd628f5803254c742a7e4fc876978 100644 (file)
@@ -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 */
index 8012a1e4ea58303456f4d6c23fb0e624e3f7278f..78c741349c750a0c1ae81a61b7aa4764fec86698 100644 (file)
@@ -11,6 +11,7 @@
 #include <limits.h>
 #include <stdint.h>
 #include <lttng/constant.h>
+#include <common/macros.h>
 
 /*
  * 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.
index c15a26f889bc83bcd682103abb4ab079622dab18..fca331fe7511efdf84f384f90749cf3abfc4014f 100644 (file)
@@ -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];
This page took 0.035337 seconds and 5 git commands to generate.