All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net 0/2] mptcp: Bug fixes
@ 2021-08-18 23:42 Mat Martineau
  2021-08-18 23:42 ` [PATCH net 1/2] mptcp: fix memory leak on address flush Mat Martineau
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Mat Martineau @ 2021-08-18 23:42 UTC (permalink / raw)
  To: netdev; +Cc: Mat Martineau, davem, kuba, matthieu.baerts, mptcp, geliangtang

Here are two bug fixes for the net tree:

Patch 1 fixes a memory leak that could be encountered when clearing the
list of advertised MPTCP addresses.

Patch 2 fixes a protocol issue early in an MPTCP connection, to ensure
both peers correctly understand that the full MPTCP connection handshake
has completed even when the server side quickly sends an ADD_ADDR
option.


Matthieu Baerts (1):
  mptcp: full fully established support after ADD_ADDR

Paolo Abeni (1):
  mptcp: fix memory leak on address flush

 net/mptcp/options.c    | 10 +++-------
 net/mptcp/pm_netlink.c | 44 ++++++++++++------------------------------
 2 files changed, 15 insertions(+), 39 deletions(-)


base-commit: fb4b1373dcab086d0619c29310f0466a0b2ceb8a
-- 
2.33.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net 1/2] mptcp: fix memory leak on address flush
  2021-08-18 23:42 [PATCH net 0/2] mptcp: Bug fixes Mat Martineau
@ 2021-08-18 23:42 ` Mat Martineau
  2021-08-18 23:42 ` [PATCH net 2/2] mptcp: full fully established support after ADD_ADDR Mat Martineau
  2021-08-19 11:30 ` [PATCH net 0/2] mptcp: Bug fixes patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: Mat Martineau @ 2021-08-18 23:42 UTC (permalink / raw)
  To: netdev
  Cc: Paolo Abeni, davem, kuba, matthieu.baerts, mptcp, geliangtang,
	Mat Martineau

From: Paolo Abeni <pabeni@redhat.com>

The endpoint cleanup path is prone to a memory leak, as reported
by syzkaller:

 BUG: memory leak
 unreferenced object 0xffff88810680ea00 (size 64):
   comm "syz-executor.6", pid 6191, jiffies 4295756280 (age 24.138s)
   hex dump (first 32 bytes):
     58 75 7d 3c 80 88 ff ff 22 01 00 00 00 00 ad de  Xu}<....".......
     01 00 02 00 00 00 00 00 ac 1e 00 07 00 00 00 00  ................
   backtrace:
     [<0000000072a9f72a>] kmalloc include/linux/slab.h:591 [inline]
     [<0000000072a9f72a>] mptcp_nl_cmd_add_addr+0x287/0x9f0 net/mptcp/pm_netlink.c:1170
     [<00000000f6e931bf>] genl_family_rcv_msg_doit.isra.0+0x225/0x340 net/netlink/genetlink.c:731
     [<00000000f1504a2c>] genl_family_rcv_msg net/netlink/genetlink.c:775 [inline]
     [<00000000f1504a2c>] genl_rcv_msg+0x341/0x5b0 net/netlink/genetlink.c:792
     [<0000000097e76f6a>] netlink_rcv_skb+0x148/0x430 net/netlink/af_netlink.c:2504
     [<00000000ceefa2b8>] genl_rcv+0x24/0x40 net/netlink/genetlink.c:803
     [<000000008ff91aec>] netlink_unicast_kernel net/netlink/af_netlink.c:1314 [inline]
     [<000000008ff91aec>] netlink_unicast+0x537/0x750 net/netlink/af_netlink.c:1340
     [<0000000041682c35>] netlink_sendmsg+0x846/0xd80 net/netlink/af_netlink.c:1929
     [<00000000df3aa8e7>] sock_sendmsg_nosec net/socket.c:704 [inline]
     [<00000000df3aa8e7>] sock_sendmsg+0x14e/0x190 net/socket.c:724
     [<000000002154c54c>] ____sys_sendmsg+0x709/0x870 net/socket.c:2403
     [<000000001aab01d7>] ___sys_sendmsg+0xff/0x170 net/socket.c:2457
     [<00000000fa3b1446>] __sys_sendmsg+0xe5/0x1b0 net/socket.c:2486
     [<00000000db2ee9c7>] do_syscall_x64 arch/x86/entry/common.c:50 [inline]
     [<00000000db2ee9c7>] do_syscall_64+0x38/0x90 arch/x86/entry/common.c:80
     [<000000005873517d>] entry_SYSCALL_64_after_hwframe+0x44/0xae

We should not require an allocation to cleanup stuff.

Rework the code a bit so that the additional RCU work is no more needed.

Fixes: 1729cf186d8a ("mptcp: create the listening socket for new port")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
---
 net/mptcp/pm_netlink.c | 44 ++++++++++++------------------------------
 1 file changed, 12 insertions(+), 32 deletions(-)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 56263c2c4014..7b3794459783 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -1135,36 +1135,12 @@ static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net,
 	return 0;
 }
 
-struct addr_entry_release_work {
-	struct rcu_work	rwork;
-	struct mptcp_pm_addr_entry *entry;
-};
-
-static void mptcp_pm_release_addr_entry(struct work_struct *work)
+/* caller must ensure the RCU grace period is already elapsed */
+static void __mptcp_pm_release_addr_entry(struct mptcp_pm_addr_entry *entry)
 {
-	struct addr_entry_release_work *w;
-	struct mptcp_pm_addr_entry *entry;
-
-	w = container_of(to_rcu_work(work), struct addr_entry_release_work, rwork);
-	entry = w->entry;
-	if (entry) {
-		if (entry->lsk)
-			sock_release(entry->lsk);
-		kfree(entry);
-	}
-	kfree(w);
-}
-
-static void mptcp_pm_free_addr_entry(struct mptcp_pm_addr_entry *entry)
-{
-	struct addr_entry_release_work *w;
-
-	w = kmalloc(sizeof(*w), GFP_ATOMIC);
-	if (w) {
-		INIT_RCU_WORK(&w->rwork, mptcp_pm_release_addr_entry);
-		w->entry = entry;
-		queue_rcu_work(system_wq, &w->rwork);
-	}
+	if (entry->lsk)
+		sock_release(entry->lsk);
+	kfree(entry);
 }
 
 static int mptcp_nl_remove_id_zero_address(struct net *net,
@@ -1244,7 +1220,8 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
 	spin_unlock_bh(&pernet->lock);
 
 	mptcp_nl_remove_subflow_and_signal_addr(sock_net(skb->sk), &entry->addr);
-	mptcp_pm_free_addr_entry(entry);
+	synchronize_rcu();
+	__mptcp_pm_release_addr_entry(entry);
 
 	return ret;
 }
@@ -1297,6 +1274,7 @@ static void mptcp_nl_remove_addrs_list(struct net *net,
 	}
 }
 
+/* caller must ensure the RCU grace period is already elapsed */
 static void __flush_addrs(struct list_head *list)
 {
 	while (!list_empty(list)) {
@@ -1305,7 +1283,7 @@ static void __flush_addrs(struct list_head *list)
 		cur = list_entry(list->next,
 				 struct mptcp_pm_addr_entry, list);
 		list_del_rcu(&cur->list);
-		mptcp_pm_free_addr_entry(cur);
+		__mptcp_pm_release_addr_entry(cur);
 	}
 }
 
@@ -1329,6 +1307,7 @@ static int mptcp_nl_cmd_flush_addrs(struct sk_buff *skb, struct genl_info *info)
 	bitmap_zero(pernet->id_bitmap, MAX_ADDR_ID + 1);
 	spin_unlock_bh(&pernet->lock);
 	mptcp_nl_remove_addrs_list(sock_net(skb->sk), &free_list);
+	synchronize_rcu();
 	__flush_addrs(&free_list);
 	return 0;
 }
