Re: [PATCH net-next v4 5/7] ipv4: convert do_ip_getsockopt() to sockopt_t

From: Joe Damato

Date: Tue Nov 03 2026 - 18:10:05 EST


On Tue, Nov 03, 2026 at 03:01:04AM -0800, Breno Leitao wrote:
> Convert the SOL_IP switch and ip_mroute_getsockopt() to sockopt_t, its
> last leaf on a sockptr_t pair. The IP_MSFILTER and MCAST_MSFILTER
> bridges go away.
>
> ip_getsockopt() builds the sockopt_t with sockopt_init_user() and
> writes optlen back unconditionally, because IP_OPTIONS and others
> report a length and can then fail. ip_mc_msfget() therefore stores its
> length only after its last copy, so a copy failure can't report a
> changed one.
>
> The write-back also happens before the netfilter fallback, so an
> unwritable optlen turns any error into -EFAULT and skips the fallback.
> Likewise optlen is now read before the level check and the MRT_*
> dispatch, so an unreadable or negative one wins over -EOPNOTSUPP.
>
> IP_OPTIONS with no options set and IP_PKTOPTIONS used to return the
> result of copy_to_sockptr(), the number of bytes not copied, so an
> unwritable optlen made getsockopt() return 4. They now return -EFAULT.
>
> sol_ip_sockopt() builds the sockopt_t with sockptr_to_sockopt() and
> stores optlen back as well. This extra code will go away when we
> convert sol_ip_sockopt() to talk sockopt as well, but for now we are
> converting the leaves.
>
> Acked-by: Stanislav Fomichev <sdf@xxxxxxxxxxx>
> Acked-by: Ido Schimmel <idosch@xxxxxxxxxx>
> Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
> ---
> include/linux/mroute.h | 4 +--
> include/net/ip.h | 3 +-
> net/core/filter.c | 18 ++++++++---
> net/ipv4/igmp.c | 3 +-
> net/ipv4/ip_sockglue.c | 87 +++++++++++++++++++-------------------------------
> net/ipv4/ipmr.c | 11 +++----
> 6 files changed, 56 insertions(+), 70 deletions(-)

[...]

> @@ -1711,43 +1707,25 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
> case IP_MSFILTER:
> {
> struct ip_msfilter msf;
> - struct kvec kvec;
> - sockopt_t opt;
>
> if (len < IP_MSFILTER_SIZE(0)) {
> err = -EINVAL;
> goto out;
> }
> - if (copy_from_sockptr(&msf, optval, IP_MSFILTER_SIZE(0))) {
> + if (copy_from_iter(&msf, IP_MSFILTER_SIZE(0), &sopt->iter_in) !=
> + IP_MSFILTER_SIZE(0)) {

The line wrapping is a little weird looking to me. Not sure if there is
anything that can be done about it and not sure it would be worth a re-spin
just because I think it's a little ugly :)

Reviewed-by: Joe Damato <joe@xxxxxxx>