Re: [PATCH net] sctp: initialize new_value in custom proc_dointvec sysctl handlers

From: Ian Rogers

Date: Tue Dec 01 2026 - 12:38:16 EST


On Thu, Nov 26, 2026 at 2:17 PM Xin Long <lucien.xin@xxxxxxxxx> wrote:
>
> On Wed, Nov 25, 2026 at 8:43 PM <willemb@xxxxxxxxxx> wrote:
> >
> > Returning early on reads (`if (!write) return proc_dointvec(ctl, write,
> > buffer, lenp, ppos);`), initializing `old_value = READ_ONCE(...)` /
> > `new_value = old_value` unconditionally on the write path (keeping Clang's
> > -Wconditional-uninitialized happy), and gating the commit block on
> > `new_value != old_value` with WRITE_ONCE() avoids both the data race and
> > stale writebacks on ignored writes.
> Right.
>
> I think you can replace proc_sctp_do_rto_min() and proc_sctp_do_rto_max()
> with proc_dointvec_minmax().
>
> Then apply Willem's suggestion only to proc_sctp_do_auth() and
> proc_sctp_do_probe_interval().
[...]
> With sctp_sysctl_mutex, we don't need the extra old_value variable, unlike
> in proc_sctp_do_auth() and proc_sctp_do_probe_interval() above.

Thanks both for the thorough review! I've updated the patch to replace
proc_sctp_do_rto_min() and proc_sctp_do_rto_max() with
proc_dointvec_minmax(), apply the early !write return + READ_ONCE() /
WRITE_ONCE() + new_value != old_value check to proc_sctp_do_auth() and
proc_sctp_do_probe_interval(), and hold sctp_sysctl_mutex across
new_value initialization and proc_dointvec() in proc_sctp_do_udp_port().

I also reproduced the unpatched stack corruption/-EINVAL in QEMU with
CONFIG_INIT_STACK_NONE=y and verified the fix under
CONFIG_KCSAN_STRICT=y, CONFIG_PROVE_LOCKING=y, and
tools/testing/selftests/net/sctp_vrf.sh. I'll send v2 shortly.

Thanks,
Ian

pw-bot: cr