public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Kees Cook <kees.cook@canonical.com>
Cc: linux-kernel@vger.kernel.org, Pekka Enberg <penberg@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jiri Slaby <jslaby@suse.cz>,
	"David S. Miller" <davem@davemloft.net>,
	Hugh Dickins <hughd@google.com>,
	Manfred Spraul <manfred@colorfullife.com>,
	Vasiliy Kulikov <segooon@gmail.com>
Subject: Re: [PATCH] ipc: explicitly clear stack memory for shminfo
Date: Tue, 16 Nov 2010 12:08:56 -0800	[thread overview]
Message-ID: <1289938136.28741.198.camel@Joe-Laptop> (raw)
In-Reply-To: <1289937508-19458-1-git-send-email-kees.cook@canonical.com>

On Tue, 2010-11-16 at 11:58 -0800, Kees Cook wrote:
> This fixes a kernel stack memory contents leak by explicitly clearing
> the shminfo structure on the kernel stack before it is populated and
> copied back to userspace.
> diff --git a/ipc/shm.c b/ipc/shm.c
> index 7d3bb22..1d3d41f 100644
> --- a/ipc/shm.c
> +++ b/ipc/shm.c
> @@ -531,6 +531,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

Hi Kees.

Trivial size optimization:

Perhaps it's better to use
	struct type var = {};
instead of
	struct type var;
	memset(&var, 0, sizeof(var));

At least for x86, gcc produces very slightly smaller code
when there are other automatic variables like:

Larger:
	struct type var;
	struct type var2;
	memset(&var, 0, sizeof(var));
Smaller:
	struct type var = {};
	struct type var2;

On the other hand, memset is more obvious.


  reply	other threads:[~2010-11-16 20:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-16 19:58 [PATCH] ipc: explicitly clear stack memory for shminfo Kees Cook
2010-11-16 20:08 ` Joe Perches [this message]
2010-11-16 20:16 ` Vasiliy Kulikov
2010-11-16 20:51   ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1289938136.28741.198.camel@Joe-Laptop \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=hughd@google.com \
    --cc=jslaby@suse.cz \
    --cc=kees.cook@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manfred@colorfullife.com \
    --cc=penberg@kernel.org \
    --cc=segooon@gmail.com \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox