The net.inet.tcp.rack.pacing.pace_max_seg sysctl is a 32-bit integer,
but rack_init() copies it into each new connection's 7-bit bitfield
rc_user_set_max_segs. Values that do not fit are truncated, and a value
of 128 becomes 0. A connection with rc_user_set_max_segs of 0 ends up
with a pacing max segment size of 0, and rack_setup_fast_output() then
executes rounddown(left_to_send, 0), causing an integer divide fault:
Fatal trap 18: integer divide fault while in kernel mode #5 rack_do_segment_nounlock+0x29eb ... (fault in rack_setup_fast_output() inlined into rack_output())
The TCP_RACK_PACE_MAX_SEG socket option clamps values above
MAX_USER_SET_SEG (63), but it accepts 0, which leads to the same
division by zero.
Validate the sysctl with a handler that only accepts 1 to
MAX_USER_SET_SEG, and reject a socket option value of 0 with EINVAL
before any state is changed. Sysctl values from 64 to 127 used to be
stored unchanged and are now rejected too.
Reproduced on 15.1-RELEASE with
"sysctl net.inet.tcp.rack.pacing.pace_max_seg=128" while RACK was the
default stack: the host panicked on the next connection's data transfer.
Signed-off-by: Michael Adler <madler@tapil.com>
Fixes: 030434acaf46 ("Update rack to the latest code used at NF.")
MFC after: 2 weeks