netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: David Miller <davem@davemloft.net>
Cc: dan.carpenter@oracle.com, jhs@mojatatu.com,
	netdev@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] net_sched: stack info leak in cbq_dump_wrr()
Date: Mon, 29 Jul 2013 14:50:42 -0700	[thread overview]
Message-ID: <1375134642.2075.77.camel@joe-AO722> (raw)
In-Reply-To: <20130729.141725.1188109086272236102.davem@davemloft.net>

On Mon, 2013-07-29 at 14:17 -0700, David Miller wrote:
> From: Joe Perches <joe@perches.com>
> Date: Mon, 29 Jul 2013 13:12:31 -0700
> 
> > On Mon, 2013-07-29 at 23:01 +0300, Dan Carpenter wrote:
> >> On Mon, Jul 29, 2013 at 12:44:32PM -0700, Joe Perches wrote:
> >> > On Mon, 2013-07-29 at 22:36 +0300, Dan Carpenter wrote:
> >> > > opt.__reserved isn't cleared so we leak a byte of stack information.
> >> > []
> >> > > diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c
> >> > []
> >> > > @@ -1469,6 +1469,7 @@ static int cbq_dump_wrr(struct sk_buff *skb, struct cbq_class *cl)
> >> > >          opt.allot = cl->allot;
> >> > >          opt.priority = cl->priority + 1;
> >> > >          opt.cpriority = cl->cpriority + 1;
> >> > > +        opt.__reserved = 0;
> >> > >          opt.weight = cl->weight;
> >> > >          if (nla_put(skb, TCA_CBQ_WRROPT, sizeof(opt), &opt))
> >> > >                  goto nla_put_failure;
> >> > 
> >> > Alignment isn't guaranteed here so it'd
> >> > probably be better with a memset.
> >> > 
> >> 
> >> Hm...  Which arches would align it differently?
> > 
> > Hey Dan.
> > 
> > None so far as I know, but what difference does it make
> > when it's a general correctness issue?
> 
> Should see if the compiler optimizes the spurious stores away,
> and if not we can use an initializer.

If the initializer is

	struct foo = {0};

then as far as I know, the compiler is free to 
not initialize any padding.

However, it looks like gcc 4.7 generates the same
code for this with or without the __aligned__ use.

(with gcc -O2 -S t.c)

$ cat t.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct foo {
	int a;
	char b __attribute__((__aligned__(256)));
	long c;
};

void init1(void)
{
	struct foo bar = {0};
	printf("%p\n", &bar);
}

void init2(void)
{
	struct foo bar;
	memset(&bar, 0, sizeof(bar));
	printf("%p\n", &bar);
}

  reply	other threads:[~2013-07-29 21:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-29 19:36 [patch] net_sched: stack info leak in cbq_dump_wrr() Dan Carpenter
2013-07-29 19:44 ` Joe Perches
2013-07-29 20:01   ` Dan Carpenter
2013-07-29 20:12     ` Joe Perches
2013-07-29 21:17       ` David Miller
2013-07-29 21:50         ` Joe Perches [this message]
2013-07-30  6:55       ` Dan Carpenter
2013-07-30  7:12         ` Joe Perches
2013-07-30  7:18           ` David Miller
2013-07-30 10:18             ` walter harms
2013-07-29 21:20 ` Jiri Pirko

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=1375134642.2075.77.camel@joe-AO722 \
    --to=joe@perches.com \
    --cc=dan.carpenter@oracle.com \
    --cc=davem@davemloft.net \
    --cc=jhs@mojatatu.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).