From 74c551ed3078a9ae6ab109cfb7595396c8260fdc Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Fri, 25 Oct 2024 14:18:26 +0800 Subject: [PATCH] fix Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 68 ++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 5993138225e4..3e24101c07af 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -214,17 +214,17 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *in static int userspace_pm_address_announce(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local) { - int err; + int err = -EINVAL; if (local->addr.id == 0 || !(local->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) { pr_debug("invalid addr id or flags\n"); - return -EINVAL; + goto announce_err; } err = mptcp_userspace_pm_append_new_local_addr(msk, local, false); if (err < 0) { pr_debug("did not match address and id\n"); - return err; + goto announce_err; } spin_lock_bh(&msk->pm.lock); @@ -237,7 +237,9 @@ static int userspace_pm_address_announce(struct mptcp_sock *msk, spin_unlock_bh(&msk->pm.lock); - return 0; + err = 0; +announce_err: + return err; } int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) @@ -312,16 +314,19 @@ static int userspace_pm_address_remove(struct mptcp_sock *msk, u8 id) { struct sock *sk = (struct sock *)msk; struct mptcp_pm_addr_entry *match; + int err = -EINVAL; - if (id == 0) - return mptcp_userspace_pm_remove_id_zero_address(msk); + if (id == 0) { + err = mptcp_userspace_pm_remove_id_zero_address(msk); + goto out; + } spin_lock_bh(&msk->pm.lock); match = mptcp_userspace_pm_lookup_addr_by_id(msk, id); spin_unlock_bh(&msk->pm.lock); if (!match) { pr_debug("address with specified id not found\n"); - return -EINVAL; + goto out; } mptcp_pm_remove_addr_entry(msk, match); @@ -331,7 +336,9 @@ static int userspace_pm_address_remove(struct mptcp_sock *msk, u8 id) sock_kfree_s(sk, match, sizeof(*match)); spin_unlock_bh(&msk->pm.lock); - return 0; + err = 0; +out: + return err; } int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) @@ -372,23 +379,23 @@ static int userspace_pm_subflow_create(struct mptcp_sock *msk, struct mptcp_addr_info *remote) { struct sock *sk = (struct sock *)msk; - int err; + int err = -EINVAL; if (local->flags & MPTCP_PM_ADDR_FLAG_SIGNAL) { pr_debug("invalid addr flags\n"); - return -EINVAL; + goto create_err; } local->flags |= MPTCP_PM_ADDR_FLAG_SUBFLOW; if (!mptcp_pm_addr_families_match(sk, &local->addr, remote)) { pr_debug("families mismatch\n"); - return -EINVAL; + goto create_err; } err = mptcp_userspace_pm_append_new_local_addr(msk, local, false); if (err < 0) { pr_debug("did not match address and id\n"); - return err; + goto create_err; } err = __mptcp_subflow_connect(sk, local, remote); @@ -399,6 +406,7 @@ static int userspace_pm_subflow_create(struct mptcp_sock *msk, msk->pm.subflows++; spin_unlock_bh(&msk->pm.lock); + create_err: return err; } @@ -501,8 +509,8 @@ static int userspace_pm_subflow_destroy(struct mptcp_sock *msk, struct mptcp_addr_info *remote) { struct sock *sk = (struct sock *)msk; + int err = -EINVAL; struct sock *ssk; - int err = -ESRCH; #if IS_ENABLED(CONFIG_MPTCP_IPV6) if (local->addr.family == AF_INET && ipv6_addr_v4mapped(&remote->addr6)) { @@ -516,27 +524,29 @@ static int userspace_pm_subflow_destroy(struct mptcp_sock *msk, #endif if (local->addr.family != remote->family) { pr_debug("address families do not match\n"); - return -EINVAL; + goto destroy_err; } if (!local->addr.port || !remote->port) { pr_debug("missing local or remote port\n"); - return -EINVAL; + goto destroy_err; } ssk = mptcp_nl_find_ssk(msk, &local->addr, remote); - if (ssk) { - struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); - - spin_lock_bh(&msk->pm.lock); - mptcp_userspace_pm_delete_local_addr(msk, local); - spin_unlock_bh(&msk->pm.lock); - mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); - mptcp_close_ssk(sk, ssk, subflow); - MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW); - err = 0; + if (!ssk) { + err = -ESRCH; + goto destroy_err; } + spin_lock_bh(&msk->pm.lock); + mptcp_userspace_pm_delete_local_addr(msk, local); + spin_unlock_bh(&msk->pm.lock); + mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); + mptcp_close_ssk(sk, ssk, mptcp_subflow_ctx(ssk)); + MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW); + err = 0; + +destroy_err: return err; } @@ -591,12 +601,13 @@ static int userspace_pm_set_flags(struct mptcp_sock *msk, struct mptcp_addr_info *rem) { struct mptcp_pm_addr_entry *entry; + int ret = -EINVAL; u8 bkup = 0; if (loc->addr.family == AF_UNSPEC || rem->family == AF_UNSPEC) { pr_debug("invalid address families\n"); - return -EINVAL; + goto set_flags_err; } if (loc->flags & MPTCP_PM_ADDR_FLAG_BACKUP) @@ -612,7 +623,10 @@ static int userspace_pm_set_flags(struct mptcp_sock *msk, } spin_unlock_bh(&msk->pm.lock); - return mptcp_pm_nl_mp_prio_send_ack(msk, &loc->addr, rem, bkup); + ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc->addr, rem, bkup); + +set_flags_err: + return ret; } int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc,