Commit Graph

3151 Commits

Author SHA1 Message Date
Vadim Yanitskiy 8c00f9d753 vty/vty.c: the command buffer can be accessed directly
Change-Id: Ic6d7d68e9a559a6fb5bd6eaf6eccceae51e7ed39
2019-07-30 17:17:15 +00:00
Vadim Yanitskiy 757dea8d4a vty/vty.c: fix vty_read(): prevent further heap-buffer overrun
After reading data from the socket, assigned to a given VTY, we
need to '\0'-terminate the received string. Otherwise, further
access to that string, stored in a heap buffer vty->buf, would
lead to a heap overrun.

== How to reproduce?

  $ python -c "print 'A' * 512" | telnet $HOST $PORT

  ==21264==ERROR: AddressSanitizer: heap-buffer-overflow on address
                                    0x6190000211e0 at pc 0x000000435d2f
				    bp 0x7ffc06c7add0 sp 0x7ffc06c7a578
  READ of size 1025 at 0x6190000211e0 thread T0
    #0 0x435d2e in __interceptor_strlen (/usr/local/bin/osmo-msc+0x435d2e)
    #1 0x7fb95bfa5624 in talloc_strdup (/usr/lib/x86_64-linux-gnu/libtalloc.so.2+0x6624)
    #2 0x7fb95c1be2bc in vty_hist_add /opt/osmocom/libosmocore/src/vty/vty.c:578
    #3 0x7fb95c1be2bc in vty_execute /opt/osmocom/libosmocore/src/vty/vty.c:703
    #4 0x7fb95c1be2bc in vty_read /opt/osmocom/libosmocore/src/vty/vty.c:1425
    #5 0x7fb95c1bfd78 in client_data /opt/osmocom/libosmocore/src/vty/telnet_interface.c:157
    #6 0x7fb95b90bd33 in osmo_fd_disp_fds /opt/osmocom/libosmocore/src/select.c:223
    #7 0x7fb95b90bd33 in osmo_select_main /opt/osmocom/libosmocore/src/select.c:263
    #8 0x5006cc in main /opt/osmocom/osmo-msc/src/osmo-msc/msc_main.c:723:3
    #9 0x7fb959935f44 in __libc_start_main /build/eglibc-xkFqqE/eglibc-2.19/csu/libc-start.c:287
    #10 0x4226fb in _start (/usr/local/bin/osmo-msc+0x4226fb)

== Why exactly 512?

Because the initial size of the heap buffer is 512 (see VTY_BUFSIZ).
Later on it can be realloc()ated, so X > 512 should also work.

Found using AddressSanitizer and Radamsa [1] fuzzer.

[1] https://gitlab.com/akihe/radamsa

Change-Id: I82f774ad18d0e555eb8f3590a519946d9c583c78
2019-07-30 17:17:15 +00:00
Vadim Yanitskiy 74b6ff074b vty/telnet_interface.c: log connection accept() / close() events
Unfortunately, osmo_sock_get_name_buf() fails in telnet_close_client():

  DLGLOBAL INFO telnet_interface.c:130 Closing telnet connection <error-in-getsockname>

because getsockname(), getpeername(), and even close() fail with:

  "Bad file descriptor".

This looks like a bug of the existing code.

Change-Id: I77b31abfa159d2f269deaa5a08d94b7bbba7d23c
2019-07-30 17:17:15 +00:00
Pau Espin 2605ffc3d7 gsm0808_test: Fix wrong use of memcp
After recent system upgrade, gcc 9.1.0, I started getting gsm0808_test
failing locally:
Assert failed memcmp(&enc_ct, &dec_ct, sizeof(enc_ct)) == 0 libosmocore/tests/gsm0808/gsm0808_test.c:992

During investigation with gdb, fields of both structures seem to contain
same values. However, closer lookup gives some hints on why it fails:
(gdb) print memcmp(&enc_ct, &dec_ct, sizeof(enc_ct))
$1 = 85
(gdb) print memcmp(&enc_ct, &dec_ct, 12)
$14 = 85
(gdb) print ((uint8_t*)&enc_ct)[11]
$15 = 85 'U'
(gdb) print ((uint8_t*)&dec_ct)[11]
$16 = 0 '\000'

So the 12th byte in struct gsm0808_channel_type is basically an
alignment padding byte added by the compiler (to align perm_spch_len to
4-byte alignment). Since both compared structs are initialized without
memset(0) but using compiler's designated initializers, it seems the compiler
decided it's no longer needed to zero the padding byte, making memcp fail in
this case.

In order to avoid the failure, let's properly check every field instead
of using memcp here.

Change-Id: I17fe7a0a5dc650f050bba1f47d071be749550729
2019-07-30 12:51:29 +00:00
Vadim Yanitskiy 5c4b9850c2 vty/logging_vty.c: fix writing of 'print category-hex'
Change-Id: I33837f0fac1afe83596fa600916abc05ecb8c356
2019-07-30 12:42:47 +00:00
Vadim Yanitskiy a9a8ea5347 vty/telnet_interface.c: avoid unneeded initialization
Unconditional initialization follows the structure definition,
so there is no need to do it twice. This prevents compiler
from warning about potential errors.

Change-Id: If9fd2826f132dfa203dda62940d93dbdfcfd92ac
2019-07-27 21:58:55 +07:00
Vadim Yanitskiy 0ba357343b vty/telnet_interface.c: use DLGLOBAL logging sub-system
Change-Id: I1564f4714a33d36792e4982deb8f19d1b740dc0c
2019-07-27 21:47:59 +07:00
Vadim Yanitskiy 0d8da790df gsm/gsm48.h: drop meaningless 'const' from gsm48_mi_to_string()
Change-Id: I5eb17edadf89ac47b4ca86c9e822037f7c0e518e
2019-07-26 05:23:56 +00:00
Daniel Willmann 6f3bbd4b9f stats_vty: Add verb to sentence for show asciidoc counters
Change-Id: Ib444383d2074ddb89b3fe5bbf198bcbfabd7057f
2019-07-25 11:39:11 +02:00
Eric Wild eb5769b8b3 tell ubsan to ignore SUN_LEN
ubsan will report undefined behavior due to the SUN_LEN macros interaction with a null pointer,
so let's tell ubsan to ignore this function. After carefully reviewing the final publically
availlable drafts of the C99,C11 and C18 standards I can confirm that dereferencing null pointers
is still undefined behavior, as such ubsan will always warn with absolutely every existing compiler
version. Since the sanitizers are periodically synced between llvm and gcc I'm also fairly confident
that rebuilding everything with compiler_rt to use the integrated sanitizers would result in the same message.
I sincerly hope that this explanation provides to be sufficient, If not I'd be willing to show up at
the next llvm dev meeting to provide quotes from actual sanitizer developers to back up these claims.

Change-Id: I0ff445072f1b46390c9f70b21d61c789e39358d5
2019-07-21 15:49:58 +00:00
Vadim Yanitskiy 1cc42f7b9e gsm/gsm0480.c: use DLGLOBAL and LOGL_ERROR for logging
Change-Id: Id38272ff93fae6d2fdf39df4ffc74856d6c9a898
2019-07-21 15:47:35 +00:00
Vadim Yanitskiy ec865ddb45 gsm/gsm0480.c: parse_ss(): drop needless debug print
Change-Id: Ie18c291d0cfe3b246d09ac6cfd9591951a2984c8
2019-07-21 15:47:35 +00:00
Harald Welte dd0d76be5f osmo_get_rand_id(): Avoid dead code by proper #if/#else/#endif
Change-Id: I34e465dead179487f7d4508e0e6ecf0e838c6eb7
Closes: CID#177910
2019-07-21 12:09:03 +02:00
Harald Welte cfd6ac6462 tdef: remove bogus OSMO_ASSERT(unsigned long >= 0)
Change-Id: I7a544d2d43b83135def296674f777e48fe5fd80a
Closes: CID#190866
2019-07-21 09:25:18 +02:00
Harald Welte c30d8be919 cbsp.c: Remove dead code
Change-Id: I0888fbad0f9094ec1b31e2cceecfc9cd372399bd
Closes: CID#202057
2019-07-21 07:59:42 +02:00
Harald Welte 3f27f71b5f Add Cell Broadcast related definitions from 3GPP TS 23.041
Change-Id: I1e2c62cb9047648907c91b99f764f6caba8f4493
2019-07-20 12:11:28 +02:00
Harald Welte f72155a3a4 cbsp: Introduce osmo_cbsp_errstr
Rather than having the encoder/decoder library print some log
messages in case of encoding/decoding errors, let's provide something
akin to 'errno', but with a string instead of a numeric error code.

