Skip to contentSkip to conversation

ipc: initialize structure memory to zero for shmctl

PATCH In review Kees Cook 2 participants 2 messages Oct 7, 2010

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH v2 1/1 ipc: initialize structure memory to zero for shmctl

The old shm interface will leak a few bytes of stack contents. Explicitly initialize the structure to zero-fill the untouched fields, using memset instead of C99-style in case there are ever holes in the structure.

---
 ipc/shm.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
ipc/shm.c +2 -0
index 52ed77e..f943b1e 100644
@@ -473,6 +473,7 @@ static inline unsigned long copy_shmid_to_user(void __user *buf, struct shmid64_
 	    {
 		struct shmid_ds out;
 
+		memset(&out, 0, sizeof(out));
 		ipc64_perm_to_ipc_perm(&in->shm_perm, &out.shm_perm);
 		out.shm_segsz	= in->shm_segsz;
 		out.shm_atime	= in->shm_atime;
@@ -524,6 +525,7 @@ static inline unsigned long copy_shminfo_to_user(void __user *buf, struct shminf
 	    {
 		struct shminfo out;
 
+		memset(&out, 0, sizeof(out));
 		if(in->shmmax > INT_MAX)
 			out.shmmax = INT_MAX;
 		else
Signature · 6 lines
1.7.1


-- 
Kees Cook
Ubuntu Security Team
#1 lore raw
Quoted 6 lines · Kees Cook

The old shm interface will leak a few bytes of stack contents. Explicitly initialize the structure to zero-fill the untouched fields, using memset instead of C99-style in case there are ever holes in the structure.

---

If you wish to have a patch included in the stable series, please read Documentation/stable_kernel_rules.txt which state that adding a:
Cc: stable <[email protected]>
to the signed-off-by: area will cause it to be automagically included when the patch gets into Linus's tree. Otherwise it just causes a lot of extra work for me to dig around and watch out for it in the future.

thanks,

greg k-h