ipc: Fail build if IPC structures change layout
PATCH 1/1 ipc: Fail build if IPC structures change layout
Since struct layout can be seen at build-time, turn runtime report into a build failure so it can be fixed more quickly.
Cc Manfred Spraul <[email protected]>
Signed-off-by Kees Cook <[email protected]>
---
Should be applied on top of the -mm tree's IPC changes
--- ipc/msg.c | 5 +---- ipc/sem.c | 5 +---- ipc/shm.c | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-)
ipc/msg.c +1 -4
@@ -118,10 +118,7 @@ static int newque(struct ipc_namespace *ns, struct ipc_params *params)key_t key = params->key;int msgflg = params->flg; -if (offsetof(struct msg_queue , q_perm) !=0 ) { -pr_err ("Invalid struct sem_perm, failing msgget().\n" ); -return -ENOMEM ; - } +BUILD_BUG_ON (offsetof(struct msg_queue , q_perm) !=0 ); msq = container_of(ipc_rcu_alloc(sizeof(*msq)), struct msg_queue, q_perm);
ipc/sem.c +1 -4
@@ -469,10 +469,7 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params)if (ns->used_sems + nsems > ns->sc_semmns)return -ENOSPC ; -if (offsetof(struct sem_array , sem_perm) !=0 ) { -pr_err ("Invalid struct sem_perm, failing semget().\n" ); -return -ENOMEM ; - } +BUILD_BUG_ON (offsetof(struct sem_array , sem_perm) !=0 ); size =sizeof (*sma) + nsems *sizeof (sma->sems[0 ]); sma = container_of(ipc_rcu_alloc(size), struct sem_array, sem_perm);
ipc/shm.c +1 -4
@@ -543,10 +543,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params) ns->shm_tot + numpages > ns->shm_ctlall)return -ENOSPC ; -if (offsetof(struct shmid_kernel , shm_perm) !=0 ) { -pr_err ("Invalid struct sem_perm, failing msgget().\n" ); -return -ENOMEM ; - } +BUILD_BUG_ON (offsetof(struct shmid_kernel , shm_perm) !=0 ); shp = container_of(ipc_rcu_alloc(sizeof(*shp)), struct shmid_kernel, shm_perm);
Signature · 6 lines
2.7.4 -- Kees Cook Pixel Security
Quoted 2 lines · On Fri, 19 May 2017 16:44:00 -0700 Kees Cook <[email protected]> wrote:
Since struct layout can be seen at build-time, turn runtime report into a build failure so it can be fixed more quickly.
I've just dropped the patch which this fixes, due to runtime issues. Manfred, please include this in the resend?