We found a problem regarding TCP connection alias in the following code at
tcp_main.c:
int tcpconn_finish_connect( struct tcp_connection* c,
union sockaddr_union* from)
{
:
:
/* remove all the aliases
except the first one and re-add them
* (there shouldn't be more
then the 3 default aliases at this
* stage) */
for (r=1; r<c->aliases;
r++){
a=&c->con_aliases[r];
tcpconn_listrm(tcpconn_aliases_hash[a->hash],
a, next, prev);
}
c->aliases=1;
As TCP_ALIAS_REPLACE flag is set for the default TCP options value, in the
function _tcpconn_add_alias_unsafe() a TCP connection alias can be moved
from connection A to connection B based on the TCP alias hash. In this
case, the number of aliases is incremented in the connection A, and
decremented from connection B. However, in the connection B the number of
aliases can reach zero (no alias). And the code above can be executed for
connection B setting the number of aliases to 1 unconditionally. When this
case happens, the connection B keeps an invalid alias (already excluded
from connection B by tcpconn_add_alias_unsafe() function called from
connection A). When the connection A is released, the aliases are also
released, and this memory area can be filled with different data. As
connection B has references to an invalid alias it can try to access
invalid areas, and can crash Kamailio. This access happens, for example,
when another alias is added to connection B.
To fix it we include a check before the code:
if (c->aliases>0) {
for (r=1;
r<c->aliases; r++){
a=&c->con_aliases[r];
tcpconn_listrm(tcpconn_aliases_hash[a->hash], a, next, prev);
memset(a,0xbb,sizeof(struct tcp_conn_alias));
}
c->aliases=1;
}
Please let us know if any comments.
Thanks
Jijo
Module: sip-router
Branch: master
Commit: e71435b0276c89ef756fecf1bbd5e339b80e804c
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e71435b…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Wed Oct 10 10:02:00 2012 +0200
tcp: fix connection alias replacing
When the TCP_ALIAS_REPLACE is set and an alias has to be added to
a connection that had 0 aliases (it can happen due to
TCP_ALIAS_REPLACE flag), the connection aliases count was wrongly
forced to 1.
For more details see:
http://lists.sip-router.org/pipermail/sr-users/2012-October/074932.html
Patch-by Jijo
---
tcp_main.c | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/tcp_main.c b/tcp_main.c
index 2c4bf82..9d3359e 100644
--- a/tcp_main.c
+++ b/tcp_main.c
@@ -1339,11 +1339,14 @@ int tcpconn_finish_connect( struct tcp_connection* c,
/* remove all the aliases except the first one and re-add them
* (there shouldn't be more then the 3 default aliases at this
* stage) */
- for (r=1; r<c->aliases; r++){
- a=&c->con_aliases[r];
- tcpconn_listrm(tcpconn_aliases_hash[a->hash], a, next, prev);
+ if (c->aliases > 1) {
+ for (r=1; r<c->aliases; r++){
+ a=&c->con_aliases[r];
+ tcpconn_listrm(tcpconn_aliases_hash[a->hash],
+ a, next, prev);
+ }
+ c->aliases=1;
}
- c->aliases=1;
/* add the local_ip:0 and local_ip:local_port aliases */
_tcpconn_add_alias_unsafe(c, c->rcv.src_port, &c->rcv.dst_ip,
0, new_conn_alias_flags);
Hello,
kamailio cores when receives a corrupted route header.
For example, this was causing the core.
Route: sip:10.236.236.100;transport=tcp;r2=on;lr;ftag=1348218287134-Test-553188;osb-tag=NM;nat=yes;twan=yes?[=&
[=<sip:10.236.236.100;transport=tcp;r2=on;lr;ftag=1348218287134-Test-553188;osb-tag=NM;nat=yes;twan=yes?[=&%20[=>
I found the problem, the pointer was not initializing to null after freeing
it. Please apply this fix in the next version.
Here is the diff with the original(3.2.2) and changed version.
PGA:/mnt/o/kamailio-3.2.2/parser # diff -u parse_param.c.orig parse_param.c
--- parse_param.c.orig 2012-10-09 09:42:58.372003500 -0300
+++ parse_param.c 2012-10-09 21:34:14.556367900 -0300
@@ -545,6 +545,7 @@
error:
if (t) pkg_free(t);
free_params(*_p);
+ *_p = 0;
return -2;
ok:
Thanks
Jijo