[PATCH net v3] ipv6: fix ioam6_id_wide sysctl on 32-bit architectures
From: Shashank Mohan Jain
Date: Sun Nov 22 2026 - 21:30:56 EST
net.ipv6.ioam6_id_wide stores a u64 (netns_sysctl_ipv6.ioam6_id_wide),
but its table entry uses proc_doulongvec_minmax() with .maxlen =
sizeof(u64) and .extra2 pointing at a u64. On 32-bit, unsigned long is
4 bytes, so the handler treats the field as a vector of two 32-bit
values and reads the u64 max through an unsigned long pointer:
- reading prints two numbers ("4294967295 16777215" by default on
little-endian);
- writing one value only replaces one half of the u64: on
little-endian "echo 5 >" leaves 0x00ffffff00000005; on big-endian it
sets the upper half, and the range check uses the upper word of
ioam6_id_wide_max (0x00ffffff).
The wide namespace ID emitted in IOAM trace data is then not the
configured value. Same class of issue as commit 162cf592b577
("net/smc: fix limit_smc_hs sysctl on big-endian architecture").
There is no u64 variant of proc_doulongvec_minmax(), so add a small
local handler. On 64-bit it calls proc_doulongvec_minmax() as before,
so nothing changes there. On 32-bit it goes through proc_dostring() and
kstrtou64(): it reads and writes one value, parses it with base 0
(decimal, hex or octal), accepts surrounding white space, and returns
-EINVAL for a value above IOAM6_DEFAULT_ID_WIDE, for a write of only
"\n", and for a write of 24 bytes or more. A generic u64 helper in
kernel/sysctl.c would be a larger change for net and stable; it can
follow in net-next.
The 32-bit parser is not identical to proc_doulongvec_minmax() for
unusual input: a second value after a space is rejected rather than
ignored, and a leading "+" is accepted. As the sysctl did not work on
32-bit before, this only affects input that was already broken there.
The bug was discovered by an AI coding agent (Claude Code) reading the
code. It was confirmed and the fix tested on i386 and x86_64 kernels
under QEMU, with a small static test program as init: before the fix,
i386 reads "4294967295 16777215", and after "echo 5" it reads
"5 16777215". With the fix, i386 reads and writes a single 64-bit value,
and x86_64 behaves exactly as before. No kernel change was needed to
reproduce it.
Fixes: 9ee11f0fff20 ("ipv6: ioam: Data plane support for Pre-allocated Trace")
Signed-off-by: Shashank Mohan Jain <jain.sm@xxxxxxxxx>
---
v3:
- Keep proc_doulongvec_minmax() on 64-bit, so 64-bit parsing does not
change at all; the string based parser is used on 32-bit only
(Sashiko review of v2 listed several 64-bit parsing differences).
- Set .procname in the temporary table, so the sysctl write warning
names ioam6_id_wide (Sashiko review of v2).
v2: https://lore.kernel.org/netdev/20261122013848.14287-1-jain.sm@xxxxxxxxx/
- Keep -EINVAL for a write of only "\n", as before; a continued write
at a non-zero offset in strict mode is still ignored (Justin Iurman).
- Changelog: describe how the bug was found and how the fix was tested
in plain English, instead of an Assisted-by tag.
- Cc the sysctl maintainers.
v1: https://lore.kernel.org/netdev/20261118042958.83243-1-jain.sm@xxxxxxxxx/
Prepared with Claude Code (Anthropic), model Claude Opus 5.5
(claude-opus-5-5).
Tested on net.git main af6737b90668: x86_64 and i386 defconfig builds,
plus a build-only 32-bit big-endian powerpc (pmac32_defconfig). W=1
shows no warnings for sysctl_net_ipv6.o before or after.
Under QEMU (TCG) with a small static test program as init, x86_64 gives
exactly the same output as the unpatched kernel for every case. i386
reads and writes one 64-bit value, with the same results as v2. With
sysctl_writes_strict=0, the "file position was not 0" warning names
ioam6_id_wide on i386, as it does on x86_64.
The big-endian kernel was built only, not run.
I did not add Cc: stable; please add it if you think it fits.
net/ipv6/sysctl_net_ipv6.c | 49 +++++++++++++++++++++++++++++++++++++-
1 file changed, 48 insertions(+), 1 deletion(-)
diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
index 1a0a36dcda..c93ccf7e98 100644
--- a/net/ipv6/sysctl_net_ipv6.c
+++ b/net/ipv6/sysctl_net_ipv6.c
@@ -30,6 +30,53 @@ static u32 rt6_multipath_hash_fields_all_mask =
static u32 ioam6_id_max = IOAM6_DEFAULT_ID;
static u64 ioam6_id_wide_max = IOAM6_DEFAULT_ID_WIDE;
+/* unsigned long is 32-bit on some arches, so handle the u64 here */
+static int proc_ioam6_id_wide(const struct ctl_table *table, int write,
+ void *buffer, size_t *lenp, loff_t *ppos)
+{
+ u64 *valp = table->data;
+ char buf[24] = "";
+ const struct ctl_table tmp = {
+ .procname = table->procname,
+ .data = buf,
+ .maxlen = sizeof(buf),
+ };
+ loff_t pos = *ppos;
+ u64 val;
+ int ret;
+
+ /* on 64-bit, unsigned long is a u64: keep the generic handler */
+ if (IS_ENABLED(CONFIG_64BIT))
+ return proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
+
+ if (!write) {
+ snprintf(buf, sizeof(buf), "%llu", READ_ONCE(*valp));
+ return proc_dostring(&tmp, write, buffer, lenp, ppos);
+ }
+
+ /* an empty write changes nothing, as with proc_doulongvec_minmax() */
+ if (!*lenp)
+ return 0;
+
+ /* reject what may not fit in buf, proc_dostring() would truncate it */
+ if (*lenp >= sizeof(buf))
+ return -EINVAL;
+
+ ret = proc_dostring(&tmp, write, buffer, lenp, ppos);
+ if (ret)
+ return ret;
+
+ /* a lone "\n" is invalid, a continued write in strict mode is ignored */
+ if (!buf[0])
+ return pos ? 0 : -EINVAL;
+
+ if (kstrtou64(strim(buf), 0, &val) || val > ioam6_id_wide_max)
+ return -EINVAL;
+
+ WRITE_ONCE(*valp, val);
+ return 0;
+}
+
static int proc_rt6_multipath_hash_policy(const struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos)
{
@@ -210,7 +257,7 @@ static const struct ctl_table ipv6_table_template[] = {
.data = &init_net.ipv6.sysctl.ioam6_id_wide,
.maxlen = sizeof(u64),
.mode = 0644,
- .proc_handler = proc_doulongvec_minmax,
+ .proc_handler = proc_ioam6_id_wide,
.extra2 = &ioam6_id_wide_max,
},
};
--
2.54.0 (Apple Git-157)