Skip to contentSkip to conversation

ipc: initialize structure memory to zero for shmctl

PATCH Superseded Kees Cook 2 participants 3 messages Oct 7, 2010

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 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.

---
 ipc/shm.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)
ipc/shm.c +9 -8
index 52ed77e..d2ee426 100644
@@ -471,16 +471,17 @@ static inline unsigned long copy_shmid_to_user(void __user *buf, struct shmid64_
 		return copy_to_user(buf, in, sizeof(*in));
 	case IPC_OLD:
 	    {
-		struct shmid_ds out;
+		struct shmid_ds out = {
+			.shm_segsz	= in->shm_segsz,
+			.shm_atime	= in->shm_atime,
+			.shm_dtime	= in->shm_dtime,
+			.shm_ctime	= in->shm_ctime,
+			.shm_cpid	= in->shm_cpid,
+			.shm_lpid	= in->shm_lpid,
+			.shm_nattch	= in->shm_nattch,
+		};
 
 		ipc64_perm_to_ipc_perm(&in->shm_perm, &out.shm_perm);
-		out.shm_segsz	= in->shm_segsz;
-		out.shm_atime	= in->shm_atime;
-		out.shm_dtime	= in->shm_dtime;
-		out.shm_ctime	= in->shm_ctime;
-		out.shm_cpid	= in->shm_cpid;
-		out.shm_lpid	= in->shm_lpid;
-		out.shm_nattch	= in->shm_nattch;
 
 		return copy_to_user(buf, &out, sizeof(out));
 	    }
Signature · 6 lines
1.7.1


-- 
Kees Cook
Ubuntu Security Team
#1 lore raw
Quoted 2 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.

Umm... I wonder if we ever have gaps in there; note that gaps between the fields are _not_ initialized in compound literals. Yes, I realize that it's a separate problem, but explicit memset() prior to initializations of fields might be a better solution, covering both.

author
#2 lore raw

Hi Al,

Quoted 8 lines · Al Viro
Quoted 2 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.

Umm... I wonder if we ever have gaps in there; note that gaps between the fields are _not_ initialized in compound literals. Yes, I realize that it's a separate problem, but explicit memset() prior to initializations of fields might be a better solution, covering both.

Excellent point. I'll resend with a memset.

Signature · 2 lines
Kees Cook
Ubuntu Security Team