libosmocore/tests
Neels Hofmeyr 554f7b8a77 rate_ctr: fix osmo-sgsn DoS: don't return NULL on already used index
Recent patch I563764af1d28043e909234ebb048239125ce6ecd introduced returning
NULL from rate_ctr_group_alloc() when the index passed already exists.

Instead of returning NULL, find an unused group index and use that, adjust the
error message.

In stats_test.c, adjust, and also assert allocated counter group indexes
everywhere.

Rationale:

The original patch causes osmo-sgsn to crash as soon as the second subscriber
attempts to establish an MM context. Of course osmo-sgsn is wrong to a) fail to
check a NULL return value and crash and b) to fail to allocate an MM context
just because the rate counter group could not be allocated (it still rejects
the MM context completely if rate_ctr_group_alloc() fails).

Nevertheless, the price we pay for rate counter correctness is, at least in
this instance, way too high: osmo-sgsn becomes completely unusable for more
than one subscriber.

Numerous other places exist where rate_ctr_group_alloc() is called with a
constant index number; from a quick grep magic I found these possible breaking
points:

osmo-sgsn/src/gprs/gb_proxy.c:1431:     cfg->ctrg = rate_ctr_group_alloc(tall_bsc_ctx, &global_ctrg_desc, 0);
osmo-sgsn/src/gprs/gprs_sgsn.c:139:     sgsn->rate_ctrs = rate_ctr_group_alloc(tall_bsc_ctx, &sgsn_ctrg_desc, 0);
osmo-sgsn/src/gprs/gprs_sgsn.c:270:     ctx->ctrg = rate_ctr_group_alloc(ctx, &mmctx_ctrg_desc, 0);
osmo-sgsn/src/gprs/gtphub.c:888:        b->counters_io = rate_ctr_group_alloc(osmo_gtphub_ctx,
                                                                              &gtphub_ctrg_io_desc, 0);
osmo-bsc/src/libfilter/bsc_msg_acc.c:87:        lst->stats = rate_ctr_group_alloc(lst, &bsc_cfg_acc_list_desc, 0);
osmo-pcu/src/bts.cpp:228:               m_ratectrs = rate_ctr_group_alloc(tall_pcu_ctx, &bts_ctrg_desc, 0);
osmo-pcu/src/tbf.cpp:793:       tbf->m_ctrs = rate_ctr_group_alloc(tbf, &tbf_ctrg_desc, 0);
osmo-pcu/src/tbf.cpp:879:       tbf->m_ul_egprs_ctrs = rate_ctr_group_alloc(tbf, &tbf_ul_egprs_ctrg_desc, 0);
osmo-pcu/src/tbf.cpp:880:       tbf->m_ul_gprs_ctrs = rate_ctr_group_alloc(tbf, &tbf_ul_gprs_ctrg_desc, 0);
osmo-pcu/src/tbf.cpp:970:               tbf->m_dl_egprs_ctrs = rate_ctr_group_alloc(tbf, &tbf_dl_egprs_ctrg_desc, 0);
osmo-pcu/src/tbf.cpp:977:               tbf->m_dl_gprs_ctrs = rate_ctr_group_alloc(tbf, &tbf_dl_gprs_ctrg_desc, 0);
osmo-pcu/src/tbf.cpp:1475:      ul_tbf->m_ctrs = rate_ctr_group_alloc(ul_tbf, &tbf_ctrg_desc, 0);
osmo-pcu/src/bts.cpp:226:               m_ratectrs = rate_ctr_group_alloc(tall_pcu_ctx, &bts_ctrg_desc, 1);

We can fix all of these callers and then reconsider returning NULL, but IMO
even into the future, rate counter group indexes are not something worth
failing to provide service for. For future bugs we should keep the automatic
index picking in case of index collisions. We will get an error message barfed
and can fix the issue in our own time, while the application remains completely
usable, and even the rate counters can still be queried (at wrong indexes, but
life is tough).

Related: I49aa95b610f2faec52dede2e4816da47ca1dfb14 (osmo-sgsn's segfault)
Change-Id: Iba6e41b8eeaea5ff6ed862bab3f34a62ab976914
2017-12-20 01:29:59 +01:00
..
a5 fix compiler warnings for a5 tests 2015-04-07 20:08:38 +02:00
abis abis_test: sanitize: fix msgb memleak 2017-11-18 10:30:58 +00:00
auth milenage_test: cosmetic: verify AUTS in comments 2017-03-15 13:46:58 +00:00
bits Add tests for bitvec_write_field() 2017-10-24 08:21:59 +00:00
bitvec Add function to get uninterrupted bit run 2017-01-06 10:37:42 +00:00
codec Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
coding Add functions for extended RACH coding 2017-12-11 10:36:47 +00:00
comp128 tests: test actual support status for auth. algo 2016-06-29 16:33:40 +00:00
conv Add functions for extended RACH coding 2017-12-11 10:36:47 +00:00
ctrl ctrl: on parse errors, return a detailed message to sender 2017-12-18 23:05:50 +00:00
endian introduce byteswap.h with osmo_{htonl,ntohl,htons,ntohs} 2017-05-15 13:42:00 +02:00
fr license: Fix the license to GPL 2017-12-09 13:03:29 +00:00
fsm fsm_test.c: fix unreachable check 2017-05-15 12:51:15 +00:00
gb bssgp_fc_test: sanitize: free fc struct when done 2017-11-20 17:22:42 +01:00
gea Add GEA3 & GEA4 ciphers 2016-07-11 19:15:24 +00:00
gprs Make osmo_apn_to_str() more robust 2017-10-20 18:19:58 +00:00
gsm0408 gsm0408_test: sanitize: cleanup msgb 2017-11-18 10:30:58 +00:00
gsm0808 gsm0808_create_cipher_reject: Fix encoding of Cause IE 2017-12-17 20:51:48 +01:00
gsm23003 Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
gsup gsup: Add encoding/decoding for the pdp charging characteristics 2017-07-07 21:54:38 +02:00
kasumi kasumi_test.c: fix incomplete check 2017-05-14 20:27:22 +03:00
lapd Fix malformed Abis/RSL messages with extra L3 Information field 2017-12-10 14:44:19 +00:00
logging license: Fix the license to GPL 2017-12-09 13:03:29 +00:00
loggingrb license: Fix the license to GPL 2017-12-09 13:03:29 +00:00
msgb add function msgb_printf() to print formatted text into msg buf 2017-10-22 20:09:26 +00:00
msgfile build: resolve compiler warning about implicit delcaration 2014-10-04 11:49:23 +02:00
oap Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
osmo-auc-gen umts aka: add sqn_ms out-param, print SQN.MS in osmo-auc-gen 2017-08-29 12:46:46 +00:00
prbs Add pseudo-random bit sequence generator to libosmcoore 2017-07-10 23:42:02 +02:00
sercomm Embedded: fix sercomm test 2017-12-05 18:43:14 +00:00
sim sim: Fix compiler warning and by this fixing the test result 2016-03-21 11:29:16 +01:00
sms sms_test.c: Remove test of deprecated wrapper function 2017-06-18 10:40:18 +02:00
smscb test: Fix compiler warnings on 64bit systems 2015-11-09 16:46:03 +00:00
socket osmo_sock_get_name(): clearly indicate local and remote 2017-07-03 17:29:05 +00:00
stats rate_ctr: fix osmo-sgsn DoS: don't return NULL on already used index 2017-12-20 01:29:59 +01:00
strrb Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
timer timer: add osmo_timer_setup() 2017-05-09 12:10:51 +02:00
tlv tlv_test.c: Fix compilation warnings 2017-06-18 10:40:18 +02:00
ussd ussd: Decode interrogateSS that doesn't have test 2016-07-12 17:45:34 +02:00
utils utils: add osmo_escape_str() 2017-12-18 23:05:49 +00:00
vty Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
write_queue wqueue: Reject messges if queue is considered full 2016-12-09 11:37:37 +01:00
Makefile.am embedded: fix tests 2017-12-04 09:40:39 +00:00
atlocal.in build: make check: disable sim_test when built with --disable-pcsc 2016-11-16 16:40:44 +00:00
testsuite.at Add tests for bitvec_write_field() 2017-10-24 08:21:59 +00:00