From nobody Mon Nov 23 04:27:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793742900; cv=none; d=zohomail.com; s=zohoarc; b=lKh+uWCTx5jOul41zuhQPaT/tl5cxwFsQWqdqnXZHGyzbhw7eF4BH0KKp7cOaG8stiPsc2vrCnXjHaJ3niY1G5HvDmmWmd+NjpBAw4Pf+gq/jCMiw7BKGQUEnNO9bNByxwfPc0YNF0XbbdVWQf+g1/9nNK95w68IjE7ho1v/ESo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793742900; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=CzymT0Ax80PyEPucbkxT8ibKIAoVhiDwcmhwrIm2TT0=; b=amUr+qelPeMkn9LKbVfz0G5eZyiNmXWj+B3T/h25tq6wRonP8HWdn/W0qqFcBtn6YYaLc7Zagf+CAQVatKqPuuaEU4YBmVEO2NC0N2VKxZ66ooTu5wVzidbs8YLha9jkc53P+EizwzFhflEg2oYXe6+czLgIwazDxZJbiDblE5s= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793742900251317.6575516373987; Tue, 3 Nov 2026 13:55:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOMSs-0007Co-Qs; Tue, 03 Nov 2026 16:54:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOMSk-0007C1-OL for qemu-devel@nongnu.org; Tue, 03 Nov 2026 16:54:40 -0500 Received: from mail.weilnetz.de ([37.120.169.71] helo=mail.v2201612906741603.powersrv.de) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOMSh-0006wj-6O for qemu-devel@nongnu.org; Tue, 03 Nov 2026 16:54:38 -0500 Received: from qemu.weilnetz.de (qemu.weilnetz.de [188.68.58.204]) by mail.v2201612906741603.powersrv.de (Postfix) with ESMTP id 37A5DDA04B5; Tue, 03 Nov 2026 22:54:32 +0100 (CET) Received: by qemu.weilnetz.de (Postfix, from userid 1000) id F1F03466751; Tue, 03 Nov 2026 22:54:30 +0100 (CET) Authentication-Results: mail.v2201612906741603.powersrv.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=weilnetz.de (policy=none); spf=softfail (mail.v2201612906741603.powersrv.de: 188.68.58.204 is neither permitted nor denied by domain of stefan@weilnetz.de) smtp.mailfrom=stefan@weilnetz.de To: Jason Wang Cc: qemu-devel@nongnu.org, Stefan Weil , Hui Peng , Peter Maydell Subject: [PATCH v2] hw/net/eepro100: fix use-after-free on reset after hot-unplug Date: Tue, 3 Nov 2026 22:54:05 +0100 Message-ID: <20261103215430.703404-1-sw@weilnetz.de> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: v2201612906741603 X-Rspamd-Queue-Id: 37A5DDA04B5 X-Spamd-Bar: ++ X-Spamd-Result: default: False [2.60 / 10.00]; VIOLATED_DIRECT_SPF(3.50)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; FORGED_SENDER(0.30)[sw@weilnetz.de,stefan@weilnetz.de]; ONCE_RECEIVED(0.20)[]; DMARC_POLICY_SOFTFAIL(0.10)[weilnetz.de : No valid SPF, No valid DKIM,quarantine,sampled_out]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; RCVD_COUNT_ONE(0.00)[1]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:197540, ipnet:188.68.56.0/22, country:DE]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; FREEMAIL_TO(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all:c]; FROM_NEQ_ENVFROM(0.00)[sw@weilnetz.de,stefan@weilnetz.de]; RCPT_COUNT_FIVE(0.00)[5]; FREEMAIL_CC(0.00)[nongnu.org,weilnetz.de,gmail.com,linaro.org]; R_DKIM_NA(0.00)[] X-Rspamd-Action: no action Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=37.120.169.71; envelope-from=stefan@weilnetz.de; helo=mail.v2201612906741603.powersrv.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Stefan Weil From: Stefan Weil via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793742903320158500 Content-Type: text/plain; charset="utf-8" e100_nic_realize() registers a system reset handler via qemu_register_reset(nic_reset, s), but pci_nic_uninit() never unregisters it. After the device is hot-unplugged, the LegacyReset object stored in the root reset container still holds the raw pointer to the freed EEPRO100State, so the next system reset invokes nic_reset() on freed memory. Instead, define a reset phase on the device itself: assign phases.hold in eepro100_class_init() to a wrapper around nic_reset(). The device is already part of the resettable tree via its parent bus (TYPE_DEVICE implements the Resettable interface), so no explicit registration is needed, and the reset state is automatically dropped when the device is unplugged. This follows the approach used by the e1000, e1000e and igb emulations. Reported-by: Hui Peng Reported-by: MyeonghunPak Suggested-by: Peter Maydell Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4058 Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4510 Signed-off-by: Stefan Weil Reviewed-by: Peter Maydell --- v1: Initial fix, created and tested with AI assistance. v2: Removed nic_reset() in e100_nic_realize as suggested by Peter Maydell. I did not replace the DO_UPCAST macro by a standard QOM cast which was also suggested, because I think it is better to focus on the required fix. Replacing DO_UPCAST would be worth a separate patch (to be done later). Stefan hw/net/eepro100.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c index aaa3eb60f8a..8fe7f31bd2f 100644 --- a/hw/net/eepro100.c +++ b/hw/net/eepro100.c @@ -617,6 +617,13 @@ static void nic_reset(void *opaque) nic_selective_reset(s); } =20 +static void eepro100_reset_hold(Object *obj, ResetType type) +{ + EEPRO100State *s =3D DO_UPCAST(EEPRO100State, dev, PCI_DEVICE(obj)); + + nic_reset(s); +} + #if defined(DEBUG_EEPRO100) static const char * const e100_reg[PCI_IO_SIZE / 4] =3D { "Command/Status", @@ -1871,8 +1878,6 @@ static void e100_nic_realize(PCIDevice *pci_dev, Erro= r **errp) qemu_macaddr_default_if_unset(&s->conf.macaddr); logout("macaddr: %s\n", nic_dump(&s->conf.macaddr.a[0], 6)); =20 - nic_reset(s); - s->nic =3D qemu_new_nic(&net_eepro100_info, &s->conf, object_get_typename(OBJECT(pci_dev)), pci_dev->qdev.id, @@ -1881,8 +1886,6 @@ static void e100_nic_realize(PCIDevice *pci_dev, Erro= r **errp) qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); TRACE(OTHER, logout("%s\n", qemu_get_queue(s->nic)->info_str)); =20 - qemu_register_reset(nic_reset, s); - s->vmstate =3D g_memdup(&vmstate_eepro100, sizeof(vmstate_eepro100)); s->vmstate->name =3D qemu_get_queue(s->nic)->model; vmstate_register_any(VMSTATE_IF(&pci_dev->qdev), s->vmstate, s); @@ -2064,6 +2067,7 @@ static void eepro100_class_init(ObjectClass *klass, c= onst void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); E100PCIDeviceInfo *info; =20 info =3D eepro100_get_class_by_name(object_class_get_name(klass)); @@ -2080,6 +2084,7 @@ static void eepro100_class_init(ObjectClass *klass, c= onst void *data) k->revision =3D info->revision; k->subsystem_vendor_id =3D info->subsystem_vendor_id; k->subsystem_id =3D info->subsystem_id; + rc->phases.hold =3D eepro100_reset_hold; } =20 static void eepro100_register_types(void) --=20 2.54.0 (Apple Git-157)