public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ipc: initialize structure memory to zero for shmctl
@ 2010-10-07  0:10 Kees Cook
  2010-10-07  1:21 ` Al Viro
  0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2010-10-07  0:10 UTC (permalink / raw)
  To: linux-kernel; +Cc: Al Viro, Andrew Morton, Jiri Slaby, David S. Miller, stable

The old shm interface will leak a few bytes of stack contents. Explicitly
initialize the structure to zero-fill the untouched fields.

Signed-off-by: Kees Cook <kees.cook@canonical.com>
---
 ipc/shm.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/ipc/shm.c b/ipc/shm.c
index 52ed77e..d2ee426 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -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));
 	    }
-- 
1.7.1


-- 
Kees Cook
Ubuntu Security Team

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

* Re: [PATCH] ipc: initialize structure memory to zero for shmctl
  2010-10-07  0:10 [PATCH] ipc: initialize structure memory to zero for shmctl Kees Cook
@ 2010-10-07  1:21 ` Al Viro
  2010-10-07  2:13   ` Kees Cook
  0 siblings, 1 reply; 3+ messages in thread
From: Al Viro @ 2010-10-07  1:21 UTC (permalink / raw)
  To: Kees Cook
  Cc: linux-kernel, Andrew Morton, Jiri Slaby, David S. Miller, stable

On Wed, Oct 06, 2010 at 05:10:31PM -0700, Kees Cook wrote:
> 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.

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

* Re: [PATCH] ipc: initialize structure memory to zero for shmctl
  2010-10-07  1:21 ` Al Viro
@ 2010-10-07  2:13   ` Kees Cook
  0 siblings, 0 replies; 3+ messages in thread
From: Kees Cook @ 2010-10-07  2:13 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-kernel, Andrew Morton, Jiri Slaby, David S. Miller, stable

Hi Al,

On Thu, Oct 07, 2010 at 02:21:36AM +0100, Al Viro wrote:
> On Wed, Oct 06, 2010 at 05:10:31PM -0700, Kees Cook wrote:
> > 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.

-- 
Kees Cook
Ubuntu Security Team

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

end of thread, other threads:[~2010-10-07  2:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-07  0:10 [PATCH] ipc: initialize structure memory to zero for shmctl Kees Cook
2010-10-07  1:21 ` Al Viro
2010-10-07  2:13   ` Kees Cook

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