[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/4] Define a common GNTTAB_MAX_PAGES


  • To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
  • Date: Tue, 13 Oct 2026 14:32:38 +0200
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:In-Reply-To:References:Feedback-ID"
  • Cc: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
  • Delivery-date: Tue, 13 Oct 2026 12:32:48 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

Each grant must not exceed 4GB to avoid overflow. So use MAXULONG
divided by PAGE_SIZE as the limit instead of 1024*1024, as the latter
will overflow when multiplied with PAGE_SIZE.

Signed-off-by: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
---
 src/xeniface/ioctl_gnttab.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/xeniface/ioctl_gnttab.c b/src/xeniface/ioctl_gnttab.c
index dd1f4bb..0dab8e2 100644
--- a/src/xeniface/ioctl_gnttab.c
+++ b/src/xeniface/ioctl_gnttab.c
@@ -36,6 +36,8 @@
 #include "irp_queue.h"
 #include "util.h"
 
+#define GNTTAB_MAX_PAGES    (MAXULONG / PAGE_SIZE)
+
 // Complete a canceled gnttab IRP, cleanup associated grant/map.
 _Function_class_(IO_WORKITEM_ROUTINE)
 VOID
@@ -391,7 +393,7 @@ IoctlGnttabPermitForeignAccess(
     }
 
     Status = STATUS_INVALID_PARAMETER;
-    if (In->NumberPages == 0 || In->NumberPages > 1024 * 1024) {
+    if (In->NumberPages == 0 || In->NumberPages > GNTTAB_MAX_PAGES) {
         goto fail4;
     }
 
@@ -660,7 +662,7 @@ IoctlGnttabMapForeignPages(
 
         In1 = Buffer;
         ReferenceSize = InLen - 
(ULONG)FIELD_OFFSET(XENIFACE_GNTTAB_MAP_FOREIGN_PAGES_IN, References);
-        if (ReferenceSize > 1024 * 1024 * sizeof(ULONG))
+        if (ReferenceSize > GNTTAB_MAX_PAGES * sizeof(ULONG))
             goto fail3;
         status = __CaptureUserBuffer(Buffer, InLen, &In1);
         if (!NT_SUCCESS(status))
@@ -694,7 +696,7 @@ IoctlGnttabMapForeignPages(
 
         In = Buffer;
         ReferenceSize = InLen - 
(ULONG)FIELD_OFFSET(XENIFACE_GNTTAB_MAP_FOREIGN_PAGES_IN_V2, References);
-        if (ReferenceSize > 1024 * 1024 * sizeof(ULONG))
+        if (ReferenceSize > GNTTAB_MAX_PAGES * sizeof(ULONG))
             goto fail3;
         status = __CaptureUserBuffer(Buffer, InLen, &In);
         if (!NT_SUCCESS(status))
@@ -707,7 +709,7 @@ IoctlGnttabMapForeignPages(
     // At this point we only access In.
     status = STATUS_INVALID_PARAMETER;
     if (In->NumberPages == 0 ||
-        In->NumberPages > 1024 * 1024 ||
+        In->NumberPages > GNTTAB_MAX_PAGES ||
         In->NumberPages * sizeof(ULONG) > ReferenceSize) {
         goto fail6;
     }
-- 
2.55.0.windows.3



--
Ngoc Tu Dinh | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.