From nobody Mon Nov 23 04:28:04 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=1793732322; cv=none; d=zohomail.com; s=zohoarc; b=BnnIMWsCdB91ypFg8e51WWsvecl2xq43SHKdLJtnEM3memCF7vPdGPTufQ0h0GbRgfINprnzMq5zzjmtrmFyZflvbcCLw2nV03oVENTgXifsYp1sI2DCxiVCmlYanvlowvWccQpr1SxuA35IqpmjJRLg+bv74KqNLCP4C7ZXMao= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793732322; 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=ebNd/mwInS17slcUOk7Vv9/IhqR1AKy4VZd0mrWUr1A=; b=k+A4bA/ksY9PWffUlZE4lUMCf59LfBUAFdRpWweUypUeStGhnYO1a3rXqrRVczrIg5TuSTdEQYU8zQpk1tEtXe2DeePMBnUsN7j1AIAcR+SUw/cUPU1oh2pbX+Qk/3A2LYflnuL/wgLMX53yImSmZbpocA+N61vjA2uYbU4v6jE= 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 1793732322440279.0024550885497; Tue, 3 Nov 2026 10:58:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOJhx-0005f0-4T; Tue, 03 Nov 2026 13:58:09 -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 1xOJhv-0005er-3U for qemu-devel@nongnu.org; Tue, 03 Nov 2026 13:58:07 -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 1xOJhs-0006BU-Qy for qemu-devel@nongnu.org; Tue, 03 Nov 2026 13:58:06 -0500 Received: from qemu.weilnetz.de (qemu.weilnetz.de [188.68.58.204]) by mail.v2201612906741603.powersrv.de (Postfix) with ESMTP id CB633DA0566; Tue, 03 Nov 2026 19:57:36 +0100 (CET) Received: by qemu.weilnetz.de (Postfix, from userid 1000) id 31088466751; Tue, 03 Nov 2026 19:57:21 +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] hw/net/eepro100: fix use-after-free on reset after hot-unplug Date: Tue, 3 Nov 2026 19:56:59 +0100 Message-ID: <20261103185659.698079-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: CB633DA0566 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)[]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; DMARC_POLICY_SOFTFAIL(0.10)[weilnetz.de : No valid SPF, No valid DKIM,quarantine,sampled_out]; TO_DN_SOME(0.00)[]; ASN(0.00)[asn:197540, ipnet:188.68.56.0/22, country:DE]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ONE(0.00)[1]; R_DKIM_NA(0.00)[]; ARC_NA(0.00)[]; FROM_NEQ_ENVFROM(0.00)[sw@weilnetz.de,stefan@weilnetz.de]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; R_SPF_SOFTFAIL(0.00)[~all]; FREEMAIL_CC(0.00)[nongnu.org,weilnetz.de,gmail.com,linaro.org]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] 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: 1793732324831158500 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 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 Reported-by: MyeonghunPak --- Note that I used AI assistance to create and test the patch. I am not shure whether this is acceptable to small and rather mechnical changes like in this case. The Reported-by for issue 4058 was not added because I did not find the required full name and email of the reporter. Stefan W. hw/net/eepro100.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c index aaa3eb60f8a..e1cd8346941 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", @@ -1881,8 +1888,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 +2069,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 +2086,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)