mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-07-19 21:40:29 +02:00
sctp: Hold sock lock while iterating over address list
[ Upstream commitf1fc201148] Move address list traversal in inet_assoc_attr_size() under the sock lock to avoid holding the RCU read lock. Suggested-by: Xin Long <lucien.xin@gmail.com> Fixes:8f840e47f1("sctp: add the sctp_diag.c file") Signed-off-by: Stefan Wiehler <stefan.wiehler@nokia.com> Acked-by: Xin Long <lucien.xin@gmail.com> Link: https://patch.msgid.link/20251028161506.3294376-4-stefan.wiehler@nokia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
c9119f243d
commit
2ad229bc61
+10
-6
@@ -230,14 +230,15 @@ struct sctp_comm_param {
|
||||
bool net_admin;
|
||||
};
|
||||
|
||||
static size_t inet_assoc_attr_size(struct sctp_association *asoc)
|
||||
static size_t inet_assoc_attr_size(struct sock *sk,
|
||||
struct sctp_association *asoc)
|
||||
{
|
||||
int addrlen = sizeof(struct sockaddr_storage);
|
||||
int addrcnt = 0;
|
||||
struct sctp_sockaddr_entry *laddr;
|
||||
|
||||
list_for_each_entry_rcu(laddr, &asoc->base.bind_addr.address_list,
|
||||
list)
|
||||
list, lockdep_sock_is_held(sk))
|
||||
addrcnt++;
|
||||
|
||||
return nla_total_size(sizeof(struct sctp_info))
|
||||
@@ -263,11 +264,14 @@ static int sctp_sock_dump_one(struct sctp_endpoint *ep, struct sctp_transport *t
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
rep = nlmsg_new(inet_assoc_attr_size(assoc), GFP_KERNEL);
|
||||
if (!rep)
|
||||
return -ENOMEM;
|
||||
|
||||
lock_sock(sk);
|
||||
|
||||
rep = nlmsg_new(inet_assoc_attr_size(sk, assoc), GFP_KERNEL);
|
||||
if (!rep) {
|
||||
release_sock(sk);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (ep != assoc->ep) {
|
||||
err = -EAGAIN;
|
||||
goto out;
|
||||
|
||||
Reference in New Issue
Block a user