The 'osmo_cbsp_errstr' global variable (if set) contains a
human-readable string describing the most recent encoding/decoding error.

It exists separately for each thread and hence can be used safely in
multi-threaded environments.

Change-Id: Id9a5a595a76ba278647aee9470ded213d8464103
2019-07-20 12:11:28 +02:00
Harald Welte 07958e44ec CBSP (Cell Broadcast Service Protocol; 3GPP TS 48.049) support
This introduces definitions as well as a parser+encoder for the
Cell Broadcast Service Protocol (CBSP) as specified in 3GPP TS 48.049.

CBSP is used on the interface between CBC and BSC.

Related: OS#3537
Change-Id: I5b7ae08f67e415967b60ac4b824db9e22ca00935
2019-07-20 12:11:28 +02:00
Vadim Yanitskiy 00a55ae7fe bitvec/bitval2mask(): cosmetic: get rid of temporary int variable
Change-Id: I9d6f6b66c99c43107d1ad3e80af332e967bb19e8
2019-07-18 09:07:53 +00:00
Vadim Yanitskiy 74474cf8a6 osmo_gsm48_rest_octets_si3_decode(): fix copy-paste error in comment
Change-Id: I57a330e16cc2910597672e1b27cf971499cea5bc
2019-07-18 09:07:30 +00:00
Ruben Undheim 8f6700fa8a Set HTML_TIMESTAMP to NO to make build reproducible
Change-Id: I56cce5cda0621f5e9f1c28aaad4646e9e267d17d
2019-07-17 11:03:44 +00:00
Oliver Smith a3dec04c00 contrib/jenkins.sh: run "make maintainer-clean"
Related: OS#3047
Change-Id: Ic147678e7906a8b9ad7fac8367602b656f4172e6
2019-07-11 03:37:36 +00:00
Vadim Yanitskiy d1f15bd896 libosmogsm/l1sap.h: extend ph_rach_ind_param with lqual_cb
The link quality, defined by C/I (Carrier-to-Interference) ratio,
can be computed from the training sequence of each burst, where we
can compare the "ideal" training sequence with the actual training
sequence and then express that in cB (centiBels, dB * 10).

By analogy with both RSSI and ToA, it can be used to filter out
false-positive detections and ghost Access Bursts.

Change-Id: Ie2a66ebd040b61d6daf49e04bf8a84d3d64764ee
2019-07-10 15:48:33 +00:00
Vadim Yanitskiy e2425485c4 Revert "utils.h: require a semi colon after OSMO_ASSERT"
This reverts commit 4e284b6379.

Unfortunately, some projects such as OsmoMSC, OsmoBTS and OpenBSC
do contain OSMO_ASSERT statements without a semi colon. Thus,
this change causes compilation errors when building them.

Please note that only the OSMO_ASSERT's definition is reverted,
while changes to other files (adding missing semicolons) are kept.

Change-Id: I6da4d7397d993f6c1af658cb5ae1e49c92a1b350
2019-07-09 14:05:19 +07:00
Alexander Couzens 4e284b6379 utils.h: require a semi colon after OSMO_ASSERT
When using `OSMO_ASSERT(exp);` clang will warn about
an empty expression because the semi colon was superflous.
Use do {} while (0) to enfore the need of a semi colon.
This might break other test.

Change-Id: I2272d29a81496164bebd1696a694383a28a86434
2019-07-08 13:23:45 +00:00
Oliver Smith 316d1e1b7b Makefile.am: don't delete example.xml, vtydoc.xsd
Do not remove the entire doc/vty/ dir during the doxygen generation,
because it contains versioned files.

