[PATCH mptcp-net] mptcp: use sock_kfree_s instead of kfree

Geliang Tang posted 1 patch 3 weeks ago
Failed in applying to current master (apply log)
net/mptcp/pm_userspace.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH mptcp-net] mptcp: use sock_kfree_s instead of kfree
Posted by Geliang Tang 3 weeks ago
From: Geliang Tang <tanggeliang@kylinos.cn>

The local address entries on userspace_pm_local_addr_list are allocated
by sock_kmalloc(). It's better to use sock_kfree_s() to free each of them
and adjust the allocated size, instead of using kfree().

Fixes: 24430f8bf516 ("mptcp: add address into userspace pm list")
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 net/mptcp/pm_userspace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index a3b93fb01dd7..f83eeb04d7c9 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -94,6 +94,7 @@ static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk,
 						struct mptcp_pm_addr_entry *addr)
 {
 	struct mptcp_pm_addr_entry *entry, *tmp;
+	struct sock *sk = (struct sock *)msk;
 
 	list_for_each_entry_safe(entry, tmp, &msk->pm.userspace_pm_local_addr_list, list) {
 		if (mptcp_addresses_equal(&entry->addr, &addr->addr, false)) {
@@ -101,7 +102,7 @@ static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk,
 			 * be used multiple times (e.g. fullmesh mode).
 			 */
 			list_del_rcu(&entry->list);
-			kfree(entry);
+			sock_kfree_s(sk, entry, sizeof(*entry));
 			msk->pm.local_addr_used--;
 			return 0;
 		}
-- 
2.45.2
Re: [PATCH mptcp-net] mptcp: use sock_kfree_s instead of kfree
Posted by Matthieu Baerts 2 weeks, 6 days ago
Hi Geliang,

On 31/10/2024 08:49, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> The local address entries on userspace_pm_local_addr_list are allocated
> by sock_kmalloc(). It's better to use sock_kfree_s() to free each of them
> and adjust the allocated size, instead of using kfree().

Thank you for the fix!

Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>

Now in our tree (I slightly modified the commit message to say it is
"required" to use sock_kfree_s()):

New patches for t/upstream-net and t/upstream:
- 10225fa09def: mptcp: use sock_kfree_s instead of kfree
- Results: d72fc6f97589..b3a5bd8682ef (export-net)
- Results: 2e11fab4d3e0..e696c82b4c5f (export)

Tests are now in progress:

- export-net:
https://github.com/multipath-tcp/mptcp_net-next/commit/06c3fa1ec4966b86c8be0ced5e3764460451ea2c/checks
- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/06709216e8b6bb4c80db23131714e85c8043be18/checks

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.