Re: [PATCH net-next v4 6/7] ipv6: convert do_ipv6_getsockopt() to sockopt_t
From: Stanislav Fomichev
Date: Tue Nov 03 2026 - 14:34:29 EST
On 11/03, Breno Leitao wrote:
> Convert the SOL_IPV6 switch and its two remaining sockptr_t leaves,
> ip6_mroute_getsockopt() and ipv6_getsockopt_sticky().
>
> ipv6_getsockopt() writes optlen back unconditionally, and
> sol_ipv6_sockopt() builds the sockopt_t with sockptr_to_sockopt() and
> stores optlen back as well.
>
> ipv6_getsockopt() cannot use sockopt_init_user() as its IPv4 sibling
> does, since that rejects a negative optlen and this level answers it as
> 4. See "ipv6: treat a negative optlen as 4 in do_ipv6_getsockopt()".
>
> Instead ipv6_getsockopt() applies that rule itself and builds the
> sockopt_t with the new sockopt_set_user(), which sockopt_init_user() now
> shares. MRT6_* is the exception: it has always rejected a negative
> optlen, and still does.
>
> 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 MRT6_* dispatch, so an unreadable
> or negative one wins over -EOPNOTSUPP.
>
> For the other options, a failing call that passed a negative optlen now
> leaves it as 4 instead of untouched, and the netfilter fallback sees that
> 4 too.
>
> IPV6_2292PKTOPTIONS and the sticky options 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.
>
> The extra code in sol_ipv6_sockopt() will go away when
> sol_ipv6_sockopt() receives sockopt_t, but, for now, it only moves the
> leaves.
>
> Acked-by: Ido Schimmel <idosch@xxxxxxxxxx>
> Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
Acked-by: Stanislav Fomichev <sdf@xxxxxxxxxxx>