From 7ae1600e041389deeea3402821359a9121381bc3 Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Fri, 18 Sep 2020 14:53:23 -0400 Subject: [PATCH] Add exception handling for #568 If packet buffer is exhausted, the packet is sliently discarded --- lib/core/ogs-abort.c | 12 +++++++++++- lib/core/ogs-pkbuf.c | 6 ++++++ lib/pfcp/handler.c | 9 ++++++++- lib/sbi/message.c | 1 + src/amf/nas-path.c | 7 ++++++- src/amf/ngap-path.c | 1 + src/mme/nas-path.c | 4 ++++ src/mme/s1ap-path.c | 1 + src/sgwc/pfcp-path.c | 16 ++++++++++++---- 9 files changed, 50 insertions(+), 7 deletions(-) diff --git a/lib/core/ogs-abort.c b/lib/core/ogs-abort.c index d03040727..921a8c1f6 100644 --- a/lib/core/ogs-abort.c +++ b/lib/core/ogs-abort.c @@ -28,11 +28,21 @@ OGS_GNUC_NORETURN void ogs_abort(void) { #if HAVE_BACKTRACE + int i; int nptrs; void *buffer[100]; + char **strings; nptrs = backtrace(buffer, OGS_ARRAY_SIZE(buffer)); - backtrace_symbols_fd(buffer, nptrs, 2); + ogs_fatal("backtrace() returned %d addresses", nptrs); + + strings = backtrace_symbols(buffer, nptrs); + if (strings) { + for (i = 1; i < nptrs; i++) + ogs_log_print(OGS_LOG_FATAL, "%s\n", strings[i]); + + free(strings); + } abort(); #elif defined(_WIN32) diff --git a/lib/core/ogs-pkbuf.c b/lib/core/ogs-pkbuf.c index e45e13a22..cc18ab403 100644 --- a/lib/core/ogs-pkbuf.c +++ b/lib/core/ogs-pkbuf.c @@ -177,6 +177,7 @@ ogs_pkbuf_t *ogs_pkbuf_alloc(ogs_pkbuf_pool_t *pool, unsigned int size) cluster = cluster_alloc(pool, size); if (!cluster) { ogs_error("ogs_pkbuf_alloc() failed [size=%d]", size); + ogs_thread_mutex_unlock(&pool->mutex); return NULL; } ogs_assert(cluster); @@ -238,6 +239,11 @@ ogs_pkbuf_t *ogs_pkbuf_copy(ogs_pkbuf_t *pkbuf) ogs_thread_mutex_lock(&pool->mutex); ogs_pool_alloc(&pool->pkbuf, &newbuf); + if (!newbuf) { + ogs_error("ogs_pkbuf_copy() failed"); + ogs_thread_mutex_unlock(&pool->mutex); + return NULL; + } ogs_assert(newbuf); memcpy(newbuf, pkbuf, sizeof *pkbuf); diff --git a/lib/pfcp/handler.c b/lib/pfcp/handler.c index 6d2eb55f5..39c5231c4 100644 --- a/lib/pfcp/handler.c +++ b/lib/pfcp/handler.c @@ -128,7 +128,14 @@ void ogs_pfcp_up_handle_pdr( memset(report, 0, sizeof(*report)); sendbuf = ogs_pkbuf_copy(recvbuf); - ogs_assert(sendbuf); + if (!sendbuf) { + ogs_error("CHECK CONFIGURATION : Not enough packet buffer"); + ogs_error("Edit sgwu.yaml in EPC or upf.yaml in 5GC"); + ogs_error("pool"); + ogs_error(" packet: 32768"); + + return; + } buffering = false; diff --git a/lib/sbi/message.c b/lib/sbi/message.c index fb487bc0f..8fcdb3172 100644 --- a/lib/sbi/message.c +++ b/lib/sbi/message.c @@ -1516,6 +1516,7 @@ static int parse_multipart( http->part[http->num_of_part].content_type; message->part[message->num_of_part].pkbuf = ogs_pkbuf_copy(http->part[http->num_of_part].pkbuf); + ogs_assert(message->part[message->num_of_part].pkbuf); http->num_of_part++; message->num_of_part++; diff --git a/src/amf/nas-path.c b/src/amf/nas-path.c index 7208b1899..08a49c508 100644 --- a/src/amf/nas-path.c +++ b/src/amf/nas-path.c @@ -200,6 +200,7 @@ void nas_5gs_send_identity_request(amf_ue_t *amf_ue) } amf_ue->t3570.pkbuf = ogs_pkbuf_copy(gmmbuf); + ogs_assert(amf_ue->t3570.pkbuf); ogs_timer_start(amf_ue->t3570.timer, amf_timer_cfg(AMF_TIMER_T3570)->duration); @@ -224,6 +225,7 @@ void nas_5gs_send_authentication_request(amf_ue_t *amf_ue) } amf_ue->t3560.pkbuf = ogs_pkbuf_copy(gmmbuf); + ogs_assert(amf_ue->t3560.pkbuf); ogs_timer_start(amf_ue->t3560.timer, amf_timer_cfg(AMF_TIMER_T3560)->duration); @@ -265,6 +267,7 @@ void nas_5gs_send_security_mode_command(amf_ue_t *amf_ue) } amf_ue->t3560.pkbuf = ogs_pkbuf_copy(gmmbuf); + ogs_assert(amf_ue->t3560.pkbuf); ogs_timer_start(amf_ue->t3560.timer, amf_timer_cfg(AMF_TIMER_T3560)->duration); @@ -287,6 +290,7 @@ void nas_5gs_send_configuration_update_command( ogs_expect_or_return(gmmbuf); amf_ue->t3555.pkbuf = ogs_pkbuf_copy(gmmbuf); + ogs_assert(amf_ue->t3555.pkbuf); ogs_timer_start(amf_ue->t3555.timer, amf_timer_cfg(AMF_TIMER_T3555)->duration); @@ -296,6 +300,7 @@ void nas_5gs_send_configuration_update_command( if (param->acknowledgement_requested) { amf_ue->t3555.pkbuf = ogs_pkbuf_copy(gmmbuf); + ogs_assert(amf_ue->t3555.pkbuf); ogs_timer_start(amf_ue->t3555.timer, amf_timer_cfg(AMF_TIMER_T3555)->duration); } @@ -444,7 +449,7 @@ void nas_5gs_send_back_5gsm_message( ogs_assert(sess->payload_container); pbuf = ogs_pkbuf_copy(sess->payload_container); - ogs_expect_or_return(pbuf); + ogs_assert(pbuf); nas_5gs_send_gsm_reject(sess, sess->payload_container_type, pbuf, cause, AMF_NAS_BACKOFF_TIME); diff --git a/src/amf/ngap-path.c b/src/amf/ngap-path.c index cc0d5a9f1..dc6953b54 100644 --- a/src/amf/ngap-path.c +++ b/src/amf/ngap-path.c @@ -367,6 +367,7 @@ void ngap_send_paging(amf_ue_t *amf_ue, NGAP_CNDomain_t cn_domain) } amf_ue->t3413.pkbuf = ogs_pkbuf_copy(ngapbuf); + ogs_assert(amf_ue->t3413.pkbuf); rv = ngap_send_to_gnb(gnb, ngapbuf, NGAP_NON_UE_SIGNALLING); ogs_expect(rv == OGS_OK); diff --git a/src/mme/nas-path.c b/src/mme/nas-path.c index 2841befd2..81e4d1888 100644 --- a/src/mme/nas-path.c +++ b/src/mme/nas-path.c @@ -164,6 +164,7 @@ void nas_eps_send_identity_request(mme_ue_t *mme_ue) } mme_ue->t3470.pkbuf = ogs_pkbuf_copy(emmbuf); + ogs_assert(mme_ue->t3470.pkbuf); ogs_timer_start(mme_ue->t3470.timer, mme_timer_cfg(MME_TIMER_T3470)->duration); @@ -191,6 +192,7 @@ void nas_eps_send_authentication_request( } mme_ue->t3460.pkbuf = ogs_pkbuf_copy(emmbuf); + ogs_assert(mme_ue->t3460.pkbuf); ogs_timer_start(mme_ue->t3460.timer, mme_timer_cfg(MME_TIMER_T3460)->duration); @@ -217,6 +219,7 @@ void nas_eps_send_security_mode_command(mme_ue_t *mme_ue) } mme_ue->t3460.pkbuf = ogs_pkbuf_copy(emmbuf); + ogs_assert(mme_ue->t3460.pkbuf); ogs_timer_start(mme_ue->t3460.timer, mme_timer_cfg(MME_TIMER_T3460)->duration); @@ -310,6 +313,7 @@ void nas_eps_send_esm_information_request(mme_bearer_t *bearer) } bearer->t3489.pkbuf = ogs_pkbuf_copy(esmbuf); + ogs_assert(bearer->t3489.pkbuf); ogs_timer_start(bearer->t3489.timer, mme_timer_cfg(MME_TIMER_T3489)->duration); diff --git a/src/mme/s1ap-path.c b/src/mme/s1ap-path.c index 733e88103..0efa32ec6 100644 --- a/src/mme/s1ap-path.c +++ b/src/mme/s1ap-path.c @@ -350,6 +350,7 @@ void s1ap_send_paging(mme_ue_t *mme_ue, S1AP_CNDomain_t cn_domain) } mme_ue->t3413.pkbuf = ogs_pkbuf_copy(s1apbuf); + ogs_assert(mme_ue->t3413.pkbuf); rv = s1ap_send_to_enb(enb, s1apbuf, S1AP_NON_UE_SIGNALLING); ogs_expect(rv == OGS_OK); diff --git a/src/sgwc/pfcp-path.c b/src/sgwc/pfcp-path.c index 8c1db8a6a..8c6aa1189 100644 --- a/src/sgwc/pfcp-path.c +++ b/src/sgwc/pfcp-path.c @@ -218,8 +218,10 @@ void sgwc_pfcp_send_session_establishment_request( sess->pfcp_node, &h, sxabuf, sess_timeout, sess); ogs_expect_or_return(xact); xact->assoc_xact = gtp_xact; - if (gtpbuf) + if (gtpbuf) { xact->gtpbuf = ogs_pkbuf_copy(gtpbuf); + ogs_assert(xact->gtpbuf); + } rv = ogs_pfcp_xact_commit(xact); ogs_expect(rv == OGS_OK); @@ -248,8 +250,10 @@ void sgwc_pfcp_send_sess_modification_request( ogs_expect_or_return(xact); xact->assoc_xact = gtp_xact; xact->modify_flags = flags | OGS_PFCP_MODIFY_SESSION; - if (gtpbuf) + if (gtpbuf) { xact->gtpbuf = ogs_pkbuf_copy(gtpbuf); + ogs_assert(xact->gtpbuf); + } rv = ogs_pfcp_xact_commit(xact); ogs_expect(rv == OGS_OK); @@ -281,8 +285,10 @@ void sgwc_pfcp_send_bearer_modification_request( ogs_expect_or_return(xact); xact->assoc_xact = gtp_xact; xact->modify_flags = flags; - if (gtpbuf) + if (gtpbuf) { xact->gtpbuf = ogs_pkbuf_copy(gtpbuf); + ogs_assert(xact->gtpbuf); + } rv = ogs_pfcp_xact_commit(xact); ogs_expect(rv == OGS_OK); @@ -309,8 +315,10 @@ void sgwc_pfcp_send_session_deletion_request( sess->pfcp_node, &h, sxabuf, sess_timeout, sess); ogs_expect_or_return(xact); xact->assoc_xact = gtp_xact; - if (gtpbuf) + if (gtpbuf) { xact->gtpbuf = ogs_pkbuf_copy(gtpbuf); + ogs_assert(xact->gtpbuf); + } rv = ogs_pfcp_xact_commit(xact); ogs_expect(rv == OGS_OK);