|
[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
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
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |