Re: [PATCH net v3 1/3] sctp: Hold RCU read lock while iterating over address list

From: Simon Horman

Date: Wed Oct 29 2025 - 12:38:43 EST


On Tue, Oct 28, 2025 at 05:12:26PM +0100, Stefan Wiehler wrote:
> With CONFIG_PROVE_RCU_LIST=y and by executing
>
> $ netcat -l --sctp &
> $ netcat --sctp localhost &
> $ ss --sctp
>
> one can trigger the following Lockdep-RCU splat(s):

...

> diff --git a/net/sctp/diag.c b/net/sctp/diag.c
> index 996c2018f0e6..1a8761f87bf1 100644
> --- a/net/sctp/diag.c
> +++ b/net/sctp/diag.c
> @@ -73,19 +73,23 @@ static int inet_diag_msg_sctpladdrs_fill(struct sk_buff *skb,
> struct nlattr *attr;
> void *info = NULL;
>
> + rcu_read_lock();
> list_for_each_entry_rcu(laddr, address_list, list)
> addrcnt++;
> + rcu_read_unlock();
>
> attr = nla_reserve(skb, INET_DIAG_LOCALS, addrlen * addrcnt);
> if (!attr)
> return -EMSGSIZE;
>
> info = nla_data(attr);

Hi Stefan,

If the number of entries in list increases while rcu_read_lock is not held,
between when addrcnt is calculated and when info is written, then can an
overrun occur while writing info?

> + rcu_read_lock();
> list_for_each_entry_rcu(laddr, address_list, list) {
> memcpy(info, &laddr->a, sizeof(laddr->a));
> memset(info + sizeof(laddr->a), 0, addrlen - sizeof(laddr->a));
> info += addrlen;
> }
> + rcu_read_unlock();
>
> return 0;
> }
> --
> 2.51.0
>