public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ipc: Fail build if IPC structures change layout
@ 2017-05-19 23:44 Kees Cook
  2017-05-22 21:44 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2017-05-19 23:44 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Manfred Spraul

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 <manfred@colorfullife.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
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(-)

diff --git a/ipc/msg.c b/ipc/msg.c
index e9785c4d2e0d..0ed7dae7d4e8 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -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);
diff --git a/ipc/sem.c b/ipc/sem.c
index 18241c16d07c..2109fad750b5 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -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);
diff --git a/ipc/shm.c b/ipc/shm.c
index cec6df186050..2eb85bd5b855 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -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);
-- 
2.7.4


-- 
Kees Cook
Pixel Security

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ipc: Fail build if IPC structures change layout
  2017-05-19 23:44 [PATCH] ipc: Fail build if IPC structures change layout Kees Cook
@ 2017-05-22 21:44 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2017-05-22 21:44 UTC (permalink / raw)
  To: Kees Cook; +Cc: linux-kernel, Manfred Spraul

On Fri, 19 May 2017 16:44:00 -0700 Kees Cook <keescook@chromium.org> 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?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-05-22 21:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-19 23:44 [PATCH] ipc: Fail build if IPC structures change layout Kees Cook
2017-05-22 21:44 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox