Date: Fri, 24 Jun 2005 21:31:28 -0500 (CDT) From: Mike Silbersack <silby@silby.com> To: current@freebsd.org Cc: Thierry Herbelot <thierry@herbelot.com> Subject: Mbuf double-free guilty party detection patch Message-ID: <20050624212729.C537@odysseus.silby.com>
next in thread | raw e-mail | index | archive | help
This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --0-1915742314-1119666662=:537 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII; format=flowed Content-ID: <20050624213107.H537@odysseus.silby.com> The attached patch stores the address of who freed an mbuf/cluster/whatever inside it, then prints that address when panicing. You can then feed that address into "x 0xwhatever" in DDB to see who the semi-guilty party is. Two flaws in the patch as is: - It's messy and not compatible with non-i386, cleanups are needed. - If the mbuf in question is part of a mbuf chain, we'll see m_freem as the guilty party, because it called m_free. So, if you're one of the people seeing panics due to mbufs being used after free, please try applying the patch and see what results you get. If you keep getting m_freem as the previous user, then I'll have to enhance it to work around that. Mike "Silby" Silbersack --0-1915742314-1119666662=:537 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII; NAME=mbuf_trash_list_freeing_address.patch Content-Transfer-Encoding: BASE64 Content-ID: <20050624213102.N537@odysseus.silby.com> Content-Description: Content-Disposition: ATTACHMENT; FILENAME=mbuf_trash_list_freeing_address.patch ZGlmZiAtdSAtciAvdXNyL3NyYy9zeXMub2xkL2tlcm4vdWlwY19tYnVmLmMg L3Vzci9zcmMvc3lzL2tlcm4vdWlwY19tYnVmLmMNCi0tLSAvdXNyL3NyYy9z eXMub2xkL2tlcm4vdWlwY19tYnVmLmMJRnJpIEp1biAyNCAyMDoxMzo1OSAy MDA1DQorKysgL3Vzci9zcmMvc3lzL2tlcm4vdWlwY19tYnVmLmMJRnJpIEp1 biAyNCAyMDo1MDoxNiAyMDA1DQpAQCAtMjE5LDcgKzIxOSw3IEBADQogICog c3RvcmFnZSBhdHRhY2hlZCB0byB0aGVtIGlmIHRoZSByZWZlcmVuY2UgY291 bnQgaGl0cyAwLg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yL3NyYy9zeXMub2xkL3ZtL3VtYV9kYmcuYyAvdXNyL3NyYy9zeXMv dm0vdW1hX2RiZy5jDQotLS0gL3Vzci9zcmMvc3lzLm9sZC92bS91bWFfZGJn LmMJRnJpIEp1biAyNCAyMDoxMzoyNyAyMDA1DQorKysgL3Vzci9zcmMvc3lz L3ZtL3VtYV9kYmcuYwlGcmkgSnVuIDI0IDIxOjExOjA1IDIwMDUNCkBAIC02 NiwxMSArNjYsMTQgQEANCiAJdV9pbnQzMl90ICpwOw0KIA0KIAljbnQgPSBz aXplIC8gc2l6ZW9mKHVtYV9qdW5rKTsNCisJY250IC09IHNpemVvZih2b2lk ICopOw0KIA0KIAlmb3IgKHAgPSBtZW07IGNudCA+IDA7IGNudC0tLCBwKysp DQotCQlpZiAoKnAgIT0gdW1hX2p1bmspDQorCQlpZiAoKnAgIT0gdW1hX2p1 bmspIHsNCisJCQlwcmludGYoIlRoaXMgbWVtb3J5IGxhc3QgZnJlZWQgYnk6 ICVwXG4iLCAodm9pZCAqKSpwKTsNCiAJCQlwYW5pYygiTWVtb3J5IG1vZGlm aWVkIGFmdGVyIGZyZWUgJXAoJWQpIHZhbD0leCBAICVwXG4iLA0KIAkJCSAg ICBtZW0sIHNpemUsICpwLCBwKTsNCisJCX0NCiAJcmV0dXJuICgwKTsNCiB9 DQogDQpAQCAtODcsOSArOTAsMTEgQEANCiAJdV9pbnQzMl90ICpwOw0KIA0K IAljbnQgPSBzaXplIC8gc2l6ZW9mKHVtYV9qdW5rKTsNCisJY250IC09IHNp emVvZih2b2lkICopOw0KIA0KIAlmb3IgKHAgPSBtZW07IGNudCA+IDA7IGNu dC0tLCBwKyspDQogCQkqcCA9IHVtYV9qdW5rOw0KKwkqcCA9IChpbnQpYXJn Ow0KIH0NCiANCiAvKg0K --0-1915742314-1119666662=:537--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050624212729.C537>