From: Florian Westphal <fw@strlen.de>
To: Jan Engelhardt <jengelh@medozas.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH xt-addons] xt_geoip: fix possible out-of-bounds access
Date: Sun, 13 Jun 2010 10:38:27 +0200 [thread overview]
Message-ID: <20100613083827.GA11457@Chamillionaire.breakpoint.cc> (raw)
In-Reply-To: <alpine.LSU.2.01.1006121037230.29158@obet.zrqbmnf.qr>
Jan Engelhardt <jengelh@medozas.de> wrote:
> On Tuesday 2010-06-01 10:51, Florian Westphal wrote:
>
> >It is possible for geoip_bsearch() to pick mid == sizeof(subnets).
> >
> >Consider a set with a single entry and a "address to test"
> >higher than the range:
> >
> >1st call: lo = 0, hi = 1 -> mid will be 0
> >2nd call: lo = 1, hi = 1 -> mid will be 1
> >
> >On the 2nd call, we'll examine random data.
>
> Isn't this simpler?
Guess that is a matter of taste :-)
To me, lo and hi are indexes into range[] and thus should not
exceed sizeof(range). This is what my patch fixes.
> diff --git a/extensions/xt_geoip.c b/extensions/xt_geoip.c
> index 4c6b29f..44e489d 100644
> --- a/extensions/xt_geoip.c
> +++ b/extensions/xt_geoip.c
> @@ -126,13 +126,13 @@ static bool geoip_bsearch(const struct geoip_subnet *range,
> {
> int mid;
>
> - if (hi < lo)
> + if (hi <= lo)
> return false;
> mid = (lo + hi) / 2;
> if (range[mid].begin <= addr && addr <= range[mid].end)
> return true;
> if (range[mid].begin > addr)
> - return geoip_bsearch(range, addr, lo, mid - 1);
> + return geoip_bsearch(range, addr, lo, mid);
> else if (range[mid].end < addr)
> return geoip_bsearch(range, addr, mid + 1, hi);
>
> Seems to work on paper.
Yes, this works as well.
I do not have a strong preference on how this is fixed; if you
consider your patch to be the better choice then please, by all means,
apply it :-)
Thanks,
Florian
next prev parent reply other threads:[~2010-06-13 8:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-01 8:51 [PATCH xt-addons] xt_geoip: fix possible out-of-bounds access Florian Westphal
2010-06-12 8:59 ` Jan Engelhardt
2010-06-13 8:38 ` Florian Westphal [this message]
2010-06-13 8:40 ` 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=20100613083827.GA11457@Chamillionaire.breakpoint.cc \
--to=fw@strlen.de \
--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).