Skip to content

Commit f1fc201

Browse files
sephalonkuba-moo
authored andcommitted
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: 8f840e4 ("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>
1 parent 95aef86 commit f1fc201

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

net/sctp/diag.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,15 @@ struct sctp_comm_param {
230230
bool net_admin;
231231
};
232232

233-
static size_t inet_assoc_attr_size(struct sctp_association *asoc)
233+
static size_t inet_assoc_attr_size(struct sock *sk,
234+
struct sctp_association *asoc)
234235
{
235236
int addrlen = sizeof(struct sockaddr_storage);
236237
int addrcnt = 0;
237238
struct sctp_sockaddr_entry *laddr;
238239

239240
list_for_each_entry_rcu(laddr, &asoc->base.bind_addr.address_list,
240-
list)
241+
list, lockdep_sock_is_held(sk))
241242
addrcnt++;
242243

243244
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
263264
if (err)
264265
return err;
265266

266-
rep = nlmsg_new(inet_assoc_attr_size(assoc), GFP_KERNEL);
267-
if (!rep)
267+
lock_sock(sk);
268+
269+
rep = nlmsg_new(inet_assoc_attr_size(sk, assoc), GFP_KERNEL);
270+
if (!rep) {
271+
release_sock(sk);
268272
return -ENOMEM;
273+
}
269274

270-
lock_sock(sk);
271275
if (ep != assoc->ep) {
272276
err = -EAGAIN;
273277
goto out;

0 commit comments

Comments
 (0)