mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 10:01:39 -05:00
sctp: Hold sock lock while iterating over address list
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>
This commit is contained in:
committed by
Jakub Kicinski
parent
95aef86ab2
commit
f1fc201148
@@ -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