Skip to content

Commit 95aef86

Browse files
sephalonkuba-moo
authored andcommitted
sctp: Prevent TOCTOU out-of-bounds write
For the following path not holding the sock lock, sctp_diag_dump() -> sctp_for_each_endpoint() -> sctp_ep_dump() make sure not to exceed bounds in case the address list has grown between buffer allocation (time-of-check) and write (time-of-use). Suggested-by: Kuniyuki Iwashima <kuniyu@google.com> Fixes: 8f840e4 ("sctp: add the sctp_diag.c file") Signed-off-by: Stefan Wiehler <stefan.wiehler@nokia.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Acked-by: Xin Long <lucien.xin@gmail.com> Link: https://patch.msgid.link/20251028161506.3294376-3-stefan.wiehler@nokia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 38f5024 commit 95aef86

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/sctp/diag.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ static int inet_diag_msg_sctpladdrs_fill(struct sk_buff *skb,
8888
memcpy(info, &laddr->a, sizeof(laddr->a));
8989
memset(info + sizeof(laddr->a), 0, addrlen - sizeof(laddr->a));
9090
info += addrlen;
91+
92+
if (!--addrcnt)
93+
break;
9194
}
9295
rcu_read_unlock();
9396

0 commit comments

Comments
 (0)