Date: Wed, 12 Oct 2011 09:53:34 +0800 From: dave jones <s.dave.jones@gmail.com> To: Mikolaj Golub <trociny@freebsd.org> Cc: "freebsd-net@freebsd.org" <freebsd-net@freebsd.org>, Adrian Chadd <adrian@freebsd.org>, Robert Watson <rwatson@freebsd.org>, "K. Macy" <kmacy@freebsd.org>, Arnaud Lacombe <lacombar@gmail.com> Subject: Re: Kernel panic on FreeBSD 9.0-beta2 Message-ID: <CANf5e8bLcxYDe%2BmHssUndOqh2B0j-V28Ox2dZCfy6%2Bo7aURw=w@mail.gmail.com> In-Reply-To: <CANf5e8YtQ5P2euF7E-D6Wt7U38UuLc8KVU-NCehq74XV_WTvBg@mail.gmail.com> References: <CANf5e8aG4go4M_vsRExUsJB_sjaN5x-QK-TCDAhSH64JSo0mdQ@mail.gmail.com> <CACqU3MXStMMEoppvDtZS6hV4WGttbdJiF8E-ORwJ%2BQSmnTy-Yg@mail.gmail.com> <CACqU3MV-t4Va6VWUoXy1Y9FYnNJTUw1X%2BE7ik-2%2BtMVuVOV3RA@mail.gmail.com> <CAJ-Vmom-177OkdUXjz%2BZLqbaqn=p%2BuTGypiVuMqdeXgdOgb4hQ@mail.gmail.com> <CAHM0Q_Mmn3z1V6AtZHQMpgbdY7oQqOChiNt=8NJrZQDnravb7A@mail.gmail.com> <CACqU3MU9ZZtOsdBOa%2BF3SqUaYgO%2BEo0v1ACjY0S4rY4fRQyv5Q@mail.gmail.com> <CAHM0Q_PZD9_0ZkELZ5XL8Ebh8eD-uFuSjXWKKVpGDeM_JDaqMA@mail.gmail.com> <8662kcigif.fsf@kopusha.home.net> <alpine.BSF.2.00.1109301432570.65269@fledge.watson.org> <CANf5e8ab=mUw-AJuRXZy1T6%2BZcryxjKfuCOsakPPfqatuA3HdA@mail.gmail.com> <86y5x0ooik.fsf@in138.ua3> <CANf5e8YtQ5P2euF7E-D6Wt7U38UuLc8KVU-NCehq74XV_WTvBg@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Oct 7, 2011 at 9:12 AM, dave jones wrote: > 2011/10/4 Mikolaj Golub : >> >> On Sat, 1 Oct 2011 14:15:45 +0800 dave jones wrote: >> >> =A0dj> On Fri, Sep 30, 2011 at 9:41 PM, Robert Watson wrote: >> =A0>> >> =A0>> On Wed, 28 Sep 2011, Mikolaj Golub wrote: >> =A0>> >> =A0>>> On Mon, 26 Sep 2011 16:12:55 +0200 K. Macy wrote: >> =A0>>> >> =A0>>> KM> Sorry, didn't look at the images (limited bw), I've seen some= thing KM> >> =A0>>> like this before in timewait. This "can't happen" with UDP so wil= l be KM> >> =A0>>> interested in learning more about the bug. >> =A0>>> >> =A0>>> The panic can be easily triggered by this: >> =A0>> >> =A0>> Hi: >> =A0>> >> =A0>> Just catching up on this thread. =A0I think the analysis here is g= enerally >> =A0>> right: in 9.0, you're much more likely to see an inpcb with its in= _socket >> =A0>> pointer cleared in the hash list than in prior releases, and >> =A0>> in_pcbbind_setup() trips over this. >> =A0>> >> =A0>> However, at least on first glance (and from the perspective of inv= ariants >> =A0>> here), I think the bug is actualy that in_pcbbind_setup() is askin= g >> =A0>> in_pcblookup_local() for an inpcb and then access the returned inp= cb's >> =A0>> in_socket pointer without acquiring a lock on the inpcb. =A0Struct= urally, it >> =A0>> can't acquire this lock for lock order reasons -- it already holds= the lock >> =A0>> on its own inpcb. =A0Therefore, we should only access fields that = are safe to >> =A0>> follow in an inpcb when you hold a reference via the hash lock and= not a >> =A0>> lock on the inpcb itself, which appears generally OK (+/-) for all= the >> =A0>> fields in that clause but the t->inp_socket->so_options dereferenc= e. >> =A0>> >> =A0>> A preferred fix would cache the SO_REUSEPORT flag in an inpcb-laye= r field, >> =A0>> such as inp_flags2, giving us access to its value without having t= o walk >> =A0>> into the attached (or not) socket. >> =A0>> >> =A0>> This raises another structural question, which is whether we need = a new >> =A0>> inp_foo flags field that is protected explicitly by the hash lock,= and not >> =A0>> by the inpcb lock, which could hold fields relevant to address bin= ding. =A0I >> =A0>> don't think we need to solve that problem in this context, as a sl= ightly >> =A0>> race on SO_REUSEPORT is likely acceptable. >> =A0>> >> =A0>> The suggested fix does perform the desired function of explicitly = detaching >> =A0>> the inpcb from the hash list before the socket is disconnected fro= m the >> =A0>> inpcb. However, it's incomplete in that the invariant that's being= broken is >> =A0>> also relied on for other protocols (such as raw sockets). =A0The c= orrect >> =A0>> invariant is that inp_socket is safe to follow unconditionally if = an inpcb >> =A0>> is locked and INP_DROPPED isn't set -- the bug is in "locked" not = in >> =A0>> "INP_DROPPED", which is why I think this is the wrong fix, even th= ough it >> =A0>> prevents a panic :-). >> >> =A0dj> Hello Robert, >> >> =A0dj> Thank you for taking your valuable time to find out the problem. >> =A0dj> Since I don't have idea about network internals, would you have a= patch >> =A0dj> about this? I'd be glad to test it, thanks again. >> >> Here is the patch that implements what Robert suggests. >> >> Dave, could you test it? > > Sure. Thanks for cooking the patch. > Machines have been running two days now without panic. Is there any plan to commit your fix? Thank you. I'd upgrade to 9.0-release from beta-2 once it's released. Best regards, Dave.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANf5e8bLcxYDe%2BmHssUndOqh2B0j-V28Ox2dZCfy6%2Bo7aURw=w>