public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Yi Lai <yi1.lai@intel.com>
To: yi1.lai@intel.com, Alex Williamson <alex@shazbot.org>,
	David Matlack <dmatlack@google.com>,
	Shuah Khan <shuah@kernel.org>,
	Baolu Lu <baolu.lu@linux.intel.com>,
	kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] vfio: selftests: Fix iommufd compat mode __iommu_unmap() crash
Date: Fri, 20 Mar 2026 12:03:21 +0800	[thread overview]
Message-ID: <20260320040322.487429-2-yi1.lai@intel.com> (raw)
In-Reply-To: <20260320040322.487429-1-yi1.lai@intel.com>

When running vfio_dma_mapping_mmio_test in MODE_IOMMUFD_COMPAT* mode,
the test crashes with "Test terminated unexpectedly by signal 11".

The crash happens because:
1. __iommu_map() fails as expected for MMIO mappings in iommufd.
Consequently, the region.link remains uninitialized.
2. The test proceeds to call __iommu_unmap().
3. In iommufd compat mode, the kernel returns 0 for unmapping a
non-existent range.
4. __iommu_unmap() calls list_del_init(&region->link), dereferencing the
uninitialized pointer.

Fix this by explicitly initializing region.link using INIT_LIST_HEAD.

Signed-off-by: Yi Lai <yi1.lai@intel.com>
---
 tools/testing/selftests/vfio/vfio_dma_mapping_mmio_test.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/vfio/vfio_dma_mapping_mmio_test.c b/tools/testing/selftests/vfio/vfio_dma_mapping_mmio_test.c
index 957a89ce7b3a..4f7ecdca0215 100644
--- a/tools/testing/selftests/vfio/vfio_dma_mapping_mmio_test.c
+++ b/tools/testing/selftests/vfio/vfio_dma_mapping_mmio_test.c
@@ -88,6 +88,7 @@ static void do_mmio_map_test(struct iommu *iommu,
 		.vaddr = vaddr,
 		.size = size,
 		.iova = iova_allocator_alloc(iova_allocator, size),
+		.link = LIST_HEAD_INIT(region.link),
 	};
 
 	/*
-- 
2.43.0


  reply	other threads:[~2026-03-20  4:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-20  4:03 [PATCH 0/2] vfio: selftests: Fix MMIO test failures in iommufd compat mode Yi Lai
2026-03-20  4:03 ` Yi Lai [this message]
2026-03-20  4:03 ` [PATCH 2/2] vfio: selftests: Align __iommu_unmap() check with " Yi Lai
2026-03-20 17:43 ` [PATCH 0/2] vfio: selftests: Fix MMIO test failures in " David Matlack
2026-03-23  0:37   ` Lai, Yi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260320040322.487429-2-yi1.lai@intel.com \
    --to=yi1.lai@intel.com \
    --cc=alex@shazbot.org \
    --cc=baolu.lu@linux.intel.com \
    --cc=dmatlack@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox