mptcp: add accept_subflow re-check
authorGeliang Tang <geliangtang@gmail.com>
Thu, 24 Sep 2020 00:29:53 +0000 (08:29 +0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 25 Sep 2020 02:58:33 +0000 (19:58 -0700)
The re-check of pm->accept_subflow with pm->lock held was missing, this
patch fixed it.

Suggested-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/mptcp/pm.c

index 39a76620d0a5eb21fdbe24bd5f5541016956c8b3..be4157279e159f5c9fad221f1bda01ff4b64caa1 100644 (file)
@@ -48,7 +48,7 @@ void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side)
 bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk)
 {
        struct mptcp_pm_data *pm = &msk->pm;
-       int ret;
+       int ret = 0;
 
        pr_debug("msk=%p subflows=%d max=%d allow=%d", msk, pm->subflows,
                 pm->subflows_max, READ_ONCE(pm->accept_subflow));
@@ -58,9 +58,11 @@ bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk)
                return false;
 
        spin_lock_bh(&pm->lock);
-       ret = pm->subflows < pm->subflows_max;
-       if (ret && ++pm->subflows == pm->subflows_max)
-               WRITE_ONCE(pm->accept_subflow, false);
+       if (READ_ONCE(pm->accept_subflow)) {
+               ret = pm->subflows < pm->subflows_max;
+               if (ret && ++pm->subflows == pm->subflows_max)
+                       WRITE_ONCE(pm->accept_subflow, false);
+       }
        spin_unlock_bh(&pm->lock);
 
        return ret;