ipa: don't crash on missing IPA ID GET message

ipaccess_bts_read_cb() only initializes signalling links if it has received an
IPA ID GET message on it, and so far happily accesses the uninitialized
sign_links list anyway if it hasn't.

Reproduce: simply don't send an IPA ID GET message when connecting to an IPA
server run by libosmo-abis, then continue to use the link --> segfault.

Fix the segfault: make sure that the e1inp_ts' type has been set, i.e. that
e1inp_ts_config_sign() has been called and the sign_links llist is initialized,
before calling e1inp_lookup_sign_link() on it.

../../../src/libosmo-abis/src/e1_input.c:511:2: runtime error: member access within null pointer of type 'struct e1inp_sign_link'
../../../src/libosmo-abis/src/e1_input.c:512:11: runtime error: member access within null pointer of type 'struct e1inp_sign_link'
ASAN:SIGSEGV
=================================================================
==5702==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000038 (pc 0x7f28a379ea34 sp 0x7ffd7d8933f0 bp 0x62e000000a98 T0)
    #0 0x7f28a379ea33 in e1inp_lookup_sign_link ../../../src/libosmo-abis/src/e1_input.c:512
    #1 0x7f28a37b97d4 in ipaccess_bts_read_cb ../../../src/libosmo-abis/src/input/ipaccess.c:778
    #2 0x7f28a37b0277 in ipa_client_read ../../../src/libosmo-abis/src/input/ipa.c:76
    #3 0x7f28a37b0277 in ipa_client_fd_cb ../../../src/libosmo-abis/src/input/ipa.c:139
    #4 0x7f28a2ac1a34 in osmo_fd_disp_fds ../../../src/libosmocore/src/select.c:217
    #5 0x7f28a2ac1a34 in osmo_select_main ../../../src/libosmocore/src/select.c:257
    #6 0x444ba3 in bts_main ../../../../src/osmo-bts/src/common/main.c:364
    #7 0x7f28a17ddb44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b44)
    #8 0x405e54 (/usr/local/bin/osmo-bts-trx+0x405e54)

Related: OS#3498
Change-Id: I2487ca37a0fe9aa56733f66bcad9dcf91fc11144
This commit is contained in:
Neels Hofmeyr 2018-08-24 17:43:45 +02:00
parent 67902bbeb9
commit fe6731181c
1 changed files with 8 additions and 4 deletions

View File

@ -727,12 +727,11 @@ static int ipaccess_bts_read_cb(struct ipa_client_conn *link, struct msgb *msg)
struct ipaccess_head *hh = (struct ipaccess_head *) msg->data;
struct e1inp_ts *e1i_ts = NULL;
struct e1inp_sign_link *sign_link;
uint8_t msg_type = *(msg->l2h);
int ret = 0;
/* special handling for IPA CCM. */
if (hh->proto == IPAC_PROTO_IPACCESS) {
uint8_t msg_type = *(msg->l2h);
/* this is a request for identification from the BSC. */
if (msg_type == IPAC_MSGT_ID_GET) {
if (!link->line->ops->sign_link_up) {
@ -751,8 +750,6 @@ static int ipaccess_bts_read_cb(struct ipa_client_conn *link, struct msgb *msg)
goto err;
if (ret == 1 && hh->proto == IPAC_PROTO_IPACCESS) {
uint8_t msg_type = *(msg->l2h);
if (msg_type == IPAC_MSGT_ID_GET) {
sign_link = link->line->ops->sign_link_up(msg,
link->line,
@ -774,6 +771,13 @@ static int ipaccess_bts_read_cb(struct ipa_client_conn *link, struct msgb *msg)
OSMO_ASSERT(e1i_ts != NULL);
if (e1i_ts->type == E1INP_TS_TYPE_NONE) {
LOGP(DLINP, LOGL_ERROR, "Signalling link not initialized. Discarding."
" port=%u msg_type=%u\n", link->port, msg_type);
ret = -EIO;
goto err;
}
/* look up for some existing signaling link. */
sign_link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0);
if (sign_link == NULL) {