From nobody Sat Sep 26 20:00:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1790124523; cv=none; d=zohomail.com; s=zohoarc; b=aQpmmVWroZQJYXQViVWmAQE8UtG/ofUT0SkbnSAFnRZkoMOnwqFO0mqHZREwl9ahIvverOSSkEtEsGmOSeJQgO+B8nm+1nVZuScqmivi4C+Eq02pBJV0dd9162VKd07bnxoiai8jePdyVYAsGN6eEIR5fHbFEH+hZn56O3H7KRA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790124523; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=soPfNLvyehGkK5sUU9EAbSiY6UKT8pRxngG6hsGjorM=; b=cDypu/OO1hRDoIjyZ4IJ6W+47jqCqwx1fvMU/5XS7welqNK2uUr6zHJazHPjYHmntcc4wtX+Wa5ycT64dSPvYNWLUX1SgqllTEmys7N828G29TYcjtiF6hrXk8UPCPB44TBCCugtFMk1w0qagetkpcKZVsvyOz5JNv/j43w6Wws= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17901245229541018.8116565167628; Tue, 22 Sep 2026 17:48:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x9B9Z-0004u0-8L; Tue, 22 Sep 2026 20:48:05 -0400 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 1x9B9Y-0004tq-Bj for qemu-devel@nongnu.org; Tue, 22 Sep 2026 20:48:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x9B9W-0007Pp-Is for qemu-devel@nongnu.org; Tue, 22 Sep 2026 20:48:04 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-588-f-w0J0IeM9OL3lY_RaFXgA-1; Tue, 22 Sep 2026 20:46:55 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C56621830530; Wed, 23 Sep 2026 00:46:53 +0000 (UTC) Received: from mlevitsk-thinkpadt14gen3.ibmmarkh.csb (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 488161956041; Wed, 23 Sep 2026 00:46:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1790124481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=soPfNLvyehGkK5sUU9EAbSiY6UKT8pRxngG6hsGjorM=; b=M7o0X2auKrGdS5Jm7m82LFGqCO57weEQUaN/Yfop7+Jr6KhWM9Fu1hXlOtx+ulig8iBhIN 6SYmbCOYj8wEdF2Gk93VTQu6Scq045IXDr/+ijRuW+YV9jF4NmqjWEUI29WGRgWwCNEvwD xlit/HB/mFvFeAYUOb66W74cNujYjG0= X-MC-Unique: f-w0J0IeM9OL3lY_RaFXgA-1 X-Mimecast-MFC-AGG-ID: f-w0J0IeM9OL3lY_RaFXgA_1790124414 From: Maxim Levitsky To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Mauro Matteo Cascella , Maxim Levitsky , "Vulnerability Report" Subject: [PATCH] accel/kvm: protect kvm_resample_fd_list with a mutex Date: Tue, 22 Sep 2026 20:46:51 -0400 Message-ID: <20260923004651.101197-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=mlevitsk@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1790124526846158500 Content-Type: text/plain; charset="utf-8" Legacy PCI INTx interrupts are level triggered and can, in theory, be share= d. Upon receiving such an interrupt, VFIO kernel driver masks it in a generic = way, using INTX_DISABLE bit in the PCI config space. It then waits for the guest to signal completion (EOI) of the interrupt, upon which VFIO re-enables the interrupt. The completion is signaled with another eventfd. For split irqchip mode, KVM doesn't have a notion of EOI on IOAPIC level. Instead it signals EOI with a userspace VM exit, KVM_EXIT_IOAPIC_EOI. Upon receiving this VM exit, Qemu manually signals the above-mentioned even= tfd. The problem that this patch resolves is that QEMU keeps these eventfds in a linked list without any locking to prevent the list from being corrupted = by concurrent access. Such use is possible and guest triggerable if the guest rapidly toggles INTX mode of a VFIO device and at the same time signals EOI with an arbitra= ry vector. Fix this by protecting this list (kvm_resample_fd_list) with a mutex. This patch was only compile tested. Reported-by: "Vulnerability Report" Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3942 Signed-off-by: Maxim Levitsky --- accel/kvm/kvm-all.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 83cbd120a847..da3afdc68d8d 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -146,6 +146,7 @@ typedef struct KVMResampleFd KVMResampleFd; static QLIST_HEAD(, KVMResampleFd) kvm_resample_fd_list =3D QLIST_HEAD_INITIALIZER(kvm_resample_fd_list); =20 +static QemuMutex kvm_resample_fd_list_lock; static QemuMutex kml_slots_lock; =20 #define kvm_slots_lock() qemu_mutex_lock(&kml_slots_lock) @@ -157,6 +158,8 @@ static inline void kvm_resample_fd_remove(int gsi) { KVMResampleFd *rfd; =20 + qemu_mutex_lock(&kvm_resample_fd_list_lock); + QLIST_FOREACH(rfd, &kvm_resample_fd_list, node) { if (rfd->gsi =3D=3D gsi) { QLIST_REMOVE(rfd, node); @@ -164,6 +167,8 @@ static inline void kvm_resample_fd_remove(int gsi) break; } } + + qemu_mutex_unlock(&kvm_resample_fd_list_lock); } =20 static inline void kvm_resample_fd_insert(int gsi, EventNotifier *event) @@ -173,20 +178,26 @@ static inline void kvm_resample_fd_insert(int gsi, Ev= entNotifier *event) rfd->gsi =3D gsi; rfd->resample_event =3D event; =20 + qemu_mutex_lock(&kvm_resample_fd_list_lock); QLIST_INSERT_HEAD(&kvm_resample_fd_list, rfd, node); + qemu_mutex_unlock(&kvm_resample_fd_list_lock); } =20 void kvm_resample_fd_notify(int gsi) { KVMResampleFd *rfd; =20 + qemu_mutex_lock(&kvm_resample_fd_list_lock); + QLIST_FOREACH(rfd, &kvm_resample_fd_list, node) { if (rfd->gsi =3D=3D gsi) { event_notifier_set(rfd->resample_event); trace_kvm_resample_fd_notify(gsi); - return; + break; } } + + qemu_mutex_unlock(&kvm_resample_fd_list_lock); } =20 /** @@ -2910,6 +2921,7 @@ static int kvm_init(AccelState *as, MachineState *ms) int type; =20 qemu_mutex_init(&kml_slots_lock); + qemu_mutex_init(&kvm_resample_fd_list_lock); =20 /* * On systems where the kernel can support different base page --=20 2.54.0