restund: fix CVE-2021-21382
[feed/telephony.git] / net / restund / patches / 200-turn-block-forwarding-to-loopback-any.patch
1 From ffa2d56cac3d37715fe1381df81802774240da92 Mon Sep 17 00:00:00 2001
2 From: Dusan Stevanovic <dule@wire.com>
3 Date: Thu, 11 Mar 2021 10:58:32 +0100
4 Subject: [PATCH] turn: block forwarding to loopback/any
5
6 ---
7 modules/turn/turn.c | 18 ++++++++++++++----
8 1 file changed, 14 insertions(+), 4 deletions(-)
9
10 --- a/modules/turn/turn.c
11 +++ b/modules/turn/turn.c
12 @@ -153,6 +153,7 @@ static bool indication_handler(struct re
13 struct stun_attr *data, *peer;
14 struct allocation *al;
15 struct perm *perm;
16 + const struct sa *psa;
17 int err;
18 (void)sock;
19 (void)ctx;
20 @@ -173,13 +174,17 @@ static bool indication_handler(struct re
21 if (!peer || !data)
22 return true;
23
24 - perm = perm_find(al->perms, &peer->v.xor_peer_addr);
25 + psa = &peer->v.xor_peer_addr;
26 + perm = perm_find(al->perms, psa);
27 if (!perm) {
28 ++al->dropc_tx;
29 return true;
30 }
31
32 - err = udp_send(al->rel_us, &peer->v.xor_peer_addr, &data->v.data);
33 + if (sa_is_loopback(psa) || sa_is_any(psa))
34 + err = EPERM;
35 + else
36 + err = udp_send(al->rel_us, psa, &data->v.data);
37 if (err)
38 turnd.errc_tx++;
39 else {
40 @@ -200,6 +205,7 @@ static bool raw_handler(int proto, const
41 uint16_t numb, len;
42 struct perm *perm;
43 struct chan *chan;
44 + const struct sa *psa;
45 int err;
46
47 al = allocation_find(proto, src, dst);
48 @@ -219,7 +225,8 @@ static bool raw_handler(int proto, const
49 if (!chan)
50 return false;
51
52 - perm = perm_find(al->perms, chan_peer(chan));
53 + psa = chan_peer(chan);
54 + perm = perm_find(al->perms, psa);
55 if (!perm) {
56 ++al->dropc_tx;
57 return false;
58 @@ -227,7 +234,10 @@ static bool raw_handler(int proto, const
59
60 mb->end = mb->pos + len;
61
62 - err = udp_send(al->rel_us, chan_peer(chan), mb);
63 + if (sa_is_loopback(psa) || sa_is_any(psa))
64 + err = EPERM;
65 + else
66 + err = udp_send(al->rel_us, psa, mb);
67 if (err)
68 turnd.errc_tx++;
69 else {