Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Apr 2012 10:42:52 +0200
From:      =?ISO-8859-1?Q?Ermal_Lu=E7i?= <eri@freebsd.org>
To:        Gleb Smirnoff <glebius@freebsd.org>
Cc:        freebsd-pf@freebsd.org
Subject:   Re: kern/164402: [pf] pf crashes with a particular set of rules when first matching packet arrives
Message-ID:  <CAPBZQG1W3DeBQmsTJhg2RFLA7Zdjx6BwRuRZJBzbjRL%2B%2Bvx7-w@mail.gmail.com>
In-Reply-To: <CAPBZQG2gF8GSx6eE4jkFuOf29c-jB09Gz6=%2BkbpXprN8XiEE4w@mail.gmail.com>
References:  <201204151200.q3FC0LT5085161@freefall.freebsd.org> <20120416185949.GC92286@FreeBSD.org> <CAPBZQG2Tjg36GNCBetRZ20FhQnL1sK9i_-oQDDb97bcb4N=sLA@mail.gmail.com> <20120417081406.GA93887@glebius.int.ru> <CAPBZQG2gF8GSx6eE4jkFuOf29c-jB09Gz6=%2BkbpXprN8XiEE4w@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Apr 17, 2012 at 10:38 AM, Ermal Lu=E7i <eri@freebsd.org> wrote:
> 2012/4/17 Gleb Smirnoff <glebius@freebsd.org>:
>> On Tue, Apr 17, 2012 at 10:06:15AM +0200, Ermal Lu?i wrote:
>> E> 2012/4/16 Gleb Smirnoff <glebius@freebsd.org>:
>> E> > On Sun, Apr 15, 2012 at 12:00:21PM +0000, Gleb Smirnoff wrote:
>> E> > T> =A0On Sun, Apr 15, 2012 at 11:10:03AM +0000, Gleb Smirnoff wrote=
:
>> E> > T> =A0T> =A0 =A0I have a vague suspicion on what is happening. Your=
 description of
>> E> > T> =A0T> =A0the problem looks like if a packet processing in the ke=
rnel has entered
>> E> > T> =A0T> =A0an endless loop.
>> E> > T> =A0T>
>> E> > T> =A0T> =A0 =A0Looking at pf_route() I see such possibility. From =
OpenBSD we have
>> E> > T> =A0T> =A0this protection against endless looping:
>> E> > T> =A0T>
>> E> > T> =A0T> =A0 =A0 =A0 =A0 =A0if ((*m)->m_pkthdr.pf.routed++ > 3) {
>> E> > T> =A0T> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0m0 =3D *m;
>> E> > T> =A0T> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*m =3D NULL;
>> E> > T> =A0T> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto bad;
>> E> > T> =A0T> =A0 =A0 =A0 =A0 =A0}
>> E> > T> =A0T>
>> E> > T> =A0T> =A0In our code this transforms to:
>> E> > T> =A0T>
>> E> > T> =A0T> =A0 =A0 =A0 =A0 =A0if (pd->pf_mtag->routed++ > 3) {
>> E> > T> =A0T> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0m0 =3D *m;
>> E> > T> =A0T> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*m =3D NULL;
>> E> > T> =A0T> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto bad;
>> E> > T> =A0T> =A0 =A0 =A0 =A0 =A0}
>> E> > T> =A0T>
>> E> > T> =A0T> =A0The root difference between storing the tag on mbuf and=
 on pfdesc
>> E> > T> =A0T> =A0is that we lose pfdesc, and thus the tag, when we enter=
 pf_test()
>> E> > T> =A0T> =A0recursively. And pf_route() does this recursion:
>> E> > T> =A0T>
>> E> > T> =A0T> =A0 =A0 =A0 =A0 =A0if (oifp !=3D ifp) {
>> E> > T> =A0T> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (pf_test(PF_OUT, ifp=
, &m0, NULL) !=3D PF_PASS) {
>> E> > T> =A0T> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto ba=
d;
>> E> > T> =A0T> =A0 =A0 =A0 =A0 =A0....
>> E> > T>
>> E> > T> =A0On second look I see that my suspicion may not be true. In th=
e
>> E> > T> =A0beginning of pf_test() we do pf_get_mtag() which preserves al=
ready
>> E> > T> =A0present tag if there is one.
>> E> >
>> E> > Further investigation showed that problem exist when route applied
>> E> > ends in lo0, and packet passes to if_simloop(). There all mtags are
>> E> > stripped from the mbuf, including the pf mtag. Then packet is again
>> E> > processed by ip_input() again entering pf(4), if it again matches
>> E> > a routing rule, then we got an endless loop.
>> E> >
>> E> > We can try to fix this applying MTAG_PERSISTENT to the pf(4) tag id=
.
>> E>
>> E> That seems like the best fix for this case.
>>
>> In this case crash or freeze is fixed, but still packet is dropped. Exam=
ple
>> of such rule:
>>
>> pass in on igb0 fastroute proto tcp from any to $localip
>>
>> Anyway, dropping packets is much better than crashing.

To be more explicit, this breaks functionality.
Since as i said the firewall has already taken descision and the state
keeping for sure will drop this matching tcp packets.
You will not see it for other protos that do not have the state
transition like tcp though your statistics will be wrong.
This is not justifible and its better to crash :)

Though as i said the skip firewall flag seems more sensible.
>>
>
> Actually after some coffee :) i think its better marking the packet
> with M_SKIP_FIREWALL since
> it has already taken its decision on this packet.
>
> The simloop consumers seem to be just facilities of how things work
> from what i can see.
>
> So just delivering the packet by sending skipping the firewalls seems
> more sensibile!
>
> Though the persistent case for the tags should be revisited since it
> may fix some other issues with pf(4) tags, and some others.
>
>> --
>> Totus tuus, Glebius.
>
>
>
> --
> Ermal



--=20
Ermal



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAPBZQG1W3DeBQmsTJhg2RFLA7Zdjx6BwRuRZJBzbjRL%2B%2Bvx7-w>