Skip to contentSkip to conversation

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

PATCH New Kees Cook 1 participant 1 message Sep 19, 2018

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

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

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()")
---
 ipc/shm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ipc/shm.c +1 -1
index 4cd402e4cfeb..1c65fb357395 100644
@@ -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)
Signature · 6 lines
2.17.1


-- 
Kees Cook
Pixel Security