From: Gianni Tedesco Subject: [PATCH]: libblktapctl, fix use-after-free bug Date: Tue, 3 Aug 2010 16:55:17 +0100 Message-ID: <1280850917.18490.176.camel@qabil.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Xen Devel Cc: Ian Jackson , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org This has not caused crashes because generally use after free is OK provided nothing else is going on. However the patch makes things correct. It also allows us to use heap poisoning feature of valgrind on tools linking to libblktapctl. diff -r 5c5a6081f258 tools/blktap2/control/tap-ctl-list.c --- a/tools/blktap2/control/tap-ctl-list.c Tue Aug 03 15:42:53 2010 +0100 +++ b/tools/blktap2/control/tap-ctl-list.c Tue Aug 03 16:55:04 2010 +0100 @@ -385,9 +385,9 @@ _tap_ctl_free_tapdisks(struct tapdisk *t struct tapdisk *tap; for (tap = tapv; tap < &tapv[n_taps]; ++tap) { - struct tapdisk_list *tl; + struct tapdisk_list *tl, *next; - list_for_each_entry(tl, &tap->list, entry) { + list_for_each_entry_safe(tl, next, &tap->list, entry) { free(tl->params); free(tl); }