From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Geliang Tang <tanggeliang@kylinos.cn>,
Kuniyuki Iwashima <kuniyu@amazon.com>,
"Matthieu Baerts (NGI0)" <matttbe@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.12.y 2/4] sock: add sock_kmemdup helper
Date: Wed, 16 Sep 2026 22:50:16 -0400 [thread overview]
Message-ID: <20260917025018.3917338-2-sashal@kernel.org> (raw)
In-Reply-To: <20260917025018.3917338-1-sashal@kernel.org>
From: Geliang Tang <tanggeliang@kylinos.cn>
[ Upstream commit 456cc675b6d4cadd4872a477d8976ff56eef4b6f ]
This patch adds the sock version of kmemdup() helper, named sock_kmemdup(),
to duplicate the input "src" memory block using the socket's option memory
buffer.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Acked-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/f828077394c7d1f3560123497348b438c875b510.1740735165.git.tanggeliang@kylinos.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Stable-dep-of: f9f0068e8813 ("mptcp: pm: userspace: fix address ID overflow")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
include/net/sock.h | 2 ++
net/core/sock.c | 16 ++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/include/net/sock.h b/include/net/sock.h
index dffbaaa7fe493..d97e4bac6be35 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1840,6 +1840,8 @@ static inline struct sk_buff *sock_alloc_send_skb(struct sock *sk,
}
void *sock_kmalloc(struct sock *sk, int size, gfp_t priority);
+void *sock_kmemdup(struct sock *sk, const void *src,
+ int size, gfp_t priority);
void sock_kfree_s(struct sock *sk, void *mem, int size);
void sock_kzfree_s(struct sock *sk, void *mem, int size);
void sk_send_sigurg(struct sock *sk);
diff --git a/net/core/sock.c b/net/core/sock.c
index e8b03cf3a428c..f90cfe4588b84 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2837,6 +2837,22 @@ void *sock_kmalloc(struct sock *sk, int size, gfp_t priority)
}
EXPORT_SYMBOL(sock_kmalloc);
+/*
+ * Duplicate the input "src" memory block using the socket's
+ * option memory buffer.
+ */
+void *sock_kmemdup(struct sock *sk, const void *src,
+ int size, gfp_t priority)
+{
+ void *mem;
+
+ mem = sock_kmalloc(sk, size, priority);
+ if (mem)
+ memcpy(mem, src, size);
+ return mem;
+}
+EXPORT_SYMBOL(sock_kmemdup);
+
/* Free an option memory block. Note, we actually want the inline
* here as this allows gcc to detect the nullify and fold away the
* condition entirely.
--
2.53.0
next prev parent reply other threads:[~2026-09-17 2:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 16:31 FAILED: patch "[PATCH] mptcp: pm: userspace: fix address ID overflow" failed to apply to 6.12-stable tree gregkh
2026-09-17 2:50 ` [PATCH 6.12.y 1/4] mptcp: pm: drop match in userspace_pm_append_new_local_addr Sasha Levin
2026-09-17 2:50 ` Sasha Levin [this message]
2026-09-17 2:50 ` [PATCH 6.12.y 3/4] mptcp: use sock_kmemdup for address entry Sasha Levin
2026-09-17 2:50 ` [PATCH 6.12.y 4/4] mptcp: pm: userspace: fix address ID overflow Sasha Levin
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=20260917025018.3917338-2-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@amazon.com \
--cc=matttbe@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tanggeliang@kylinos.cn \
/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