浏览代码

[LibOS] Fix gcc-9 warning

This patch removes __attribute__((packed)) to eliminate warnings gcc-9
generates. Example:

> warning: taking address of packed member of struct poll_handle may result in an unaligned pointer value [-Waddress-of-packed-member]

Packed attribute is used for structures using which Graphene processes
communicate with each other. We don't implement privilege separation, so
it's ok to leak data in struct paddings.

If the padding is really a concern, we could:
- Define two structures, a packed one for serialization and a non-packed
  one for code, and then explicitly (de)serialize.
- Define the structure fields with an explicit size (e.g. uint64_t
  instead of long), carefully add explicit padding and then zero it out
  before sending.
Isaku Yamahata 5 年之前
父节点
当前提交
250dcb7aea

+ 7 - 7
LibOS/shim/include/shim_ipc.h

@@ -122,8 +122,8 @@ struct shim_ipc_resp {
 /* PID_CHECKPOINT: broadcast checkpointing */
 struct shim_ipc_checkpoint {
     IDTYPE cpsession;
-    char cpdir[1];
-} __attribute__((packed));
+    char cpdir[];
+};
 
 int ipc_checkpoint_send(const char* cpdir, IDTYPE cpsession);
 int ipc_checkpoint_callback(struct shim_ipc_msg* msg, struct shim_ipc_port* port);
@@ -204,7 +204,7 @@ struct pid_status {
 struct shim_ipc_pid_getstatus {
     int npids;
     IDTYPE pids[];
-} __attribute__((packed));
+};
 
 int ipc_pid_getstatus_send(struct shim_ipc_port* port, IDTYPE dest, int npids, IDTYPE* pids,
                            struct pid_status** status);
@@ -315,7 +315,7 @@ struct shim_ipc_sysv_movres {
     IDTYPE owner;
     LEASETYPE lease;
     char uri[1];
-} __attribute__((packed));
+};
 
 int ipc_sysv_movres_send(struct sysv_client* client, IDTYPE owner, const char* uri, LEASETYPE lease,
                          IDTYPE resid, enum sysv_type type);
@@ -349,7 +349,7 @@ struct shim_ipc_sysv_msgmov {
     LEASETYPE lease;
     unsigned short nscores;
     struct sysv_score scores[];
-} __attribute__((packed));
+};
 
 int ipc_sysv_msgmov_send(struct shim_ipc_port* port, IDTYPE dest, IDTYPE msgid, LEASETYPE lease,
                          struct sysv_score* scores, int nscores);
@@ -361,7 +361,7 @@ struct shim_ipc_sysv_semop {
     unsigned long timeout;
     int nsops;
     struct sembuf sops[];
-} __attribute__((packed));
+};
 
 #define IPC_SEM_NOTIMEOUT ((unsigned long)-1)
 
@@ -397,7 +397,7 @@ struct shim_ipc_sysv_semmov {
     LEASETYPE lease;
     unsigned short nsems, nsrcs, nscores;
     struct sem_backup sems[];
-} __attribute__((packed));
+};
 
 int ipc_sysv_semmov_send(struct shim_ipc_port* port, IDTYPE dest, IDTYPE semid, LEASETYPE lease,
                          struct sem_backup* sems, int nsems, struct sem_client_backup* srcs,

+ 5 - 9
LibOS/shim/include/shim_ipc_ns.h

@@ -46,7 +46,7 @@ struct ipc_ns_offered {
     IDTYPE base, size;
     LEASETYPE lease;
     unsigned int owner_offset;
-} __attribute__((packed));
+};
 
 struct ipc_ns_client {
     IDTYPE vmid;
@@ -125,8 +125,7 @@ int NS_CALLBACK(lease)(IPC_CALLBACK_ARGS);
 NS_MSG_TYPE(offer) {
     IDTYPE base, size;
     LEASETYPE lease;
-}
-__attribute__((packed));
+};
 
 int NS_SEND(offer)(struct shim_ipc_port* port, IDTYPE dest, IDTYPE base, IDTYPE size,
                    LEASETYPE lease, unsigned long seq);
@@ -169,8 +168,7 @@ int NS_CALLBACK(queryall)(IPC_CALLBACK_ARGS);
 NS_MSG_TYPE(answer) {
     int nanswers;
     struct ipc_ns_offered answers[];
-}
-__attribute__((packed));
+};
 
 int NS_SEND(answer)(struct shim_ipc_port* port, IDTYPE dest, int nanswers,
                     struct ipc_ns_offered* answers, int nowners, struct ipc_ns_client** ownerdata,
@@ -185,8 +183,7 @@ int CONCAT2(NS, get_key)(NS_KEY* key, bool delete);
 /* FINDKEY */
 NS_MSG_TYPE(findkey) {
     NS_KEY key;
-}
-__attribute__((packed));
+};
 
 int NS_SEND(findkey)(NS_KEY* key);
 int NS_CALLBACK(findkey)(IPC_CALLBACK_ARGS);
@@ -195,8 +192,7 @@ int NS_CALLBACK(findkey)(IPC_CALLBACK_ARGS);
 NS_MSG_TYPE(tellkey) {
     NS_KEY key;
     IDTYPE id;
-}
-__attribute__((packed));
+};
 
 int NS_SEND(tellkey)(struct shim_ipc_port* port, IDTYPE dest, NS_KEY* key, IDTYPE id,
                      unsigned long seq);

+ 1 - 1
LibOS/shim/include/shim_sysv.h

@@ -100,7 +100,7 @@ struct msg_req {
     unsigned short size;
     int flags;
     struct sysv_client dest;
-} __attribute__((packed));
+};
 
 #define INIT_MSG_TYPE_SIZE 32
 

+ 1 - 1
LibOS/shim/src/ipc/shim_ipc.c

@@ -449,7 +449,7 @@ int ipc_checkpoint_send(const char* cpdir, IDTYPE cpsession) {
     int ret;
     size_t len = strlen(cpdir);
 
-    size_t total_msg_size    = get_ipc_msg_size(sizeof(struct shim_ipc_checkpoint) + len);
+    size_t total_msg_size    = get_ipc_msg_size(sizeof(struct shim_ipc_checkpoint) + len + 1);
     struct shim_ipc_msg* msg = __alloca(total_msg_size);
     init_ipc_msg(msg, IPC_CHECKPOINT, total_msg_size, 0);
 

+ 1 - 1
LibOS/shim/src/sys/shim_poll.c

@@ -99,7 +99,7 @@ struct poll_handle {
     struct shim_handle * handle;
     struct poll_handle * next;
     struct poll_handle * children;
-} __attribute__((packed));
+};
 
 #define POLL_NOTIMEOUT  ((uint64_t)-1)