netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Jan Engelhardt <jengelh@medozas.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH 5/5] attr: avoid multiple definition of hidden variable
Date: Thu, 11 Nov 2010 18:47:40 +0100	[thread overview]
Message-ID: <4CDC2C3C.5060708@netfilter.org> (raw)
In-Reply-To: <alpine.LNX.2.01.1011111424370.22995@obet.zrqbmnf.qr>

On 11/11/10 14:25, Jan Engelhardt wrote:
> 
> On Thursday 2010-11-11 14:08, Pablo Neira Ayuso wrote:
>> On 11/11/10 00:08, Jan Engelhardt wrote:
>>> When nesting two mnl_attr_for_each loops, the __len__ variable will be
>>> declared twice, eliciting a warning when -Wshadow is turned on. There
>>> can also be warnings in pre-C99 because declarations and code are
>>> mixed. Do without any temporaries that are not explicitly specified as
>>> macro parameters.
>>
>> I like this spot, some question below:
>>
>>> -struct nlattr *mnl_attr_next(const struct nlattr *attr, int *len)
>>> +struct nlattr *mnl_attr_next(const struct nlattr *attr)
>>>  {
>>> -	*len -= MNL_ALIGN(attr->nla_len);
>>>  	return (struct nlattr *)((void *)attr + MNL_ALIGN(attr->nla_len));
>>>  }
>>
>> If we remove the len parameter from mnl_attr_next(), we may access
>> memory that may be out of the message boundary in mnl_attr_ok().
> 
> Not that I can see; mnl_attr_ok tests for len >= sizeof(struct nlattr),
> and len is tail minus attr.

mnl_attr_for_each() in your patch is OK, sorry. But, here:

+#define mnl_attr_for_each_nested(attr, nest) \
+	for ((attr) = mnl_attr_get_payload(nest); \
+	     mnl_attr_ok((attr), mnl_attr_get_payload(attr) +
mnl_attr_get_payload_len(attr) - (void *)(attr)); \
+	     (attr) = mnl_attr_next(attr))

Once we iterate over the last attribute in the nest, we iterate again to
check if there's any next. Then, mnl_attr_get_payload may access
attr->len for an attribute that doesn't belong the nest or (if the nest
is in the end of the message) an out of bound message access.

I think that we can add mnl_attr_get_payload_tail to make tail minus
attr, like in mnl_attr_for_each().

  reply	other threads:[~2010-11-11 17:47 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-10 23:07 libmnl misc patches Nov 11 Jan Engelhardt
2010-11-10 23:08 ` [PATCH 1/5] socket: constify a struct sockaddr_nl Jan Engelhardt
2010-11-11 12:56   ` Pablo Neira Ayuso
2010-11-10 23:08 ` [PATCH 2/5] include: use C++ headers in C++ mode Jan Engelhardt
2010-11-11 12:57   ` Pablo Neira Ayuso
2010-11-11 12:59     ` Jan Engelhardt
2010-11-11 13:15       ` Pablo Neira Ayuso
2010-11-13 18:19         ` Jan Engelhardt
2010-11-16 10:04           ` Pablo Neira Ayuso
2013-06-07  8:35   ` Thomas Jarosch
2013-06-08 13:38     ` Jan Engelhardt
2010-11-10 23:08 ` [PATCH 3/5] nlmsg: use bool for all _ok functions Jan Engelhardt
2010-11-11 12:59   ` Pablo Neira Ayuso
2010-11-10 23:08 ` [PATCH 4/5] attr: remove redundant check for NULL Jan Engelhardt
2010-11-11 13:02   ` Pablo Neira Ayuso
2010-11-10 23:08 ` [PATCH 5/5] attr: avoid multiple definition of hidden variable Jan Engelhardt
2010-11-11 13:08   ` Pablo Neira Ayuso
2010-11-11 13:25     ` Jan Engelhardt
2010-11-11 17:47       ` Pablo Neira Ayuso [this message]
2010-11-11 20:53         ` Jan Engelhardt

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=4CDC2C3C.5060708@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=jengelh@medozas.de \
    --cc=netfilter-devel@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).