[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 10/10] xencontrol: guard against NumberPages overflow in gnttab size calculation
- To: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>, Owen Smith <owen.smith@xxxxxxxxxx>, David ambu <david.preetham@xxxxxxxxxx>, "win-pv-devel@xxxxxxxxxxxxxxxxxxxx" <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Rafał Wojdyła <omeg@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 13 Oct 2026 11:19:50 +0200
- Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=fm2 header.d=invisiblethingslab.com header.i="@invisiblethingslab.com" header.h="Content-Transfer-Encoding:Content-Type:Date:From:In-Reply-To:Message-ID:MIME-Version:References:Subject:To"; dkim=pass header.s=fm2 header.d=messagingengine.com header.i="@messagingengine.com" header.h="Content-Transfer-Encoding:Content-Type:Date:Feedback-ID:From:In-Reply-To:Message-ID:MIME-Version:References:Subject:To:X-ME-Proxy:X-ME-Sender"
- Delivery-date: Tue, 13 Oct 2026 09:19:57 +0000
- Dkim2-signature: i=1; m=1; t=1791883192; d=invisiblethingslab.com; mf=PG9tZWdAaW52aXNpYmxldGhpbmdzbGFiLmNvbT4=; rt=PHdpbi1wdi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZz4=; s=fm2:rsa-sha256:V/Zmg58uNJP3t2TEOXlywN5FOpZpn9FXzmRHnd3mq5n2jqP R76PsTlpMfz+Z4INwNSxcgQlvlwU7tfwZM6DSxz08q7TgBsbPYolNZD1SnGMZe5u 9CJCOikrY2jHOxg3++RLOvzBHSX6XkZiofHu91LrCkhNF4aHLKjOFwtXitA7hNUD ds+VUl5uVH451dnCi3sOCBxae3hEg2+ul0wcVLWEnzWS/YOAu5Jqh/qjTA6o2rff DFFeKcDY1lLmYa5jFgoTLI1j+v4VGPaI/skY7F6d1ZCT7eD5sp0kBkX8kyZ2LSAJ R2C3hX21u6Yhfc8E/mKFvtu7/Uh+hvTDE+qggHg==;
- Feedback-id: i409c4082:Fastmail
- List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>
- Message-instance: m=1; h=sha256:yukfUM9VOBmHJa2puLIzDuzTzu4Gv5IhthQHNyALlyQ=:bLCt6LdNRk2HdWvpWl5SvyAhsX9khpMo3M4QBt9R5H0=;
On 13.10.2026 11:12, Tu Dinh wrote:
On 13/10/2026 11:10, Rafał Wojdyła wrote:
On 13.10.2026 10:10, Tu Dinh wrote:
On 13/10/2026 10:01, Owen Smith wrote:
diff --git a/src/xencontrol/xencontrol.c b/src/xencontrol/
xencontrol.c
index a68dcf6..8f21867 100644
--- a/src/xencontrol/xencontrol.c
+++ b/src/xencontrol/xencontrol.c
@@ -407,6 +407,11 @@ XcGnttabPermitForeignAccess2(
BOOL Success;
DWORD Status;
+ if (NumberPages == 0 || NumberPages >
XENCONTROL_GNTTAB_MAX_PAGES) {
I believe the boundary condition of NumberPages ==
XENCONTROL_GNTTAB_MAX_PAGES still causes an overflow? So
XENCONTROL_GNTTAB_MAX_PAGES should be (1024 * 1024 - 1) instead.
MAXULONG / PAGE_SIZE would be a better formulation still, only problem
being PAGE_SIZE is not defined for usermode targets.
Maximum number of pages allowed is also checked in
IoctlGnttabMapForeignPages
against a hard coded 1024*1024.
It would be good to have the same constant/#define referred to in
both places.
Eventually, this ends up in FdoPciHoleAllocate or
FdoMemoryHoleAllocate, depending
on the "UseMemoryHole" setting.
FdoPciHoleAllocate is limited to 4GiB - PAGE_SIZE bytes (i.e.
1024*1024 - 1 pages)
FdoMemoryHoleAllocate's allocations doesnt specify a maximum size,
but the chances
of allocating a contiguous 4GB set of pages would be problematic.
Its likely this check is excessively large, but I'm unsure as to what
the safe correct
maximum would be.
I think in general it'd be nice to bound the usermode grant consumption
to the actual free grant table space (and reserve some certain amount
for the kernel), but that doesn't look simple to implement.
SeLockMemoryPrivilege may also be worth checking in the caller path of
some ioctls.
I'll finally be sending my rework of the grant/map code soon, hopefully
this week. Got caught up with other projects, but I'm testing it now. It
includes new interface versions with bounded batched maps/unmaps, per-
page error reporting and other improvements.
Great to hear. I can share our WIP test suite of evtchn/gnttab ioctls as
well as a few private fixes we've been working on on our side.
That would be nice, I was thinking of adding more comprehensive tests to
the upstream repo.
What's the policy on retaining old xenbus interface versions?
Currently, old xenbus interface versions have to be retained
indefinitely, because since b0b9cc139600 old drivers could still bind to
devices without being aware of compatibility changes.
--
Rafał Wojdyła
Invisible Things Lab
|