[PATCH] ipc/shm: Use ERR_CAST() for shm_lock() error return

From: Kees Cook
Date: Wed Sep 19 2018 - 14:07:27 EST


This uses ERR_CAST() instead of an open-coded cast, as it is casting
across structure pointers, which upsets __randomize_layout:

ipc/shm.c: In function âshm_lockâ:
ipc/shm.c:209:9: note: randstruct: casting between randomized structure pointer types (ssa): âstruct shmid_kernelâ and âstruct kern_ipc_permâ

return (void *)ipcp;
^~~~~~~~~~~~

Fixes: 82061c57ce93 ("ipc: drop ipc_lock()")
Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>
---
ipc/shm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ipc/shm.c b/ipc/shm.c
index 4cd402e4cfeb..1c65fb357395 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -206,7 +206,7 @@ static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id)
* Callers of shm_lock() must validate the status of the returned ipc
* object pointer and error out as appropriate.
*/
- return (void *)ipcp;
+ return ERR_CAST(ipcp);
}

static inline void shm_lock_by_ptr(struct shmid_kernel *ipcp)
--
2.17.1


--
Kees Cook
Pixel Security