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

[PATCH v2 1/2] symbols: make KSYM_NAME_LEN include the trailing NUL


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Mykola Kvach <Mykola_Kvach@xxxxxxxx>
  • Date: Mon, 16 Nov 2026 19:24:35 +0000
  • Accept-language: en-US, uk-UA
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=juM5dmLD01EZkbD8MHLMChMKBIDS5WC0KtpuX+vfFb8=; b=yN8flXQj5h1Jdk68vWWQ4rbgJehBBBiysv1nLbPILkY6Ff5mLZen1ViRry9GJ31uvoJQjBQw2ZLbALVkUq94V+t/g6Nu033pEZKSryUEBwp62Q/WXIVB4cap1/opRgb73wkCuQCxtx1CxFznuykhDeZOIOSnlwB6AdLO5ZPsUEkNwaO7pE91bvq7myNsDAoC5jU7g4jENsO/mHol0T2h82aUwNF8CqNIhCH9zp7Td7BmlKNOnPX4fnrb7VRpMviUHMwyVY2LLc7w+TCS0obMEJOW9DriThl7rVoeb1OAL9fqg2feFAiSbI5ObBaDZr9FFctxd2FkH45xxn0lxAKRQA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jDDF7GG9UMQap+26Zm160s8JxHpEz0os1g2o9ZKOL8RQ3T1LsuKDiaqraSB8v6BOjWB4wUR7kQdJM9XKfBqcJCLaElhlizR8dBnFifakQ0uny9quL/vBLvf1md8nq9IprrXliYt+61yTDLijVhnm5ypJfvIt7SC2y9n8QWo6det6WHH+tKGkSaQCEK8vefxfPBJy3BWLX4d2vEJsdqMH9LkUn/lskQZjxgEoQmDJGX7YgqYEalVIEH3DTxM6b041hv7gViOMXHXd539iXLND11Y6i7J3HJkK4dU6yGpxKp4tXEhR82S/yH6JgHPWveI+jf2kGNXAVIzgi5JpBQfQwA==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:x-ms-exchange-senderadcheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Mon, 16 Nov 2026 19:24:38 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHddgAd1bEPPCGwdE6lH+O+/yfQ/g==
  • Thread-topic: [PATCH v2 1/2] symbols: make KSYM_NAME_LEN include the trailing NUL

write_src() expands compression tokens into a 128-byte buffer. A token
can contain the type byte and a valid 127-byte symbol name, leaving no
space for the NUL written by expand_symbol().

