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

[PATCH 08/11] xenvkbd: Add size annotations to buffer parameters


  • To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Césaire Mounah <cesaire.mounah@xxxxxxxxxx>
  • Date: Mon, 19 Oct 2026 15:14:34 +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: Césaire Mounah <cesaire.mounah@xxxxxxxxxx>
  • Delivery-date: Mon, 19 Oct 2026 13:14:54 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

Buffer parameters with a length parameter were annotated as single
elements, so /analyze could not check accesses to them. Annotate them
with their size: bus data buffers as _Inout_updates_bytes_(Length),
matching GET_SET_DEVICE_DATA, and copy sources and report buffers as
_In_reads_bytes_.
No functional change.

Assisted-by: Claude:opus-5.5
Signed-off-by: Césaire Mounah <cesaire.mounah@xxxxxxxxxx>
---
 src/xenvkbd/assert.h   |  8 ++++----
 src/xenvkbd/bus.c      | 20 ++++++++++----------
 src/xenvkbd/fdo.c      | 20 ++++++++++----------
 src/xenvkbd/fdo.h      | 20 ++++++++++----------
 src/xenvkbd/hid.c      | 16 ++++++++--------
 src/xenvkbd/hid.h      |  6 +++---
 src/xenvkbd/pdo.c      | 20 ++++++++++----------
 src/xenvkbd/pdo.h      | 20 ++++++++++----------
 src/xenvkbd/registry.c |  8 ++++----
 src/xenvkbd/registry.h |  8 ++++----
 src/xenvkbd/ring.c     | 10 +++++-----
 11 files changed, 78 insertions(+), 78 deletions(-)

