All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Jan Engelhardt <jengelh@computergmbh.de>
Cc: netfilter-devel@lists.netfilter.org,
	Amin Azez <azez@ufomechanic.net>,
	Pablo Neira Ayuso <pablo@netfilter.org>,
	Jaime Nebrera <jnebrera@eneotecnologia.com>
Subject: Re: VLAN match within iptables
Date: Tue, 26 Jun 2007 14:50:02 +0200	[thread overview]
Message-ID: <46810B7A.5020609@trash.net> (raw)
In-Reply-To: <Pine.LNX.4.64.0706261423150.3137@fbirervta.pbzchgretzou.qr>

Jan Engelhardt wrote:
> On Jun 26 2007 12:09, Patrick McHardy wrote:
>   
>> Pablo Neira Ayuso wrote:
>>     
>>> Since you have to apply that patch to your kernel anyway, I suggest you
>>> to apply the u32 patch instead (it is scheduled for 2.6.23 IIRC).
>>>       
>> I don't think that will work, it can't be used to match on data
>> before skb->data since the offset can only be positive.
>>     
>
> The VLAN ID is not in the Layer3 window. xt_u32 uses skb_copy_bits,
> which seems to start at the Layer3 (IPv4/ipv6) header(why that?!).
>   

It stats at skb->data, since thats the most natural way for
users. And it supports negative offsets, but you need to
make sure they're valid.

>   
>> Jan, I just noticed the length checks are insufficient, very
>> large positives offsets will lead to integer overflow and
>> probably trigger the BUG afterwards.
>>     
>
> Is this the right way to check for overflows?
>
>                 if (at > skb->len || at + pos > skb->len ||                     
>                     at + pos + 3 > skb->len)                                    
>                         return false;                                           
>
>   

It depends, I'm not sure I understand the code correctly:

        if (at + pos + 3 > skb->len || at + pos < 0)
               return false;

        BUG_ON(skb_copy_bits(skb, pos, &val, sizeof(val)) < 0);


You're only copying at pos here, so I don't get why you're
checking for at + pos. Just doing:

if (skb->len < 3 || pos > skb->len - 3)
    return false;

should be fine for this case.

The second one goes:

       if (at + pos + 3 > skb->len || at + pos < 0)
                return false;

       BUG_ON(skb_copy_bits(skb, at+pos, &val,
               sizeof(val)) < 0);


So here I would do:

if (at + 3 < at || skb->len < at + 3 || pos > skb->len - at - 3)
    return false;

  reply	other threads:[~2007-06-26 12:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-26  9:22 VLAN match within iptables Jaime Nebrera
2007-06-26  9:34 ` Jan Engelhardt
2007-06-26  9:38   ` Patrick McHardy
2007-06-26  9:41     ` Jan Engelhardt
2007-06-26 10:00 ` Pablo Neira Ayuso
2007-06-26 10:09   ` Patrick McHardy
2007-06-26 12:38     ` Jan Engelhardt
2007-06-26 12:50       ` Patrick McHardy [this message]
2007-06-26 13:12         ` xt_u32 20070626 (Re: VLAN match within iptables) Jan Engelhardt
2007-06-26 13:13           ` xt_u32 20070626 (iptables part) Jan Engelhardt
2007-06-26 16:49             ` Patrick McHardy
2007-06-26 13:19           ` xt_u32 20070626 (Re: VLAN match within iptables) Patrick McHardy
2007-06-26 13:35             ` Jan Engelhardt
2007-06-26 13:36               ` Patrick McHardy
2007-06-26 14:05                 ` Jan Engelhardt
2007-06-26 14:06                   ` Patrick McHardy

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=46810B7A.5020609@trash.net \
    --to=kaber@trash.net \
    --cc=azez@ufomechanic.net \
    --cc=jengelh@computergmbh.de \
    --cc=jnebrera@eneotecnologia.com \
    --cc=netfilter-devel@lists.netfilter.org \
    --cc=pablo@netfilter.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.