summaryrefslogtreecommitdiff
path: root/channels/chan_sip.c
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2013-01-02 18:11:59 +0000
committerMatthew Jordan <mjordan@digium.com>2013-01-02 18:11:59 +0000
commit8fb5bdce9ab9f7f3758545753cbc787653920753 (patch)
tree65809194af8a4fa757fef26a30a2cc9c3ed02182 /channels/chan_sip.c
parent1fb06fde957fb466388c764384c2e14698e2dc15 (diff)
Prevent exhaustion of system resources through exploitation of event cache
Asterisk maintains an internal cache for devices in the event subsystem. The device state cache holds the state of each device known to Asterisk, such that consumers of device state information can query for the last known state for a particular device, even if it is not part of an active call. The concept of a device in Asterisk can include entities that do not have a physical representation. One way that this occurred was when anonymous calls are allowed in Asterisk. A device was automatically created and stored in the cache for each anonymous call that occurred; this was possible in the SIP and IAX2 channel drivers and through channel drivers that utilized the res_jabber/res_xmpp resource modules (Gtalk, Jingle, and Motif). These devices are never removed from the system, allowing anonymous calls to potentially exhaust a system's resources. This patch changes the event cache subsystem and device state management to no longer cache devices that are not associated with a physical entity. (issue ASTERISK-20175) Reported by: Russell Bryant, Leif Madsen, Joshua Colp Tested by: kmoore patches: event-cachability-3.diff uploaded by jcolp (license 5000) ........ Merged revisions 378303 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 378320 from http://svn.asterisk.org/svn/asterisk/branches/10 ........ Merged revisions 378321 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@378322 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels/chan_sip.c')
-rw-r--r--channels/chan_sip.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index b2b3395c7..18c14eacd 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -6854,7 +6854,7 @@ static int update_call_counter(struct sip_pvt *fup, int event)
}
if (p) {
- ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", p->name);
+ ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, "SIP/%s", p->name);
sip_unref_peer(p, "update_call_counter: sip_unref_peer from call counter");
}
return 0;
@@ -8115,6 +8115,9 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit
ast_jb_configure(tmp, &global_jbconf);
}
+ if (!i->relatedpeer) {
+ ast_set_flag(ast_channel_flags(tmp), AST_FLAG_DISABLE_DEVSTATE_CACHE);
+ }
/* Set channel variables for this call from configuration */
for (v = i->chanvars ; v ; v = v->next) {
char valuebuf[1024];
@@ -15668,7 +15671,7 @@ static int expire_register(const void *data)
manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Unregistered\r\nCause: Expired\r\n", peer->name);
register_peer_exten(peer, FALSE); /* Remove regexten */
- ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name);
+ ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, "SIP/%s", peer->name);
/* Do we need to release this peer from memory?
Only for realtime peers and autocreated peers
@@ -16459,8 +16462,9 @@ static void sip_peer_hold(struct sip_pvt *p, int hold)
ast_atomic_fetchadd_int(&p->relatedpeer->onhold, (hold ? +1 : -1));
/* Request device state update */
- ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", p->relatedpeer->name);
-
+ ast_devstate_changed(AST_DEVICE_UNKNOWN, (ast_test_flag(ast_channel_flags(p->owner), AST_FLAG_DISABLE_DEVSTATE_CACHE) ? AST_DEVSTATE_NOT_CACHABLE : AST_DEVSTATE_CACHABLE),
+ "SIP/%s", p->relatedpeer->name);
+
return;
}
@@ -16983,7 +16987,7 @@ static enum check_auth_result register_verify(struct sip_pvt *p, struct ast_sock
} else {
update_peer_lastmsgssent(peer, -1, 0);
}
- ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name);
+ ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, "SIP/%s", peer->name);
}
if (res < 0) {
switch (res) {
@@ -23439,7 +23443,7 @@ static void handle_response_peerpoke(struct sip_pvt *p, int resp, struct sip_req
ast_log(LOG_NOTICE, "Peer '%s' is now %s. (%dms / %dms)\n",
peer->name, s, pingtime, peer->maxms);
- ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name);
+ ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, "SIP/%s", peer->name);
if (sip_cfg.peer_rtupdate) {
ast_update_realtime(ast_check_realtime("sipregs") ? "sipregs" : "sippeers", "name", peer->name, "lastms", str_lastms, SENTINEL);
}
@@ -29350,7 +29354,7 @@ static int sip_poke_noanswer(const void *data)
/* Don't send a devstate change if nothing changed. */
if (peer->lastms > -1) {
peer->lastms = -1;
- ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name);
+ ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, "SIP/%s", peer->name);
}
/* Try again quickly */