Make KSYM_NAME_LEN include the terminating NUL, following Linux commit
9281acea6a36 ("kallsyms: make KSYM_NAME_LEN include space for trailing
'\0'"). Set it to 128 and adjust the runtime users to keep their buffers
at 128 bytes.

write_src() keeps an extra byte for the type, so its buffer grows to
the required 129 bytes without changing the buffer declaration.

livepatch.c passes KSYM_NAME_LEN to strlcpy(), which now preserves up to
127 characters instead of 126.

With --all-symbols and 64 identical 127-byte names of type T, ASan reports
a stack-buffer-overflow. The fixed tool passes this case under ASan/UBSan.

Assisted-by: Codex:GPT-6.1
Signed-off-by: Mykola Kvach <mykola_kvach@xxxxxxxx>
---
Changes in v2:
- Previously patch 2; move it before the name-length check so that check
  uses the final KSYM_NAME_LEN convention from the start.
- Make KSYM_NAME_LEN include the trailing NUL, following Linux (Jan).
- Set KSYM_NAME_LEN to 128 and update the runtime users, preserving
  their 128-byte buffers.
- Use KSYM_NAME_LEN + 1 for the token buffer, keeping it at 129 bytes.
- Drop the claim that the overflow only occurs with very small symbol
  tables.

 xen/arch/x86/platform_hypercall.c | 2 +-
 xen/common/symbols.c              | 6 +++---
 xen/common/vsprintf.c             | 2 +-
 xen/include/xen/symbols.h         | 3 ++-
 xen/tools/symbols.c               | 3 ++-
 5 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/xen/arch/x86/platform_hypercall.c 
b/xen/arch/x86/platform_hypercall.c
index 0f3c791fc2..17096b1485 100644
--- a/xen/arch/x86/platform_hypercall.c
+++ b/xen/arch/x86/platform_hypercall.c
@@ -892,7 +892,7 @@ ret_t do_platform_op(
 
     case XENPF_get_symbol:
     {
-        static char name[KSYM_NAME_LEN + 1]; /* protected by xenpf_lock */
+        static char name[KSYM_NAME_LEN]; /* protected by xenpf_lock */
         XEN_GUEST_HANDLE(char) nameh;
         uint32_t namelen, copylen;
         unsigned long addr;
diff --git a/xen/common/symbols.c b/xen/common/symbols.c
index 61af77979d..ba8e31c8c6 100644
--- a/xen/common/symbols.c
+++ b/xen/common/symbols.c
@@ -113,7 +113,7 @@ const char *symbols_lookup(unsigned long addr,
     unsigned long symbol_end = 0;
     const struct virtual_region *region;
 
-    namebuf[KSYM_NAME_LEN] = 0;
+    namebuf[KSYM_NAME_LEN - 1] = 0;
     namebuf[0] = 0;
 
     region = find_text_region(addr);
@@ -247,7 +247,7 @@ int xensyms_read(uint32_t *symnum, char *type,
 
 unsigned long symbols_lookup_by_name(const char *symname)
 {
-    char name[KSYM_NAME_LEN + 1];
+    char name[KSYM_NAME_LEN];
 #ifdef CONFIG_FAST_SYMBOL_LOOKUP
     unsigned long low, high;
 #else
@@ -299,7 +299,7 @@ unsigned long symbols_lookup_by_name(const char *symname)
 
 static void __init test_lookup(unsigned long addr, const char *expected)
 {
-    char buf[KSYM_NAME_LEN + 1];
+    char buf[KSYM_NAME_LEN];
     const char *name, *symname;
     unsigned long size, offs;
 
diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c
index 90192fd9e8..491975facc 100644
--- a/xen/common/vsprintf.c
+++ b/xen/common/vsprintf.c
@@ -397,7 +397,7 @@ static char *pointer(char *str, const char *end, const char 
**fmt_ptr,
     case 'S': /* Symbol name unconditionally with offset and size */
     {
         unsigned long sym_size, sym_offset;
-        char namebuf[KSYM_NAME_LEN+1];
+        char namebuf[KSYM_NAME_LEN];
 
         /* Advance parents fmt string, as we have consumed 's' or 'S' */
         ++*fmt_ptr;
diff --git a/xen/include/xen/symbols.h b/xen/include/xen/symbols.h
index 20bbb28ef2..f53e899b6e 100644
--- a/xen/include/xen/symbols.h
+++ b/xen/include/xen/symbols.h
@@ -3,7 +3,8 @@
 
 #include <xen/types.h>
 
-#define KSYM_NAME_LEN 127
+/* Longest symbol name, including the terminating NUL. */
+#define KSYM_NAME_LEN 128
 
 /*
  * Typedef for the callback functions that symbols_lookup
diff --git a/xen/tools/symbols.c b/xen/tools/symbols.c
index 9db1c0a20c..14a045f098 100644
--- a/xen/tools/symbols.c
+++ b/xen/tools/symbols.c
@@ -33,7 +33,7 @@
 #include <stdbool.h>
 #include <ctype.h>
 
-#define KSYM_NAME_LEN          127
+#define KSYM_NAME_LEN          128
 
 
 struct sym_entry {
@@ -338,6 +338,7 @@ static void write_src(void)
        unsigned int i, k, off, ends;
        unsigned int best_idx[256];
        unsigned int *markers;
+       /* Type byte, then the longest name with its terminating NUL. */
        char buf[KSYM_NAME_LEN+1];
 
        if (map_only) {
-- 
2.53.0

 


Rackspace

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