Re: [PATCH net] sctp: Hold sock lock while iterating over address list

Eric Dumazet <[email protected]>
Newsgroups org.kernel.vger.linux-sctp,org.kernel.vger.linux-kernel,org.kernel.vger.netdev
Message-ID <CANn89iKbLadNizRB28AoNw8McQXgqtknbH3zdhErDku-m5rjqQ@mail.gmail.com>
We need a changelog.

On Mon, Oct 27, 2025 at 1:50 AM Stefan Wiehler <[email protected]> wrote:
>
> Fixes: 8f840e47f190 ("sctp: add the sctp_diag.c file")
> Signed-off-by: Stefan Wiehler <[email protected]>
> ---
>  net/sctp/diag.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/net/sctp/diag.c b/net/sctp/diag.c
> index 996c2018f0e6..7f7e2773e047 100644
> --- a/net/sctp/diag.c
> +++ b/net/sctp/diag.c
> @@ -223,14 +223,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))
> @@ -256,11 +257,12 @@ 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);
> +       lock_sock(sk);
> +
> +       rep = nlmsg_new(inet_assoc_attr_size(sk, assoc), GFP_KERNEL);
>         if (!rep)
>                 return -ENOMEM;

If -ENOMEM is returned, the lock needs to be released ?

Please do not rush patches like this.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.