linux-stable/net/sctp
Marcelo Ricardo Leitner a7585028ac sctp: fail if no bound addresses can be used for a given scope
[ Upstream commit 458e279f86 ]

Currently, if you bind the socket to something like:
        servaddr.sin6_family = AF_INET6;
        servaddr.sin6_port = htons(0);
        servaddr.sin6_scope_id = 0;
        inet_pton(AF_INET6, "::1", &servaddr.sin6_addr);

And then request a connect to:
        connaddr.sin6_family = AF_INET6;
        connaddr.sin6_port = htons(20000);
        connaddr.sin6_scope_id = if_nametoindex("lo");
        inet_pton(AF_INET6, "fe88::1", &connaddr.sin6_addr);

What the stack does is:
 - bind the socket
 - create a new asoc
 - to handle the connect
   - copy the addresses that can be used for the given scope
   - try to connect

But the copy returns 0 addresses, and the effect is that it ends up
trying to connect as if the socket wasn't bound, which is not the
desired behavior. This unexpected behavior also allows KASLR leaks
through SCTP diag interface.

The fix here then is, if when trying to copy the addresses that can
be used for the scope used in connect() it returns 0 addresses, bail
out. This is what TCP does with a similar reproducer.

Reported-by: Pietro Borrello <borrello@diag.uniroma1.it>
Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Reviewed-by: Xin Long <lucien.xin@gmail.com>
Link: https://lore.kernel.org/r/9fcd182f1099f86c6661f3717f63712ddd1c676c.1674496737.git.marcelo.leitner@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-02-06 07:52:46 +01:00
..
associola.c sctp: leave the err path free in sctp_stream_init to sctp_stream_free 2022-08-03 11:59:41 +02:00
auth.c sctp: handle the error returned from sctp_auth_asoc_init_active_key 2022-10-26 13:22:26 +02:00
bind_addr.c sctp: fail if no bound addresses can be used for a given scope 2023-02-06 07:52:46 +01:00
chunk.c
debug.c
diag.c sctp: fix kernel-infoleak for SCTP sockets 2022-03-16 13:21:46 +01:00
endpointola.c sctp: use call_rcu to free endpoint 2022-01-05 12:37:44 +01:00
input.c sctp: read sk->sk_bound_dev_if once in sctp_rcv() 2022-06-14 18:11:37 +02:00
inqueue.c
ipv6.c
Kconfig
Makefile
objcnt.c
offload.c
output.c
outqueue.c
primitive.c
proc.c
protocol.c ip: Fix data-races around sysctl_ip_nonlocal_bind. 2022-07-29 17:14:11 +02:00
sm_make_chunk.c sctp: account stream padding length for reconf chunk 2021-10-20 11:40:15 +02:00
sm_sideeffect.c sctp: check asoc strreset_chunk in sctp_generate_reconf_event 2022-05-09 09:03:24 +02:00
sm_statefuns.c sctp: fix the processing for INIT chunk 2022-03-19 13:40:13 +01:00
sm_statetable.c
socket.c sctp: Initialize daddr on peeled off socket 2022-04-20 09:19:35 +02:00
stream.c sctp: fix memory leak in sctp_stream_outq_migrate() 2022-12-08 11:23:03 +01:00
stream_interleave.c
stream_sched.c sctp: fix memory leak in sctp_stream_outq_migrate() 2022-12-08 11:23:03 +01:00
stream_sched_prio.c sctp: fix memory leak in sctp_stream_outq_migrate() 2022-12-08 11:23:03 +01:00
stream_sched_rr.c sctp: fix memory leak in sctp_stream_outq_migrate() 2022-12-08 11:23:03 +01:00
sysctl.c
transport.c
tsnmap.c
ulpevent.c
ulpqueue.c