From: Mat Martineau <mathew.j.martineau@linux.intel.com>
To: Matthieu Baerts <matthieu.baerts@tessares.net>,
Paolo Abeni <pabeni@redhat.com>
Cc: mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-net v4 02/12] mptcp: netlink: respect v4/v6-only sockets
Date: Tue, 3 Jan 2023 17:35:37 -0800 (PST) [thread overview]
Message-ID: <454ad691-ca73-f9d0-79b3-9760893bcdf4@linux.intel.com> (raw)
In-Reply-To: <20221228101748.2518303-3-matthieu.baerts@tessares.net>
On Wed, 28 Dec 2022, Matthieu Baerts wrote:
> If an MPTCP socket has been created with AF_INET6 and the IPV6_V6ONLY
> option has been set, the userspace PM would allow creating subflows
> using IPv4 addresses, e.g. mapped in v6.
>
> The userspace PM will also accept creating subflows with local and
> remote addresses having different families resulting in the creation
> of non expected subflows.
>
Could you clarify the consequences of a userspace PM allowing these
subflows on unpatched kernels? Are resources leaked, or undefined behavior
caused?
> It is then required to check the given families can be accepted. This is
> done by using a new helper for addresses family matching, taking care of
> IPv4 vs IPv4-mapped-IPv6 addresses. This helper will be re-used later by
> the in-kernel path-manager to use mixed IPv4 and IPv6 addresses.
>
> While at it, a clear error message is now reported if there are some
> conflicts with the families that have been passed by the userspace.
>
> Fixes: 702c2f646d42 ("mptcp: netlink: allow userspace-driven subflow establishment")
> Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
> ---
> net/mptcp/pm.c | 25 +++++++++++++++++++++++++
> net/mptcp/pm_userspace.c | 7 +++++++
> net/mptcp/protocol.h | 3 +++
> 3 files changed, 35 insertions(+)
>
> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
> index cdeb7280ac76..083f3f8322c0 100644
> --- a/net/mptcp/pm.c
> +++ b/net/mptcp/pm.c
> @@ -413,6 +413,31 @@ void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
> }
> }
>
> +/* if sk is ipv4 or ipv6_only allows only same-family local and remote addresses,
> + * otherwise allow any matching local/remote pair
> + */
> +bool mptcp_pm_addr_families_match(const struct sock *sk,
> + const struct mptcp_addr_info *loc,
> + const struct mptcp_addr_info *rem)
> +{
> + bool mptcp_is_v4 = sk->sk_family == AF_INET;
> +
> +#if IS_ENABLED(CONFIG_MPTCP_IPV6)
> + bool loc_is_v4 = loc->family == AF_INET || ipv6_addr_v4mapped(&loc->addr6);
> + bool rem_is_v4 = rem->family == AF_INET || ipv6_addr_v4mapped(&rem->addr6);
> +
> + if (mptcp_is_v4)
> + return loc_is_v4 && rem_is_v4;
> +
> + if (ipv6_only_sock(sk))
> + return !loc_is_v4 && !rem_is_v4;
> +
> + return loc_is_v4 == rem_is_v4;
> +#else
> + return mptcp_is_v4 && loc->family == AF_INET && rem->family && AF_INET;
^^
Looks like you intended:
+ return mptcp_is_v4 && loc->family == AF_INET && rem->family == AF_INET;
Correct?
- Mat
> +#endif
> +}
> +
> void mptcp_pm_data_reset(struct mptcp_sock *msk)
> {
> u8 pm_type = mptcp_get_pm_type(sock_net((struct sock *)msk));
> diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
> index 65dcc55a8ad8..ea6ad9da7493 100644
> --- a/net/mptcp/pm_userspace.c
> +++ b/net/mptcp/pm_userspace.c
> @@ -294,6 +294,13 @@ int mptcp_nl_cmd_sf_create(struct sk_buff *skb, struct genl_info *info)
> }
>
> sk = (struct sock *)msk;
> +
> + if (!mptcp_pm_addr_families_match(sk, &addr_l, &addr_r)) {
> + GENL_SET_ERR_MSG(info, "families mismatch");
> + err = -EINVAL;
> + goto create_err;
> + }
> +
> lock_sock(sk);
>
> err = __mptcp_subflow_connect(sk, &addr_l, &addr_r);
> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index b2b56a80e817..871ec3e93314 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
> @@ -793,6 +793,9 @@ int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
> int mptcp_pm_parse_entry(struct nlattr *attr, struct genl_info *info,
> bool require_family,
> struct mptcp_pm_addr_entry *entry);
> +bool mptcp_pm_addr_families_match(const struct sock *sk,
> + const struct mptcp_addr_info *loc,
> + const struct mptcp_addr_info *rem);
> void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk);
> void mptcp_pm_nl_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk);
> void mptcp_pm_new_connection(struct mptcp_sock *msk, const struct sock *ssk, int server_side);
> --
> 2.37.2
>
>
>
--
Mat Martineau
Intel
next prev parent reply other threads:[~2023-01-04 1:35 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-28 10:17 [PATCH mptcp-net/next v4 00/12] mptcp: add support for mixed v4/v6 Matthieu Baerts
2022-12-28 10:17 ` [PATCH mptcp-net v4 01/12] mptcp: explicitly specify sock family at subflow creation time Matthieu Baerts
2022-12-28 10:17 ` [PATCH mptcp-net v4 02/12] mptcp: netlink: respect v4/v6-only sockets Matthieu Baerts
2023-01-04 1:35 ` Mat Martineau [this message]
2023-01-04 17:03 ` Matthieu Baerts
2022-12-28 10:17 ` [PATCH mptcp-net v4 03/12] selftests: mptcp: userspace: validate v4-v6 subflows mix Matthieu Baerts
2022-12-28 10:17 ` [PATCH mptcp-next v4 04/12] mptcp: let the in-kernel PM use mixed IPv4 and IPv6 addresses Matthieu Baerts
2022-12-28 10:17 ` [PATCH mptcp-next v4 05/12] mptcp: propagate sk_ipv6only to subflows Matthieu Baerts
2022-12-28 10:17 ` [PATCH mptcp-next v4 06/12] selftests: mptcp: add test-cases for mixed v4/v6 subflows Matthieu Baerts
2022-12-28 10:17 ` [PATCH mptcp-next v4 07/12] mptcp: remove assigned but unused value Matthieu Baerts
2022-12-28 10:17 ` [PATCH mptcp-next v4 08/12] mptcp: userspace pm: use a single point of exit Matthieu Baerts
2022-12-28 10:17 ` [PATCH mptcp-next v4 09/12] selftests: mptcp: userspace: print titles Matthieu Baerts
2022-12-28 10:17 ` [PATCH mptcp-next v4 10/12] selftests: mptcp: userspace: refactor asserts Matthieu Baerts
2022-12-28 10:17 ` [PATCH mptcp-next v4 11/12] selftests: mptcp: userspace: print error details if any Matthieu Baerts
2022-12-28 10:17 ` [PATCH mptcp-next v4 12/12] selftests: mptcp: userspace: avoid read errors Matthieu Baerts
2022-12-28 16:13 ` selftests: mptcp: userspace: avoid read errors: Tests Results MPTCP CI
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=454ad691-ca73-f9d0-79b3-9760893bcdf4@linux.intel.com \
--to=mathew.j.martineau@linux.intel.com \
--cc=matthieu.baerts@tessares.net \
--cc=mptcp@lists.linux.dev \
--cc=pabeni@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox