Received: from eggs.gnu.org ([2001:4830:134:3::10]:45697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zuad0-0008VP-MY for qemu-devel@nongnu.org; Fri, 06 Nov 2015 01:36:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zuacw-000460-8n for qemu-devel@nongnu.org; Fri, 06 Nov 2015 01:36:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48743) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zuacw-00045v-3x for qemu-devel@nongnu.org; Fri, 06 Nov 2015 01:35:58 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id D3FE18E366 for ; Fri, 6 Nov 2015 06:35:57 +0000 (UTC) From: Eric Blake Date: Thu, 5 Nov 2015 23:35:27 -0700 Message-Id: <1446791754-23823-4-git-send-email-eblake@redhat.com> In-Reply-To: <1446791754-23823-1-git-send-email-eblake@redhat.com> References: <1446791754-23823-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH v10 03/30] qobject: Protect against use-after-free in qobject_decref() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com, Luiz Capitulino Adding an assertion to qobject_decref() will ensure that a programming error causing use-after-free will result in immediate failure (provided no other thread has started using the memory) instead of silently attempting to wrap refcnt around and leaving the problem to potentially bite later at a harder point to diagnose. Suggested-by: Markus Armbruster Signed-off-by: Eric Blake --- v10: new patch --- include/qapi/qmp/qobject.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h index c856f55..4b96ed5 100644 --- a/include/qapi/qmp/qobject.h +++ b/include/qapi/qmp/qobject.h @@ -90,6 +90,7 @@ static inline void qobject_incref(QObject *obj) */ static inline void qobject_decref(QObject *obj) { + assert(!obj || obj->refcnt); if (obj && --obj->refcnt == 0) { assert(obj->type != NULL); assert(obj->type->destroy != NULL); -- 2.4.3