Re: [PATCH net-next v4 2/7] net: cap sockopt_expand_out() at MAX_RW_COUNT

From: Joe Damato

Date: Tue Nov 03 2026 - 16:52:20 EST


On Tue, Nov 03, 2026 at 03:01:01AM -0800, Breno Leitao wrote:
> sockopt_expand_out() grows the output iterator up to INT_MAX, but the
> MCAST_MSFILTER getters converted by the next two patches rewind it with
> iov_iter_revert() once they know the real reply size. iov_iter_revert()
> refuses to unroll past MAX_RW_COUNT:
>
> if (WARN_ON(unroll > MAX_RW_COUNT))
> return;
>
> MAX_RW_COUNT is INT_MAX rounded down to a page boundary, so a caller
> that expands into the (MAX_RW_COUNT, INT_MAX] range and then reverts
> hits that WARN_ON, and the iterator is left where it was instead of
> rewound. So does a caller whose optlen already covers such a size.
>
> Cap the size at MAX_RW_COUNT instead, before the early return for an
> optlen that already covers it, so a size that could never be reverted
> later is rejected up front.
>
> Sashiko found this while reviewing the conversions.
>
> Acked-by: Ido Schimmel <idosch@xxxxxxxxxx>
> Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
> ---
> include/linux/net.h | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>

Reviewed-by: Joe Damato <joe@xxxxxxx>