Re: [PATCH] ipc: shm: fix information leak to userland

Vasiliy Kulikov
2010-10-30T15:40:12Z

Hi Dan,

On Sat, Oct 30, 2010 at 11:00 -0400, Dan Rosenberg wrote:
> This one already got taken care of by Kees Cook:
>
> http://lkml.org/lkml/2010/10/6/486

After 25 days it is still not in linux-next. Also the second hunk is IMO odd
as all five fields are initialized:

case IPC_OLD:
{
struct shminfo out;

if(in->shmmax > INT_MAX)
out.shmmax = INT_MAX;
else
out.shmmax = (int)in->shmmax;

out.shmmin = in->shmmin;
out.shmmni = in->shmmni;
out.shmseg = in->shmseg;
out.shmall = in->shmall;

return copy_to_user(buf, &out, sizeof(out));
}

/* Obsolete, used only for backwards compatibility */
struct shminfo {
int shmmax;
int shmmin;
int shmmni;
int shmseg;
int shmall;
};

And I see no padding hole in shminfo.

> Thanks,
> Dan
>
> > Structure shmid_ds is copied to userland with shm_unused{,2,3}
> > fields unitialized. It leads to leaking of contents of kernel stack
> > memory.
> > Cc: stable@kernel.org
> > Acked-by: Al Viro <viro@ZenIV.linux.org.uk>
> > Signed-off-by: Vasiliy Kulikov <segooon@gmail.com>
> > ---
> > Compile tested.
> > ipc/shm.c | 1 +
> > 1 files changed, 1 insertions(+), 0 deletions(-)
> > diff --git a/ipc/shm.c b/ipc/shm.c
> > index fd658a1..7d3bb22 100644
> > --- a/ipc/shm.c
> > +++ b/ipc/shm.c
> > @@ -479,6 +479,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;
>
>

Thanks,

--
Vasiliy