@@ -1939,7 +1918,8 @@ static void __net_exit pm_nl_exit_net(struct list_head *net_list)
 		struct pm_nl_pernet *pernet = net_generic(net, pm_nl_pernet_id);
 
 		/* net is removed from namespace list, can't race with
-		 * other modifiers
+		 * other modifiers, also netns core already waited for a
+		 * RCU grace period.
 		 */
 		__flush_addrs(&pernet->local_addr_list);
 	}
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net 2/2] mptcp: full fully established support after ADD_ADDR
  2021-08-18 23:42 [PATCH net 0/2] mptcp: Bug fixes Mat Martineau
  2021-08-18 23:42 ` [PATCH net 1/2] mptcp: fix memory leak on address flush Mat Martineau
@ 2021-08-18 23:42 ` Mat Martineau
  2021-08-19 11:30 ` [PATCH net 0/2] mptcp: Bug fixes patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: Mat Martineau @ 2021-08-18 23:42 UTC (permalink / raw)
  To: netdev; +Cc: Matthieu Baerts, davem, kuba, mptcp, geliangtang, Mat Martineau

From: Matthieu Baerts <matthieu.baerts@tessares.net>

If directly after an MP_CAPABLE 3WHS, the client receives an ADD_ADDR
with HMAC from the server, it is enough to switch to a "fully
established" mode because it has received more MPTCP options.

It was then OK to enable the "fully_established" flag on the MPTCP
socket. Still, best to check if the ADD_ADDR looks valid by looking if
it contains an HMAC (no 'echo' bit). If an ADD_ADDR echo is received
while we are not in "fully established" mode, it is strange and then
we should not switch to this mode now.

But that is not enough. On one hand, the path-manager has be notified
the state has changed. On the other hand, the "fully_established" flag
on the subflow socket should be turned on as well not to re-send the
MP_CAPABLE 3rd ACK content with the next ACK.

Fixes: 84dfe3677a6f ("mptcp: send out dedicated ADD_ADDR packet")
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
---
 net/mptcp/options.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 4452455aef7f..7adcbc1f7d49 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -885,20 +885,16 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
 		return subflow->mp_capable;
 	}
 
-	if (mp_opt->dss && mp_opt->use_ack) {
+	if ((mp_opt->dss && mp_opt->use_ack) ||
+	    (mp_opt->add_addr && !mp_opt->echo)) {
 		/* subflows are fully established as soon as we get any
-		 * additional ack.
+		 * additional ack, including ADD_ADDR.
 		 */
 		subflow->fully_established = 1;
 		WRITE_ONCE(msk->fully_established, true);
 		goto fully_established;
 	}
 
-	if (mp_opt->add_addr) {
-		WRITE_ONCE(msk->fully_established, true);
-		return true;
-	}
-
 	/* If the first established packet does not contain MP_CAPABLE + data
 	 * then fallback to TCP. Fallback scenarios requires a reset for
 	 * MP_JOIN subflows.
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net 0/2] mptcp: Bug fixes
  2021-08-18 23:42 [PATCH net 0/2] mptcp: Bug fixes Mat Martineau
  2021-08-18 23:42 ` [PATCH net 1/2] mptcp: fix memory leak on address flush Mat Martineau
  2021-08-18 23:42 ` [PATCH net 2/2] mptcp: full fully established support after ADD_ADDR Mat Martineau
@ 2021-08-19 11:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-08-19 11:30 UTC (permalink / raw)
  To: Mat Martineau; +Cc: netdev, davem, kuba, matthieu.baerts, mptcp, geliangtang

Hello:

This series was applied to netdev/net.git (refs/heads/master):

On Wed, 18 Aug 2021 16:42:35 -0700 you wrote:
> Here are two bug fixes for the net tree:
> 
> Patch 1 fixes a memory leak that could be encountered when clearing the
> list of advertised MPTCP addresses.
> 
> Patch 2 fixes a protocol issue early in an MPTCP connection, to ensure
> both peers correctly understand that the full MPTCP connection handshake
> has completed even when the server side quickly sends an ADD_ADDR
> option.
> 
> [...]

Here is the summary with links:
  - [net,1/2] mptcp: fix memory leak on address flush
    https://git.kernel.org/netdev/net/c/a0eea5f10eeb
  - [net,2/2] mptcp: full fully established support after ADD_ADDR
    https://git.kernel.org/netdev/net/c/67b12f792d5e

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net 0/2] mptcp: Bug fixes
  2021-09-24  0:04 Mat Martineau
@ 2021-09-24 10:00 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-09-24 10:00 UTC (permalink / raw)
  To: Mat Martineau
  Cc: netdev, davem, kuba, matthieu.baerts, mptcp, fw, dcaratti,
	pabeni, geliangtang

Hello:

This series was applied to netdev/net.git (refs/heads/master):

On Thu, 23 Sep 2021 17:04:10 -0700 you wrote:
> This patch set includes two separate fixes for the net tree:
> 
> Patch 1 makes sure that MPTCP token searches are always limited to the
> appropriate net namespace.
> 
> Patch 2 allows userspace to always change the backup settings for
> configured endpoints even if those endpoints are not currently in use.
> 
> [...]

Here is the summary with links:
  - [net,1/2] mptcp: don't return sockets in foreign netns
    https://git.kernel.org/netdev/net/c/ea1300b9df7c
  - [net,2/2] mptcp: allow changing the 'backup' bit when no sockets are open
    https://git.kernel.org/netdev/net/c/3f4a08909e2c

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net 0/2] mptcp: Bug fixes
@ 2021-09-24  0:04 Mat Martineau
  2021-09-24 10:00 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 6+ messages in thread
From: Mat Martineau @ 2021-09-24  0:04 UTC (permalink / raw)
  To: netdev
  Cc: Mat Martineau, davem, kuba, matthieu.baerts, mptcp, fw, dcaratti,
	pabeni, geliangtang

This patch set includes two separate fixes for the net tree:

Patch 1 makes sure that MPTCP token searches are always limited to the
appropriate net namespace.

Patch 2 allows userspace to always change the backup settings for 
configured endpoints even if those endpoints are not currently in use.


Davide Caratti (1):
  mptcp: allow changing the 'backup' bit when no sockets are open

Florian Westphal (1):
  mptcp: don't return sockets in foreign netns

 net/mptcp/mptcp_diag.c |  2 +-
 net/mptcp/pm_netlink.c |  4 +---
 net/mptcp/protocol.h   |  2 +-
 net/mptcp/subflow.c    |  2 +-
 net/mptcp/syncookies.c | 13 +------------
 net/mptcp/token.c      | 11 ++++++++---
 net/mptcp/token_test.c | 14 ++++++++------
 7 files changed, 21 insertions(+), 27 deletions(-)


base-commit: 9bc62afe03afdf33904f5e784e1ad68c50ff00bb
-- 
2.33.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-09-24 10:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18 23:42 [PATCH net 0/2] mptcp: Bug fixes Mat Martineau
2021-08-18 23:42 ` [PATCH net 1/2] mptcp: fix memory leak on address flush Mat Martineau
2021-08-18 23:42 ` [PATCH net 2/2] mptcp: full fully established support after ADD_ADDR Mat Martineau
2021-08-19 11:30 ` [PATCH net 0/2] mptcp: Bug fixes patchwork-bot+netdevbpf
2021-09-24  0:04 Mat Martineau
2021-09-24 10:00 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.