diff --git a/src/xenvkbd/assert.h b/src/xenvkbd/assert.h
index ec2650c..6540eb7 100644
--- a/src/xenvkbd/assert.h
+++ b/src/xenvkbd/assert.h
@@ -154,10 +154,10 @@ __Bug(
 
 static __inline BOOLEAN
 _IsZeroMemory(
-    _In_ PCSTR      Caller,
-    _In_ PCSTR      Name,
-    _In_ PVOID      Buffer,
-    _In_ ULONG      Length
+    _In_ PCSTR                      Caller,
+    _In_ PCSTR                      Name,
+    _In_reads_bytes_(Length) PVOID  Buffer,
+    _In_ ULONG                      Length
     )
 {
     ULONG           Offset;
diff --git a/src/xenvkbd/bus.c b/src/xenvkbd/bus.c
index b1a0c73..52dd2ed 100644
--- a/src/xenvkbd/bus.c
+++ b/src/xenvkbd/bus.c
@@ -126,11 +126,11 @@ static
 _Function_class_(GET_SET_DEVICE_DATA)
 ULONG
 BusSetData(
-    _In_ PVOID              _Context,
-    _In_ ULONG              DataType,
-    _In_ PVOID              Buffer,
-    _In_ ULONG              Offset,
-    _In_ ULONG              Length
+    _In_ PVOID                             _Context,
+    _In_ ULONG                             DataType,
+    _Inout_updates_bytes_(Length) PVOID    Buffer,
+    _In_ ULONG                             Offset,
+    _In_ ULONG                             Length
     )
 {
     PXENVKBD_BUS_CONTEXT    Context = _Context;
@@ -146,11 +146,11 @@ static
 _Function_class_(GET_SET_DEVICE_DATA)
 ULONG
 BusGetData(
-    _In_ PVOID              _Context,
-    _In_ ULONG              DataType,
-    _In_ PVOID              Buffer,
-    _In_ ULONG              Offset,
-    _In_ ULONG              Length
+    _In_ PVOID                             _Context,
+    _In_ ULONG                             DataType,
+    _Inout_updates_bytes_(Length) PVOID    Buffer,
+    _In_ ULONG                             Offset,
+    _In_ ULONG                             Length
     )
 {
     PXENVKBD_BUS_CONTEXT    Context = _Context;
diff --git a/src/xenvkbd/fdo.c b/src/xenvkbd/fdo.c
index 95ed60d..133a62b 100644
--- a/src/xenvkbd/fdo.c
+++ b/src/xenvkbd/fdo.c
@@ -370,11 +370,11 @@ FdoTranslateBusAddress(
 
 ULONG
 FdoSetBusData(
-    _In_ PXENVKBD_FDO       Fdo,
-    _In_ ULONG              DataType,
-    _In_ PVOID              Buffer,
-    _In_ ULONG              Offset,
-    _In_ ULONG              Length
+    _In_ PXENVKBD_FDO                      Fdo,
+    _In_ ULONG                             DataType,
+    _Inout_updates_bytes_(Length) PVOID    Buffer,
+    _In_ ULONG                             Offset,
+    _In_ ULONG                             Length
     )
 {
     PBUS_INTERFACE_STANDARD BusInterface;
@@ -391,11 +391,11 @@ FdoSetBusData(
 
 ULONG
 FdoGetBusData(
-    _In_ PXENVKBD_FDO       Fdo,
-    _In_ ULONG              DataType,
-    _In_ PVOID              Buffer,
-    _In_ ULONG              Offset,
-    _In_ ULONG              Length
+    _In_ PXENVKBD_FDO                      Fdo,
+    _In_ ULONG                             DataType,
+    _Inout_updates_bytes_(Length) PVOID    Buffer,
+    _In_ ULONG                             Offset,
+    _In_ ULONG                             Length
     )
 {
     PBUS_INTERFACE_STANDARD BusInterface;
diff --git a/src/xenvkbd/fdo.h b/src/xenvkbd/fdo.h
index d23cef6..3cd0b2d 100644
--- a/src/xenvkbd/fdo.h
+++ b/src/xenvkbd/fdo.h
@@ -100,20 +100,20 @@ FdoTranslateBusAddress(
 
 extern ULONG
 FdoSetBusData(
-    _In_ PXENVKBD_FDO   Fdo,
-    _In_ ULONG          DataType,
-    _In_ PVOID          Buffer,
-    _In_ ULONG          Offset,
-    _In_ ULONG          Length
+    _In_ PXENVKBD_FDO                      Fdo,
+    _In_ ULONG                             DataType,
+    _Inout_updates_bytes_(Length) PVOID    Buffer,
+    _In_ ULONG                             Offset,
+    _In_ ULONG                             Length
     );
 
 extern ULONG
 FdoGetBusData(
-    _In_ PXENVKBD_FDO   Fdo,
-    _In_ ULONG          DataType,
-    _In_ PVOID          Buffer,
-    _In_ ULONG          Offset,
-    _In_ ULONG          Length
+    _In_ PXENVKBD_FDO                      Fdo,
+    _In_ ULONG                             DataType,
+    _Inout_updates_bytes_(Length) PVOID    Buffer,
+    _In_ ULONG                             Offset,
+    _In_ ULONG                             Length
     );
 
 extern NTSTATUS
diff --git a/src/xenvkbd/hid.c b/src/xenvkbd/hid.c
index 3e1bd53..97e2f96 100644
--- a/src/xenvkbd/hid.c
+++ b/src/xenvkbd/hid.c
@@ -65,11 +65,11 @@ struct _XENVKBD_HID_CONTEXT {
 
 static FORCEINLINE NTSTATUS
 HidCopyBuffer(
-    _Out_writes_bytes_opt_(Length) PVOID    Buffer,
-    _In_ ULONG                              Length,
-    _In_ const VOID                         *Source,
-    _In_ ULONG                              SourceLength,
-    _Out_ PULONG                            Returned
+    _Out_writes_bytes_opt_(Length) PVOID         Buffer,
+    _In_ ULONG                                   Length,
+    _In_reads_bytes_(SourceLength) const VOID    *Source,
+    _In_ ULONG                                   SourceLength,
+    _Out_ PULONG                                 Returned
     )
 {
     if (Buffer == NULL)
@@ -674,9 +674,9 @@ HidTeardown(
 
 BOOLEAN
 HidSendReadReport(
-    _In_ PXENVKBD_HID_CONTEXT   Context,
-    _In_ PVOID                  Buffer,
-    _In_ ULONG                  Length
+    _In_ PXENVKBD_HID_CONTEXT         Context,
+    _In_reads_bytes_(Length) PVOID    Buffer,
+    _In_ ULONG                        Length
     )
 {
     if (!Context->Enabled)
diff --git a/src/xenvkbd/hid.h b/src/xenvkbd/hid.h
index f2b4089..cc7dfd6 100644
--- a/src/xenvkbd/hid.h
+++ b/src/xenvkbd/hid.h
@@ -65,9 +65,9 @@ HidTeardown(
 
 extern BOOLEAN
 HidSendReadReport(
-    _In_ PXENVKBD_HID_CONTEXT   Context,
-    _In_ PVOID                  Buffer,
-    _In_ ULONG                  Length
+    _In_ PXENVKBD_HID_CONTEXT         Context,
+    _In_reads_bytes_(Length) PVOID    Buffer,
+    _In_ ULONG                        Length
     );
 
 #endif  // _XENVKBD_VKBD_H
diff --git a/src/xenvkbd/pdo.c b/src/xenvkbd/pdo.c
index ff2e0be..60a5ae5 100644
--- a/src/xenvkbd/pdo.c
+++ b/src/xenvkbd/pdo.c
@@ -487,11 +487,11 @@ PdoTranslateBusAddress(
 
 ULONG
 PdoSetBusData(
-    _In_ PXENVKBD_PDO   Pdo,
-    _In_ ULONG          DataType,
-    _In_ PVOID          Buffer,
-    _In_ ULONG          Offset,
-    _In_ ULONG          Length
+    _In_ PXENVKBD_PDO                      Pdo,
+    _In_ ULONG                             DataType,
+    _Inout_updates_bytes_(Length) PVOID    Buffer,
+    _In_ ULONG                             Offset,
+    _In_ ULONG                             Length
     )
 {
     Trace("<===>\n");
@@ -505,11 +505,11 @@ PdoSetBusData(
 
 ULONG
 PdoGetBusData(
-    _In_ PXENVKBD_PDO   Pdo,
-    _In_ ULONG          DataType,
-    _In_ PVOID          Buffer,
-    _In_ ULONG          Offset,
-    _In_ ULONG          Length
+    _In_ PXENVKBD_PDO                      Pdo,
+    _In_ ULONG                             DataType,
+    _Inout_updates_bytes_(Length) PVOID    Buffer,
+    _In_ ULONG                             Offset,
+    _In_ ULONG                             Length
     )
 {
     Trace("<===>\n");
diff --git a/src/xenvkbd/pdo.h b/src/xenvkbd/pdo.h
index beb88bc..28f396c 100644
--- a/src/xenvkbd/pdo.h
+++ b/src/xenvkbd/pdo.h
@@ -104,20 +104,20 @@ PdoTranslateBusAddress(
 
 extern ULONG
 PdoSetBusData(
-    _In_ PXENVKBD_PDO   Pdo,
-    _In_ ULONG          DataType,
-    _In_ PVOID          Buffer,
-    _In_ ULONG          Offset,
-    _In_ ULONG          Length
+    _In_ PXENVKBD_PDO                      Pdo,
+    _In_ ULONG                             DataType,
+    _Inout_updates_bytes_(Length) PVOID    Buffer,
+    _In_ ULONG                             Offset,
+    _In_ ULONG                             Length
     );
 
 extern ULONG
 PdoGetBusData(
-    _In_ PXENVKBD_PDO   Pdo,
-    _In_ ULONG          DataType,
-    _In_ PVOID          Buffer,
-    _In_ ULONG          Offset,
-    _In_ ULONG          Length
+    _In_ PXENVKBD_PDO                      Pdo,
+    _In_ ULONG                             DataType,
+    _Inout_updates_bytes_(Length) PVOID    Buffer,
+    _In_ ULONG                             Offset,
+    _In_ ULONG                             Length
     );
 
 extern NTSTATUS
diff --git a/src/xenvkbd/registry.c b/src/xenvkbd/registry.c
index c488fc6..52ba33b 100644
--- a/src/xenvkbd/registry.c
+++ b/src/xenvkbd/registry.c
@@ -1240,10 +1240,10 @@ fail1:
 
 NTSTATUS
 RegistryUpdateBinaryValue(
-    _In_ HANDLE                     Key,
-    _In_ PSTR                       Name,
-    _In_ PVOID                      Buffer,
-    _In_ ULONG                      Length
+    _In_ HANDLE                       Key,
+    _In_ PSTR                         Name,
+    _In_reads_bytes_(Length) PVOID    Buffer,
+    _In_ ULONG                        Length
     )
 {
     ANSI_STRING                     Ansi;
diff --git a/src/xenvkbd/registry.h b/src/xenvkbd/registry.h
index ae3eec1..2451e03 100644
--- a/src/xenvkbd/registry.h
+++ b/src/xenvkbd/registry.h
@@ -160,10 +160,10 @@ RegistryQueryBinaryValue(
 
 extern NTSTATUS
 RegistryUpdateBinaryValue(
-    _In_ HANDLE Key,
-    _In_ PSTR   Name,
-    _In_ PVOID  Buffer,
-    _In_ ULONG  Length
+    _In_ HANDLE                       Key,
+    _In_ PSTR                         Name,
+    _In_reads_bytes_(Length) PVOID    Buffer,
+    _In_ ULONG                        Length
     );
 
 extern NTSTATUS
diff --git a/src/xenvkbd/ring.c b/src/xenvkbd/ring.c
index a4f5769..9a79fc9 100644
--- a/src/xenvkbd/ring.c
+++ b/src/xenvkbd/ring.c
@@ -109,11 +109,11 @@ __RingFree(
 
 static FORCEINLINE NTSTATUS
 __RingCopyBuffer(
-    _Out_writes_bytes_opt_(Length) PVOID    Buffer,
-    _In_ ULONG                              Length,
-    _In_ const VOID                         *Source,
-    _In_ ULONG                              SourceLength,
-    _Out_ PULONG                            Returned
+    _Out_writes_bytes_opt_(Length) PVOID         Buffer,
+    _In_ ULONG                                   Length,
+    _In_reads_bytes_(SourceLength) const VOID    *Source,
+    _In_ ULONG                                   SourceLength,
+    _Out_ PULONG                                 Returned
     )
 {
     if (Buffer == NULL)
-- 
2.55.0.windows.5



--
Césaire Mounah | Vates Windows Guest Tools Engineer

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®.