Fixes: 2fe50ac951 ("doxygen: enable cross referencing everywhere")
Related: OS#3986
Change-Id: I884398c5e834ae2fac0af8c9b52d65bb3ceacb2d
2019-06-28 12:27:30 +00:00
Oliver Smith 4481e38a21 gitignore: add doc/*.tag.prep
Ignore files created during the two-pass doxygen generation that was
introduced in Ib03d0b70d536c8f1386def666c89106a840f7363.

Change-Id: I719bbc968420c462426d2c0ce703c7f3b2c1139e
2019-06-28 12:27:30 +00:00
Pau Espin e1e1ec31a3 vty: Simplify char escaping in asciidoc output
Change-Id: I7df6858bb98abffc1d5bf420f991ae5854b24638
2019-06-25 21:46:44 +00:00
Pau Espin 28a198f9c0 gsm: lapd_core: Log timeout used upon start of T200
The timeout is calculated dynamically in t200_by_lchan() based on FN
advance value estimated by bts_get_avg_fn_advance(), so it's informative
to have the final value printed out.

Change-Id: Ib50a9c23de881c66c9218833703cc41101e06bfd
2019-06-21 18:55:14 +02:00
Pau Espin 18e019e896 vty: Remove trailing whitespace in output from show asciidoc
Change-Id: Ifb3115c7488fbcf082cc9b92abc25cf7c46064e0
2019-06-19 14:26:23 +02:00
Alexander Couzens 76e8cbd8ab bitvec: correct comment in bitvec_alloc
The function allocates x bytes not bits for the vector.

Change-Id: I60fbe9fe9acd11c5d3232207f1bb677e8a98625f
2019-06-17 15:14:41 +00:00
Eric Wild dda07be055 add define for magic tmsi constant
Change-Id: I52b9f6b5f3e96d85a390ba2af21d7814df8aaeec
2019-06-17 12:19:20 +02:00
Vadim Yanitskiy a08edff80c Revert "fsm.c: Print error message for FSM with allstate_action but no events"
This reverts commit b3f94eb39e, that
unfortunately breaks some projects which call osmo_fsm_register()
on DSO load (i.e. using __attribute__((constructor))) before the
logging is initialized.

Change-Id: Idc6fcce7e946c23d48589b920e309d60aa7b6645
2019-06-16 01:04:15 +07:00
Harald Welte b3f94eb39e fsm.c: Print error message for FSM with allstate_action but no events
As suggested by Vadim while reviewing a related fix for ipa_keepalive.c
in libosmo-abis (see https://gerrit.osmocom.org/#/c/libosmo-abis/+/13540/),
it makes sense to print an error message if anyone registers a FSM
that specifies an allstate_action callback but at the same time no
events that would ever end up in that callback.

Change-Id: I9e73f7363ab15a00843e3f0d1e5776f4be7ebc46
2019-06-15 10:54:26 +02:00
Pau Espin 32e6710487 vty: command.c: Fix: single-choice optional args are no longer passed incomplete to vty func
For instance, take command "single0 [one]":
If user executes "single0 on", VTY func will receive argv[0]="one"
instead of argv[0]="on".

Related: OS#4045
Change-Id: I5f4e2d16c62a2d22717989c6acc77450957168cb
2019-06-14 17:44:21 +02:00
Pau Espin 7e1b03f763 vty: command.c: Fix: multi-choice args are no longer passed incomplete to vty func
For instance, take command "multi0 (one|two|three)":
If user executes "multi0 tw", VTY func will receive argv[0]="two"
instead of argv[0]="tw".

Fixes: OS#4045
Change-Id: I91b6621ac3d87fda5412a9b415e7bfb4736c8a9a
2019-06-14 17:44:16 +02:00
Pau Espin 14aadd5b6f vty: tests: Verify incomplete optional parameters are passed to vty funcs
The test shows that in the case were "single0 on" is executed, VTY
function should return complete "single0 one" but it doesn't.

Related: OS#4045
Change-Id: Ib5b9dc07e2b280dc95011b3926afb1d490cadd81
2019-06-14 12:43:19 +02:00
Pau Espin 8930ace072 vty: command.c: Get rid of big indentation block
This block will become bigger in forthcoming commits.

Change-Id: Ibc1494014b1e77ce10950f7268a44d2d2091a6f2
2019-06-14 12:42:22 +02:00
Pau Espin c17c6d6ea5 command.c: Improve return check condition in cmd_execut_command_real()
Check against MAX argc is changed to == since it cannot be incremented
twice without passing the check.

Change-Id: Ia330e475989fda863bedcc3cbf94deaf8dd83037
2019-06-14 12:38:44 +02:00
Pau Espin cc794e993c logging: Use reentrant ctime_r instead of ctime
It was noticed that multithreaded processes like osmo-trx can crash upon
using ctime().

Related: OS#4055
Change-Id: I19ebf29a2f1fc855bb7d56766b338c7c3432dfd1
2019-06-13 19:35:11 +02:00
Kevin Redon 77021c7bec (minor) fix typo in comments
Change-Id: I697af428a2ea9a0ccd3f04ba8ec4664935ae29f8
2019-06-13 18:13:34 +02:00
Pau Espin 3aef238980 logging: Check return error from time() call
Related: OS#4055
Change-Id: Ief155a76169426a677256e09d3e91751c4e2529f
2019-06-13 15:34:01 +00:00
Kevin Redon d1e220fb67 minor: don't redefine macros
the DEBUG macro name and ARRAY_SIZE macro function are frequently
used in other projects. If these projects also use libosmocore,
the macros will be redefined. This also generates a warning message
during compilation.
Not redefining the macros removes the warning message and possible
(but unlikely) mis-redefinition.

Change-Id: I0ba91eae8eacc5542d1647601b372e417ed1713c
2019-06-13 13:49:30 +00:00
Kevin Redon 1af2cd5624 fix isdigit taking unsigned as input
fixes the following error warnings when cross-compiling using:
./configure --enable-static --prefix=/usr/local/arm-none-eabi --host=arm-none-eabi --enable-embedded --disable-doxygen --disable-shared --disable-pseudotalloc --enable-external-tests CFLAGS="-Os -ffunction-sections -fdata-sections -nostartfiles -nodefaultlibs -Werror -Wno-error=deprecated -Wno-error=deprecated-declarations -Wno-error=cpp -mthumb -Os -mlong-calls -g3 -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -Wno-error=format"

utils.c:1002:18: error: array subscript has type 'char' [-Werror=char-subscripts]
 1002 |   if (!isdigit(in[i]))

gsm23003.c:414:34: error: array subscript has type 'char' [-Werror=char-subscripts]
  414 |  if (!mnc_str || !isdigit(mnc_str[0]) || strlen(mnc_str) > 3)

Change-Id: Ia13fd5ee79fc6dc3291c0b99958ab3c01afee17d
2019-06-13 13:49:30 +00:00
Pau Espin 274ac4dcc3 vty: command.c: Get rid of huge indentation block
Huge conditional block inside for loop is negated in this patch
together with a "continue" keyword, similar to what was already done
recently in 4742526645.

Change-Id: I803c4ed38e9ab09bf929528c75a60e6f65da3928
2019-06-12 14:25:11 +00:00
Pau Espin de89099f68 cosmetic: vty: command.c: Use upper case for enum match_type value names
Makes code easier to follow because enum values no longer look like
variables.

Change-Id: Ib6e9592c5962d047869a280c10f9b557fae6f435
2019-06-12 14:25:11 +00:00
Vadim Yanitskiy b8734baa23 protocol/gsm_04_08.h: do not check if unsigned is positive
Change-Id: I6b486b52a3733d5fd5e8ba18acbc9374e2e8bd7e
2019-06-12 11:29:06 +00:00
Vadim Yanitskiy d9fc6041e7 core/utils: drop meaningless const from return value of osmo_luhn()
Change-Id: I085da06f31a0a6862ae2ba041fafc134cc240f7e
2019-06-12 11:29:06 +00:00
Pau Espin 6df2e44404 vty: command.c: Fix is_cmd_ambiguous() returning always 0
inner block defined variable "enum match_type ret" was being masking
outter block variable "int ret = 0". The ret variable was being given
non zero values only inside the inner block, so that change was done on
the inner variable and not the outer one, which is returned.

Fixes: 5314c513f2
Change-Id: Iec87d7db49a096d07e38ff8a060b923a52bfd6ba
2019-06-11 21:50:17 +02:00
Pau Espin 4742526645 vty: command.c: Get rid of huge indentation block
Huge conditional block inside foor loop is negated in this patch
together with a "continue" keyword.

Change-Id: I9715734ed276f002fdc8c3b9742531ad36b2ef9e
2019-06-11 21:04:11 +02:00