From nobody Mon Nov 23 22:31:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1795067833; cv=none; d=zohomail.com; s=zohoarc; b=jHuEqRNYxlnY+vHUgzi5EAMCMYKhw+S+oOa4joFibzqwyqWEguSIhlnUfEVwmh8Gs0P81DxwcghbVnbTaITQ4hCKTBUqvzlfVK2Hp4Zkgwbajx5b3vAmSzAf8lwe3RYURA32RQdQj08GVIhIhZmYYCdCQ8NnfgF8pt10iVqFzF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795067833; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=P6BTWEWXY/BTGnn2IlV1PnrmMbfZ4BbNEeQU2kMUSc0=; b=IsPcsia4iy9CoTHpuzDw/UGqVJwSLfxRNNBwg57MtlhtmyyjwkWqWVyik/WQIGhqwzVjDslbH+f35+znCrhcTTVxlm4YnjUN9lrqNOTP6nf5IAH1sd97kB//J1QLiRBn8n+5wCtPdadB7g3lpk3J9b+RvLQoiNRbZxLKUD6HEsc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1795067833468637.332751194644; Wed, 18 Nov 2026 21:57:13 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1495384.1694503 (Exim 4.92) (envelope-from ) id 1xTv8c-0002LO-Iw; Thu, 19 Nov 2026 05:56:50 +0000 Received: by outflank-mailman (output) from mailman id 1495384.1694503; Thu, 19 Nov 2026 05:56:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xTv8c-0002LH-FD; Thu, 19 Nov 2026 05:56:50 +0000 Received: by outflank-mailman (input) for mailman id 1495384; Thu, 19 Nov 2026 01:11:54 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xTqgs-0000kQ-IS for xen-devel@lists.xenproject.org; Thu, 19 Nov 2026 01:11:54 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xTqgr-00312s-Ux for xen-devel@lists.xenproject.org; Thu, 19 Nov 2026 02:11:53 +0100 Received: from [10.42.69.10] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6afe4cb2-2eae-0a2a0a5409dd-0a2a450aedd6-28 for ; Thu, 19 Nov 2026 02:11:53 +0100 Received: from [209.85.222.173] (helo=mail-qk1-f173.google.com) by tlsNG-4011c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6afe4cd8-f2d2-0a2a450a0019-d155deadd9bb-3 for ; Thu, 19 Nov 2026 02:11:53 +0100 Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-93f269e335eso201499785a.3 for ; Wed, 18 Nov 2026 17:11:53 -0800 (PST) Received: from linux.. ([8.34.174.240]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-92114d28215sm35809866d6.16.2026.11.18.17.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 17:11:51 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795050712; x=1795655512; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=P6BTWEWXY/BTGnn2IlV1PnrmMbfZ4BbNEeQU2kMUSc0=; b=qQwNpQSC46iIyAs8+JxShvKUOzvqY5vW003otJrxsEBZqGvwahLpnC1eHl/UWoVOtJ sLHdnYNHRrt65TuZkGagwwgIfmQW+wj7GWvFKADlDhYinjAJBDTg++Pz9WbwKztLa3qi R6gcDfUJHghNidUjM+21uYnrfXdwAn7If1JwccfcAoeRLtc5ehlNyvysQDt/k+/cvgU7 je3mrXcEMoNwZpDPfrxApj4/2oFHjR/XPYXdEfFwziwTSWt1g4n/BFCECWkV7sqbTtno zDJYHPETls5HMGV7YJowGOxSJDx5vzKxF4guSxI6F6+BkSkcd5FNJVIG/3dmUQXP4tW4 LNJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795050712; x=1795655512; 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:content-type; bh=P6BTWEWXY/BTGnn2IlV1PnrmMbfZ4BbNEeQU2kMUSc0=; b=OLMq4Vw5i4LA7uLIieeW0i1kjvyhDDQLDd6UA+EIqLPv0KREhp9iBh4q1ncCvAoqZZ w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DDiOJQdTk8sIFCCovX37js3jGe/DHvSKz/gSt22GpaCW4Hhtq hFZakWFUs1wkEnNah6P/wWy50ZLPkI3V2qniUzUZzReOvtPAbvfJQ3OlPCB9ChdNUTZOB1yAs/R n X-Received: by 2002:a05:620a:1d0b:b0:945:d148:657a with SMTP id af79cd13be357-9499957e77dmr772314685a.24.1795050712252; Wed, 18 Nov 2026 17:11:52 -0800 (PST) From: Changyul Lee To: Juergen Gross , Stefano Stabellini Cc: Oleksandr Tyshchenko , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, Changyul Lee Subject: [PATCH] xen/virtio: Fix use-after-free of grant DMA data after rebind Date: Wed, 18 Nov 2026 20:11:49 -0500 Message-ID: <20261119011149.534095-1-lcy8047@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-4011c0/1795050713-4ACDBCFC-007A6A1D/0/0 X-purgate-type: clean X-purgate-size: 1870 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1795067834972158500 Content-Type: text/plain; charset="utf-8" When the device is unbound, devres frees its grant DMA data but leaves the entry in xen_grant_dma_devices. On rebind, the remaining entry causes xen_grant_setup_dma_ops() to skip setup. Since x86 retains dev->dma_ops across unbind, subsequent DMA operations access the freed data. Register a devres action to erase the entry before freeing the data. Fixes: 61367688f1fb ("xen/virtio: enable grant based virtio on x86") Signed-off-by: Changyul Lee --- Found with a static analysis tool we are developing. Tested in QEMU with KVM Xen HVM emulation (xen-version=3D0x4000a) and CONFIG_XEN_VIRTIO_FORCE_GRANT=3Dy, using a virtio-keyboard-pci device with iommu_platform=3Don. Unbinding and rebinding virtio-pci through sysfs triggers a KASAN slab-use-after-free in xen_grant_dma_alloc() before this patch and no report after it. drivers/xen/grant-dma-ops.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c index 5fcafa4c344f..784413e6d282 100644 --- a/drivers/xen/grant-dma-ops.c +++ b/drivers/xen/grant-dma-ops.c @@ -66,6 +66,15 @@ static int store_xen_grant_dma_data(struct device *dev, return ret; } =20 +static void remove_xen_grant_dma_data(void *dev) +{ + unsigned long flags; + + xa_lock_irqsave(&xen_grant_dma_devices, flags); + __xa_erase(&xen_grant_dma_devices, (unsigned long)dev); + xa_unlock_irqrestore(&xen_grant_dma_devices, flags); +} + /* * DMA ops for Xen frontends (e.g. virtio). * @@ -396,6 +405,9 @@ static void xen_grant_setup_dma_ops(struct device *dev,= domid_t backend_domid) goto err; } =20 + if (devm_add_action_or_reset(dev, remove_xen_grant_dma_data, dev)) + goto err; + dev->dma_ops =3D &xen_grant_dma_ops; =20 return; base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3 --=20 2.43.0