* [PATCH net v2] ipv6: fix ioam6_id_wide sysctl on 32-bit architectures
@ 2026-11-22 1:38 Shashank Mohan Jain
2026-11-23 1:40 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Shashank Mohan Jain @ 2026-11-22 1:38 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Justin Iurman
Cc: Simon Horman, Joel Granados, netdev, linux-kernel
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 use a small
local handler that goes through proc_dostring() and kstrtou64(). A
generic u64 helper in kernel/sysctl.c would be a larger change for net
and stable; it can follow in net-next. For normal input the handler
behaves as the 64-bit one does today: base 0 parsing (decimal, hex or
octal), surrounding white space is accepted, values above
IOAM6_DEFAULT_ID_WIDE return -EINVAL, and a write of only "\n" returns
-EINVAL. A continued write at a non-zero offset in strict mode is
ignored, as before. Input too long for the 24-byte buffer is rejected
rather than truncated by proc_dostring().
One change on 64-bit: a write of two numbers such as "5 6" is now
rejected with -EINVAL, instead of being a partial write that sets the
value to 5.
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 gives the same results as x86_64, and on x86_64 reads, writes and
range checks behave 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@gmail.com>
---
v2:
- 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: say that on 64-bit "5 6" is now rejected with -EINVAL
instead of being a partial write that sets 5 (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@gmail.com/
Prepared with Claude Code (Anthropic), model Claude Opus 5.5
(claude-opus-5-5).
Tested on net.git main d5b89d55a322: 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, i386 now
gives the same results as x86_64. On x86_64 vs unpatched: a lone "\n"
still returns -EINVAL, a continued write at a non-zero offset with
sysctl_writes_strict=1 is still ignored and succeeds, "5 6" now returns
-EINVAL instead of setting 5, and 21 to 23 digit input is now accepted.
Other changes seen: a lone "\n" at a non-zero offset with
sysctl_writes_strict=0 is ignored instead of returning -EINVAL, and a
read in small chunks returns the whole value.
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 | 45 ++++++++++++++++++++++++++++++++++++--
1 file changed, 43 insertions(+), 2 deletions(-)
diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
index 1a0a36dcda..61c28df64d 100644
--- a/net/ipv6/sysctl_net_ipv6.c
+++ b/net/ipv6/sysctl_net_ipv6.c
@@ -30,6 +30,48 @@ 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 = {
+ .data = buf,
+ .maxlen = sizeof(buf),
+ };
+ loff_t pos = *ppos;
+ u64 val;
+ int ret;
+
+ 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;
+
+ /* proc_dostring() would silently truncate a longer input */
+ 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,8 +252,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,
- .extra2 = &ioam6_id_wide_max,
+ .proc_handler = proc_ioam6_id_wide,
},
};
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net v2] ipv6: fix ioam6_id_wide sysctl on 32-bit architectures
2026-11-22 1:38 [PATCH net v2] ipv6: fix ioam6_id_wide sysctl on 32-bit architectures Shashank Mohan Jain
@ 2026-11-23 1:40 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 1:40 UTC (permalink / raw)
To: jain.sm
Cc: davem, edumazet, kuba, pabeni, justin.iurman, horms,
joel.granados, netdev, linux-kernel
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] proc_ioam6_id_wide() (net/ipv6/sysctl_net_ipv6.c) changes how
writes are parsed on 64-bit in several ways the commit body does not…
- [Low] proc_ioam6_id_wide() passes a temporary ctl_table `tmp` with only
.data and .maxlen set to proc_dostring().
--
ipv6: fix ioam6_id_wide sysctl on 32-bit architectures
net.ipv6.ioam6_id_wide was handled by proc_doulongvec_minmax(). This
commit replaces that with a local handler, proc_ioam6_id_wide(), which
formats and parses the u64 through proc_dostring() and kstrtou64(). This
fixes 32-bit architectures, where unsigned long is 4 bytes and the old
handler treated the u64 as a vector of two 32-bit values.
> diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
> index 1a0a36dcdabc1..61c28df64d582 100644
> --- a/net/ipv6/sysctl_net_ipv6.c
> +++ b/net/ipv6/sysctl_net_ipv6.c
> @@ -30,6 +30,48 @@ 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 = {
> + .data = buf,
> + .maxlen = sizeof(buf),
> + };
[Severity: Low]
The temporary table passed to proc_dostring() has no procname. Will the
sysctl write warning then print "(null)" instead of ioam6_id_wide?
On every write, proc_dostring() calls:
kernel/sysctl.c:proc_dostring() {
if (SYSCTL_USER_TO_KERN(dir))
proc_first_pos_non_zero_ignore(ppos, table);
...
}
Take kernel.sysctl_writes_strict=0 and a write shorter than 24 bytes at
a non-zero offset. That write reaches warn_sysctl_write(&tmp):
pr_warn_once("%s wrote to %s when file position was not 0!\n"
[ ... ]
current->comm, table->procname);
This is pr_warn_once(), so a message that doesn't name the file would
use up the only warning for the whole system. The old
proc_doulongvec_minmax() path passed the real table here.
Would adding .procname = table->procname to tmp be enough?
> + loff_t pos = *ppos;
> + u64 val;
> + int ret;
> +
> + 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;
> +
> + /* proc_dostring() would silently truncate a longer input */
> + 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;
[Severity: Medium]
The commit message says:
One change on 64-bit: a write of two numbers such as "5 6" is now
rejected with -EINVAL, instead of being a partial write that sets the
value to 5.
Does proc_ioam6_id_wide() change 64-bit behaviour in other ways that
should be listed too?
The length guard checks the total write size. But _proc_do_string()
copies at most maxlen - 1 bytes and stops at the first '\n' or NUL:
kernel/sysctl.c:_proc_do_string() {
...
while ((p - buffer) < *lenp && len < maxlen - 1) {
c = *(p++);
if (c == 0 || c == '\n')
break;
data[len++] = c;
}
...
}
So a 24-byte write of 23 characters plus "\n" fits in buf without being
truncated, yet the guard rejects it. The guard also rejects "5\n"
followed by 22 or more bytes, and a value padded with 24 or more bytes
of whitespace. The old path accepted all of these, fully or as a partial
write.
Is the comment "proc_dostring() would silently truncate a longer input"
accurate for these cases?
In strict mode, a continued write at a non-zero offset now returns
-EINVAL if it is 24 bytes or longer, and is ignored if it is shorter.
The old proc_first_pos_non_zero_ignore() path ignored it at any length.
Because _proc_do_string() stops at the first '\n', "\n5" or " \n 5"
leaves buf empty and returns -EINVAL. The old path skipped the newline
in proc_skip_spaces() and set 5.
In the other direction, "5\n6" now succeeds, sets 5 and reports all
bytes consumed. Meanwhile "5 6" and "5\t6" return -EINVAL.
kstrtou64() also skips a leading '+', so "+5" is now accepted. The old
path rejected it in proc_get_long():
if (!isdigit(*p))
return -EINVAL;
Two other changes are only described below the --- line, so they won't
reach git history: 21 to 23 digit input is now accepted, and a lone "\n"
at a non-zero offset in non-strict mode is now ignored.
Could the up-front total length check be dropped? After proc_dostring(),
the handler could check whether a terminator was found within
maxlen - 1 bytes, and decide explicitly whether data after '\n' is
rejected. Any 64-bit changes that remain could then go in the commit
body.
> +
> + WRITE_ONCE(*valp, val);
> + return 0;
> +}
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122013848.14287-1-jain.sm%40gmail.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-23 1:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 1:38 [PATCH net v2] ipv6: fix ioam6_id_wide sysctl on 32-bit architectures Shashank Mohan Jain
2026-11-23 1:40 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox