From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: Breno Leitao <leitao@debian.org>,
David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>,
Shuah Khan <shuah@kernel.org>, Eric Dumazet <edumazet@kernel.org>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
david.laight.linux@gmail.com, kernel-team@meta.com
Subject: Re: [PATCH net-next v4 2/7] net: cap sockopt_expand_out() at MAX_RW_COUNT
Date: Wed, 4 Nov 2026 12:15:51 +0800 [thread overview]
Message-ID: <bb64096f-2c73-428b-ac74-881227539a2f@linux.dev> (raw)
In-Reply-To: <20261103-sockopt_expand_out_v2-v4-2-2d36da923578@debian.org>
On 11/3/26 7:01 PM, 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@nvidia.com>
> Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>
> ---
> include/linux/net.h | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/net.h b/include/linux/net.h
> index e2a866fbcfa5ea..de56f89d475ee2 100644
> --- a/include/linux/net.h
> +++ b/include/linux/net.h
> @@ -80,16 +80,21 @@ static inline int sockopt_init_user(sockopt_t *opt, char __user *optval,
> *
> * Call it before writing through opt->iter_out: it re-anchors the iterator at
> * the head of optval. Only a user buffer can be longer than the optlen the
> - * caller declared, so a kernel-backed optval is refused with -EINVAL.
> + * caller declared, so a kernel-backed optval is refused with -EINVAL. So is a
> + * @size above MAX_RW_COUNT, which iov_iter_revert() could not unroll.
> */
> static inline int sockopt_expand_out(sockopt_t *opt, size_t size)
> {
> + /* iov_iter_revert() refuses to unroll past MAX_RW_COUNT, so a size
> + * beyond that could never be reverted back to the fixed part later,
> + * even when optlen already covers it.
> + */
> + if (size > MAX_RW_COUNT)
> + return -EINVAL;
> +
> if (size <= (size_t)opt->optlen)
> return 0;
>
> - if (size > INT_MAX)
> - return -EINVAL;
> -
> /* Re-anchoring reads iter_out.ubuf, so the iterator has to be a user
> * buffer that nothing has written through yet.
> */
>
next prev parent reply other threads:[~2026-11-04 4:16 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 11:00 [PATCH net-next v4 0/7] ipv4,ipv6: convert the getsockopt switches to sockopt_t Breno Leitao
2026-11-03 11:01 ` [PATCH net-next v4 1/7] ipv6: treat a negative optlen as 4 in do_ipv6_getsockopt() Breno Leitao
2026-11-03 21:45 ` Joe Damato
2026-11-04 4:15 ` Jiayuan Chen
2026-11-03 11:01 ` [PATCH net-next v4 2/7] net: cap sockopt_expand_out() at MAX_RW_COUNT Breno Leitao
2026-11-03 19:32 ` Stanislav Fomichev
2026-11-03 21:47 ` Joe Damato
2026-11-04 4:15 ` Jiayuan Chen [this message]
2026-11-03 11:01 ` [PATCH net-next v4 3/7] ipv6: mcast: convert ip6_mc_msfget() to sockopt_t Breno Leitao
2026-11-03 23:01 ` Joe Damato
2026-11-04 6:07 ` Jiayuan Chen
2026-11-03 11:01 ` [PATCH net-next v4 4/7] ipv4: igmp: convert ip_mc_gsfget() " Breno Leitao
2026-11-03 23:03 ` Joe Damato
2026-11-03 11:01 ` [PATCH net-next v4 5/7] ipv4: convert do_ip_getsockopt() " Breno Leitao
2026-11-03 23:07 ` Joe Damato
2026-11-04 6:05 ` Jiayuan Chen
2026-11-03 11:01 ` [PATCH net-next v4 6/7] ipv6: convert do_ipv6_getsockopt() " Breno Leitao
2026-11-03 19:32 ` Stanislav Fomichev
2026-11-03 11:01 ` [PATCH net-next v4 7/7] selftests: net: getsockopt_iter: cover ip and ipv6 Breno Leitao
2026-11-03 19:32 ` Stanislav Fomichev
2026-11-03 23:32 ` Joe Damato
2026-11-06 19:50 ` [PATCH net-next v4 0/7] ipv4,ipv6: convert the getsockopt switches to sockopt_t patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bb64096f-2c73-428b-ac74-881227539a2f@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=david.laight.linux@gmail.com \
--cc=dsahern@kernel.org \
--cc=eddyz87@gmail.com \
--cc=edumazet@kernel.org \
--cc=emil@etsalapatis.com \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.