From nobody Tue Apr 7 06:33:39 2026 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC4CA366825 for ; Sun, 15 Mar 2026 14:18:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773584305; cv=none; b=p2ke4qN8adX+Wi5e2ce6ZinDljsZQB89tOUWwavHor/zwLIuRAyuZYpY8dxXd0rduWSkaLySIW8muSpN+iv42dwe1qsVPHPMvLn7VyG6CMhq0g8sEXPx9VVn6Ho4xspSg1pOLvKQohhptIcvi6yPDh9dkug6H7tao4OvjNiHRqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773584305; c=relaxed/simple; bh=Y8fUBbvyzMQviIAW9sd4PkX24w/Vd0VYkVpKNberqqg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=LrmBWOzeMh3TovSii8KH8Eqpnm9MRHU7M8118iphw9u7L72to52/t++tStzUmB46Epr7D3iLs6i7XdvHyGThOZtOwP3jiuBiGJATirP0lDAFX9ys3JlsnPF51G4EFcpnQ6hO8npuYs86jdGVzfrvEXSEHpQQ+DOOFh6pb0DhFb8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=openresty.com; spf=pass smtp.mailfrom=openresty.com; dkim=pass (2048-bit key) header.d=openresty.com header.i=@openresty.com header.b=KzoB8J6b; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=openresty.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=openresty.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=openresty.com header.i=@openresty.com header.b="KzoB8J6b" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-82a07738118so2140986b3a.0 for ; Sun, 15 Mar 2026 07:18:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openresty.com; s=google; t=1773584303; x=1774189103; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fnEVg49IYI7HJLp/yxY4lgc89fYbkbBOZ6L8Tars9Cg=; b=KzoB8J6blozUzsEDo8eXBOEtawkea/XAev3d4QP0R9SwFhQRSmYNLSvQXiWPzIL39D trSaNuqMKDtwBuQSeM/XGObATfMZyXDW8u5fkxzpofr2w2TX/BUMCzQSNlod5qlYRDfc 8P+GOP4NXFtxIVF5Gnay1V3I4w/5C6MbQ5yZbg+R/Dsgwdd1GBcLqFQ6X/tU1sxsUmCC z1loUkd8G2LIweijsQP2DQaQiyAtbxDU7Uq5jQt01wn0pZ3BpC6HsvRoEBHyArGQFyD2 CHe4QJvJ/lt4PZHtqNLu/7AKfllupfFPatn7+KrveXJGfSmS7SNh7GFkwuoy/zd3bnen tUWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773584303; x=1774189103; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=fnEVg49IYI7HJLp/yxY4lgc89fYbkbBOZ6L8Tars9Cg=; b=NlrXTYE1xb6paxhl93hbe2UZdyFfCrWNgmoB6QUZEgkAQIHKDWsiFhNyYUnOpCEQF6 m68R23/uaJ3E257KEf8MfqOGXq4Es8Ov6/QWWTFJv3Mau13t6UXqVS6rxFRftQbq9TTJ HFdGEtfWyA6nH2oU1cOWOvsY/eAbChf7Gb4UUv7rSPdhwXhSY+lxX4rGXeffoIO8SofN xCEeLnit8MgIOwZMXc2q1VI8EOaefH1H7Kb7LwlRx+wyk9y4OpfWozC9RiiZeXqZdQkT 74JLxJZy6rPXbsV0563l6GzvWQi6HWFO1nC6gNLvI1gp6zTJSgk+DqYw/VeARvYflj3o gNcw== X-Forwarded-Encrypted: i=1; AJvYcCVBHmGXRfc3sOwliHRf32Becpi6CSzbYjitil8vbH1+D1epXIAldbSnhxzbcfVGWuGJYEZIaSthND8LJVk=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+XxtYysW7xAVV+Vh4zvYMbtFMjLxqxU28TG7Ti/iXgM5TSPQw QLu0GU93Grm/NzPSlNjSCZHlQQi3p5fkt+AJI/NUNPZscQjdWsTmkQdAESlMoIBpi/MS0AOq0HI tTpy4RKo= X-Gm-Gg: ATEYQzyr4pshkOAGmyKJIApEO66n0j/N0Hr/maD14J6Po3nTI0Iaz1e/GTqi/HwqWfK TnCa/P/UNrdcHup9r0kSqi174snPw7f67MvMJ3ajQup68f/bsw2QCeqHSb987pKnPP1eJeLX3Hv YCLTZTD7htUEZfRrcCiJohvgDHvLHd9HK5JyTiILU+n5p9q4JkjBycfSdDgL/aoIRdAyptlyuKv ji88vOdQCDLutOl71Wv6TesKdOu2rP6wSD2mpFkjpPXxYeY8gyEbvLGxi/95wcpkZW/nG4qoOia 5WXNmxiCHGGzqvMQx6UeKuqeP+pFOXWv3W+S9ySvp+xOuJLxolJ+5Q/5RK7fAh2XeBqPWBNuuMc 0FXYs0kdLhw1jUNJJHPCdSXIo0nvV6osH7K6Fef4Cwu5gErEpx6+dxWaco5StHCeQYPBWkW7vXB SufWRvGVxpL0z1EX1k26tAI7qYeZHqYzo6G0/OQBs3CRbo/o0= X-Received: by 2002:a05:6a00:4196:b0:82a:ea3:c172 with SMTP id d2e1a72fcca58-82a198f68f3mr8174011b3a.46.1773584303210; Sun, 15 Mar 2026 07:18:23 -0700 (PDT) Received: from localhost.localdomain ([2402:8780:1329:fe1:ca3e:1abc:522f:35d5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82a0725e0cdsm10871428b3a.16.2026.03.15.07.18.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Mar 2026 07:18:22 -0700 (PDT) From: Ammar Faizi To: "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?UTF-8?q?Eugenio=20P=C3=A9rez?= Cc: Ammar Faizi , Yichun Zhang , Jiri Pirko , Yuka , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Jiri Pirko , David Hildenbrand , virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, gwml@gnuweeb.org, stable@vger.kernel.org Subject: [PATCH] virtio_pci: fix vq info pointer lookup via wrong index Date: Sun, 15 Mar 2026 21:18:08 +0700 Message-Id: <20260315141808.547081-1-ammarfaizi2@openresty.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Unbinding a virtio balloon device: echo virtio0 > /sys/bus/virtio/drivers/virtio_balloon/unbind triggers a NULL pointer dereference. The dmesg says: BUG: kernel NULL pointer dereference, address: 0000000000000008 [...] RIP: 0010:__list_del_entry_valid_or_report+0x5/0xf0 Call Trace: vp_del_vqs+0x121/0x230 remove_common+0x135/0x150 virtballoon_remove+0xee/0x100 virtio_dev_remove+0x3b/0x80 device_release_driver_internal+0x187/0x2c0 unbind_store+0xb9/0xe0 kernfs_fop_write_iter.llvm.11660790530567441834+0xf6/0x180 vfs_write+0x2a9/0x3b0 ksys_write+0x5c/0xd0 do_syscall_64+0x54/0x230 entry_SYSCALL_64_after_hwframe+0x29/0x31 [...] The virtio_balloon device registers 5 queues (inflate, deflate, stats, free_page, reporting) but only the first two are unconditional. The stats, free_page and reporting queues are each conditional on their respective feature bits. When any of these features are absent, the corresponding vqs_info entry has name =3D=3D NULL, creating holes in the array. The root cause is an indexing mismatch introduced when vq info storage was changed to be passed as an argument. vp_find_vqs_msix() and vp_find_vqs_intx() store the info pointer at vp_dev->vqs[i], where 'i' is the caller's sparse array index. However, the virtqueue itself gets vq->index assigned from queue_idx, a dense index that skips NULL entries. When holes exist, 'i' and queue_idx diverge. Later, vp_del_vqs() looks up info via vp_dev->vqs[vq->index] using the dense index into the sparsely-populated array, and hits NULL. Fix this by storing info at vp_dev->vqs[queue_idx] instead of vp_dev->vqs[i], so the store index matches the lookup index (vq->index). Apply the fix to both the MSIX and INTX paths. Cc: Yichun Zhang Cc: Jiri Pirko Cc: stable@vger.kernel.org # v6.11+ Tested-by: Yuka Fixes: 89a1c435aec2 ("virtio_pci: pass vq info as an argument to vp_setup_v= q()") Signed-off-by: Ammar Faizi --- drivers/virtio/virtio_pci_common.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci= _common.c index da97b6a988de..164f480b18a6 100644 --- a/drivers/virtio/virtio_pci_common.c +++ b/drivers/virtio/virtio_pci_common.c @@ -414,28 +414,29 @@ static int vp_find_vqs_msix(struct virtio_device *vde= v, unsigned int nvqs, err =3D vp_request_msix_vectors(vdev, nvectors, per_vq_vectors, desc); if (err) goto error_find; =20 vp_dev->per_vq_vectors =3D per_vq_vectors; allocated_vectors =3D vp_dev->msix_used_vectors; for (i =3D 0; i < nvqs; ++i) { vqi =3D &vqs_info[i]; if (!vqi->name) { vqs[i] =3D NULL; continue; } - vqs[i] =3D vp_find_one_vq_msix(vdev, queue_idx++, vqi->callback, + vqs[i] =3D vp_find_one_vq_msix(vdev, queue_idx, vqi->callback, vqi->name, vqi->ctx, false, &allocated_vectors, vector_policy, - &vp_dev->vqs[i]); + &vp_dev->vqs[queue_idx]); + queue_idx++; if (IS_ERR(vqs[i])) { err =3D PTR_ERR(vqs[i]); goto error_find; } } =20 if (!avq_num) return 0; sprintf(avq->name, "avq.%u", avq->vq_index); vq =3D vp_find_one_vq_msix(vdev, avq->vq_index, vp_modern_avq_done, avq->name, false, true, &allocated_vectors, vector_policy, &vp_dev->admin_vq.info); @@ -476,27 +477,28 @@ static int vp_find_vqs_intx(struct virtio_device *vde= v, unsigned int nvqs, if (err) goto out_del_vqs; =20 vp_dev->intx_enabled =3D 1; vp_dev->per_vq_vectors =3D false; for (i =3D 0; i < nvqs; ++i) { struct virtqueue_info *vqi =3D &vqs_info[i]; =20 if (!vqi->name) { vqs[i] =3D NULL; continue; } - vqs[i] =3D vp_setup_vq(vdev, queue_idx++, vqi->callback, + vqs[i] =3D vp_setup_vq(vdev, queue_idx, vqi->callback, vqi->name, vqi->ctx, - VIRTIO_MSI_NO_VECTOR, &vp_dev->vqs[i]); + VIRTIO_MSI_NO_VECTOR, &vp_dev->vqs[queue_idx]); + queue_idx++; if (IS_ERR(vqs[i])) { err =3D PTR_ERR(vqs[i]); goto out_del_vqs; } } =20 if (!avq_num) return 0; sprintf(avq->name, "avq.%u", avq->vq_index); vq =3D vp_setup_vq(vdev, queue_idx++, vp_modern_avq_done, avq->name, false, VIRTIO_MSI_NO_VECTOR, &vp_dev->admin_vq.info); --=20 Ammar Faizi