pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-uecups/+/27769 )
Change subject: tun_device: Avoid deadlocks logging while thread is cancelled
......................................................................
tun_device: Avoid deadlocks logging while thread is cancelled
We cannot garantee that LOGP will not end up calling a syscall which can
be a cancellation point. Since the syscall will be probably called while
having the logging mutex locked, an eventuall cancellation of the thread
would leave the logging mutex locked forever, hence making all other
threads deadlock as soon as they try to write anything to the log.
Change-Id: I72a0b536c8f39857960f132a5b84cdf5b8519732
---
M daemon/tun_device.c
1 file changed, 11 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-uecups refs/changes/69/27769/1
diff --git a/daemon/tun_device.c b/daemon/tun_device.c
index 5993856..e9c0400 100644
--- a/daemon/tun_device.c
+++ b/daemon/tun_device.c
@@ -139,12 +139,17 @@
uint8_t *buffer = base_buffer + sizeof(struct gtp1_header);
struct sockaddr_storage daddr;
+ int old_cancelst_unused;
/* initialize the fixed part of the GTP header */
gtph->flags = 0x30;
gtph->type = GTP_TPDU;
pthread_cleanup_push(tun_device_pthread_cleanup_routine, tun);
+ /* IMPORTANT!: All logging functions in this function block must be called with
+ * PTHREAD_CANCEL_DISABLE set, otherwise the thread could be cancelled while
+ * holding the logging mutex, hence causing deadlock with main (or other)
+ * thread. */
while (1) {
struct gtp_tunnel *t;
@@ -154,6 +159,7 @@
/* 1) read from tun */
rc = read(tun->fd, buffer, MAX_UDP_PACKET);
if (rc < 0) {
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelst_unused);
LOGTUN(tun, LOGL_FATAL, "Error readingfrom tun device: %s\n", strerror(errno));
exit(1);
}
@@ -162,8 +168,10 @@
rc = parse_pkt(&pinfo, buffer, nread);
if (rc < 0) {
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelst_unused);
LOGTUN(tun, LOGL_NOTICE, "Error parsing IP packet: %s\n",
osmo_hexdump(buffer, nread));
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old_cancelst_unused);
continue;
}
@@ -181,7 +189,9 @@
getnameinfo((const struct sockaddr *)&pinfo.saddr,
sizeof(pinfo.saddr), host, sizeof(host), port, sizeof(port),
NI_NUMERICHOST | NI_NUMERICSERV);
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelst_unused);
LOGTUN(tun, LOGL_NOTICE, "No tunnel found for source address %s:%s\n", host, port);
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old_cancelst_unused);
continue;
}
outfd = t->gtp_ep->fd;
@@ -193,6 +203,7 @@
rc = sendto(outfd, base_buffer, nread+sizeof(*gtph), 0,
(struct sockaddr *)&daddr, sizeof(daddr));
if (rc < 0) {
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelst_unused);
LOGTUN(tun, LOGL_FATAL, "Error Writing to UDP socket: %s\n", strerror(errno));
exit(1);
}
--
To view, visit https://gerrit.osmocom.org/c/osmo-uecups/+/27769
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-uecups
Gerrit-Branch: master
Gerrit-Change-Id: I72a0b536c8f39857960f132a5b84cdf5b8519732
Gerrit-Change-Number: 27769
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: newchange
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/27763 )
Change subject: Avoid generating zero-length packets
......................................................................
Avoid generating zero-length packets
I used the construct like f_rnd_octstring(f_rnd_int(100)) in a number
of places to generate random-length packets with randomized length.
The problem I didn't realize is that f_rnd_int() of course can also
return '0', which would generate zero-length packets. This may be
permitted in some protocols, but it leads to problems e.g. when trying
to send a UDP packet of zero length (which the kernel will not do).
So let's introduce
* f_rnd_int_nonzero() for returning non-zero randomized integers
* f_rnd_octstring_rnd_len() for returning a random-length random payload
octet string
* replace all f_rnd_octstring(f_rnd_int()) call sites with the new
function.
Change-Id: I818a113ff8d2a2f7cab2ec7d9c8661607c6331d6
Closes: OS#5528
---
M fr/FR_Tests.ttcn
M library/Osmocom_Types.ttcn
M pcap-client/OPCAP_CLIENT_Tests.ttcn
M remsim/RemsimClient_Tests.ttcn
M sccp/SCCP_Tests_RAW.ttcn
M stp/STP_Tests.ttcn
M stp/STP_Tests_M3UA.ttcn
7 files changed, 29 insertions(+), 19 deletions(-)
Approvals:
Jenkins Builder: Verified
pespin: Looks good to me, but someone else must approve
fixeria: Looks good to me, approved
diff --git a/fr/FR_Tests.ttcn b/fr/FR_Tests.ttcn
index b7a56c3..65029c1 100644
--- a/fr/FR_Tests.ttcn
+++ b/fr/FR_Tests.ttcn
@@ -276,7 +276,7 @@
var integer ran_index := 0;
var template (value) PDU_LLC llc_tx;
var template (present) PDU_LLC llc_rx_exp;
- var octetstring llc_payload := f_rnd_octstring(f_rnd_int(max_llc_payload_len));
+ var octetstring llc_payload := f_rnd_octstring_rnd_len(max_llc_payload_len);
var PDU_LLC llc_rx;
timer T := 5.0;
diff --git a/library/Osmocom_Types.ttcn b/library/Osmocom_Types.ttcn
index b698a2e..2edec36 100644
--- a/library/Osmocom_Types.ttcn
+++ b/library/Osmocom_Types.ttcn
@@ -65,6 +65,11 @@
return float2int(rnd()*int2float(max));
}
+/* return random integer 1 <= ret < max */
+function f_rnd_int_nonzero(integer max) return integer {
+ return float2int(1.0 + rnd()*int2float(max-1));
+}
+
/* return hexstring composed of random digits */
function f_rnd_hexstring(in integer len, in integer max := 16) return hexstring {
var integer i;
@@ -85,6 +90,11 @@
return ret;
}
+/* return ocetstring composed of random bytes, at least 1, maximum 'maxlen' bytes long */
+function f_rnd_octstring_rnd_len(in integer maxlen) return octetstring {
+ return f_rnd_octstring(f_rnd_int_nonzero(maxlen));
+}
+
/* return bitstring composed of random bits */
function f_rnd_bitstring(in integer len) return bitstring {
var octetstring oct := f_rnd_octstring(len / 8 + 1);
diff --git a/pcap-client/OPCAP_CLIENT_Tests.ttcn b/pcap-client/OPCAP_CLIENT_Tests.ttcn
index e9fe406..1efc343 100644
--- a/pcap-client/OPCAP_CLIENT_Tests.ttcn
+++ b/pcap-client/OPCAP_CLIENT_Tests.ttcn
@@ -144,7 +144,7 @@
var octetstring udp_payload;
/* we assume 1400 is low enough to avoid IP fragmentation */
- udp_payload := f_rnd_octstring(f_rnd_int(1400));
+ udp_payload := f_rnd_octstring_rnd_len(1400);
f_trafic_pkt_ab(udp_payload);
f_opcap_exp_udp(udp_payload, 0);
@@ -173,7 +173,7 @@
var octetstring udp_payload;
/* we assume 1400 is low enough to avoid IP fragmentation */
- udp_payload := f_rnd_octstring(f_rnd_int(1400));
+ udp_payload := f_rnd_octstring_rnd_len(1400);
f_trafic_pkt_ab(udp_payload);
/* expect packet to arrive on both simulated servers */
diff --git a/remsim/RemsimClient_Tests.ttcn b/remsim/RemsimClient_Tests.ttcn
index d7d6bc7..219573c 100644
--- a/remsim/RemsimClient_Tests.ttcn
+++ b/remsim/RemsimClient_Tests.ttcn
@@ -299,8 +299,8 @@
integer count := 100, integer i := 0) runs on client_test_CT
{
for (var integer j := 0; j < count; j := j+1) {
- var octetstring c_apdu := f_rnd_octstring(f_rnd_int(270));
- var octetstring r_apdu := f_rnd_octstring(f_rnd_int(270));
+ var octetstring c_apdu := f_rnd_octstring_rnd_len(270);
+ var octetstring r_apdu := f_rnd_octstring_rnd_len(270);
f_client2bank(cslot, bslot, c_apdu, i:=i);
f_bank2client(bslot, cslot, r_apdu, i:=i);
}
@@ -345,8 +345,8 @@
f_set_atr(cslot, '3B9F96801FC78031A073BE21136743200718000001A5'O, i:=1);
- var octetstring c_apdu := f_rnd_octstring(f_rnd_int(270));
- var octetstring r_apdu := f_rnd_octstring(f_rnd_int(270));
+ var octetstring c_apdu := f_rnd_octstring_rnd_len(270);
+ var octetstring r_apdu := f_rnd_octstring_rnd_len(270);
/* Send C-APDU from correct ClientId/Slot to simulated bankd */
f_client2bank(cslot, bslot, c_apdu, i:=1);
/* respond with R-APDU from correct bankId/Slot but stating wrong ClientId */
@@ -372,8 +372,8 @@
f_set_atr(cslot, '3B9F96801FC78031A073BE21136743200718000001A5'O, i:=1);
- var octetstring c_apdu := f_rnd_octstring(f_rnd_int(270));
- var octetstring r_apdu := f_rnd_octstring(f_rnd_int(270));
+ var octetstring c_apdu := f_rnd_octstring_rnd_len(270);
+ var octetstring r_apdu := f_rnd_octstring_rnd_len(270);
/* Send C-APDU from correct ClientId/Slot to simulated bankd */
f_client2bank(cslot, bslot, c_apdu, i:=1);
/* respond with R-APDU from wrong bankId but stating correct ClientId */
diff --git a/sccp/SCCP_Tests_RAW.ttcn b/sccp/SCCP_Tests_RAW.ttcn
index 5013ddf..fd6bad9 100644
--- a/sccp/SCCP_Tests_RAW.ttcn
+++ b/sccp/SCCP_Tests_RAW.ttcn
@@ -182,7 +182,7 @@
testcase TC_udt_without_cr_cc() runs on SCCP_Test_RAW_CT {
var SCCP_PAR_Address calling, called;
var SCCP_MTP3_TRANSFERind rx;
- var octetstring data := f_rnd_octstring(f_rnd_int(100));
+ var octetstring data := f_rnd_octstring_rnd_len(100);
/* Keep recommended ratio of T(iar) >= T(ias)*2, but anyway no IT
should be received in this case. */
@@ -215,7 +215,7 @@
testcase TC_tiar_timeout() runs on SCCP_Test_RAW_CT {
var SCCP_PAR_Address calling, called;
var OCT3 remote_lref;
- var octetstring data := f_rnd_octstring(f_rnd_int(100));
+ var octetstring data := f_rnd_octstring_rnd_len(100);
/* Set T(iar) in sccp_demo_user low enough that it will trigger before other side
has time to keep alive with a T(ias). Keep recommended ratio of
@@ -320,7 +320,7 @@
/* Test if the IUT SCCP code processes an XUDT [treat it like UDT] and answers back. */
testcase TC_process_rx_xudt() runs on SCCP_Test_RAW_CT {
var SCCP_PAR_Address calling, called;
- var octetstring data := f_rnd_octstring(f_rnd_int(100));
+ var octetstring data := f_rnd_octstring_rnd_len(100);
f_init_raw(mp_sccp_cfg[0]);
f_sleep(1.0);
diff --git a/stp/STP_Tests.ttcn b/stp/STP_Tests.ttcn
index 004af05..ac45b1d 100644
--- a/stp/STP_Tests.ttcn
+++ b/stp/STP_Tests.ttcn
@@ -73,7 +73,7 @@
f_M3UA_asp_up_act(0, omit, omit); // TODO: rctx
/* send a well-formed, encoded SCCP message via M3UA */
- var octetstring data := f_rnd_octstring(f_rnd_int(100));
+ var octetstring data := f_rnd_octstring_rnd_len(100);
var SCCP_PAR_Address called := valueof(ts_SccpAddr_GT('1234'H));
var SCCP_PAR_Address calling := valueof(ts_SccpAddr_GT('5678'H));
var PDU_SCCP sccp := valueof(ts_SCCP_UDT(called, calling, data));
@@ -105,7 +105,7 @@
f_M3UA_asp_up_act(0, omit, omit); // TODO: rctx
/* send a well-formed, encoded SCCP message via IPA */
- var octetstring data := f_rnd_octstring(f_rnd_int(100));
+ var octetstring data := f_rnd_octstring_rnd_len(100);
var SCCP_PAR_Address called := valueof(ts_SccpAddr_GT('1234'H));
var SCCP_PAR_Address calling := valueof(ts_SccpAddr_GT('5678'H));
var PDU_SCCP sccp := valueof(ts_SCCP_UDT(called, calling, data));
@@ -137,7 +137,7 @@
f_M3UA_asp_up_act(0, omit, omit); // TODO: rctx
/* send a well-formed, encoded SCCP message via IPA */
- var octetstring data := f_rnd_octstring(f_rnd_int(100));
+ var octetstring data := f_rnd_octstring_rnd_len(100);
var SCCP_PAR_Address called := valueof(ts_SccpAddr_GT('1234'H));
var SCCP_PAR_Address calling := valueof(ts_SccpAddr_GT('5678'H));
var PDU_SCCP sccp := valueof(ts_SCCP_UDT(called, calling, data));
@@ -173,7 +173,7 @@
f_M3UA_asp_up_act(0, omit, omit); // TODO: rctx
/* send a well-formed, encoded SCCP message via IPA */
- var octetstring data := f_rnd_octstring(f_rnd_int(100));
+ var octetstring data := f_rnd_octstring_rnd_len(100);
var SCCP_PAR_Address called := valueof(ts_SccpAddr_GT('1234'H));
var SCCP_PAR_Address calling := valueof(ts_SccpAddr_GT('5678'H));
var PDU_SCCP sccp := valueof(ts_SCCP_UDT(called, calling, data));
diff --git a/stp/STP_Tests_M3UA.ttcn b/stp/STP_Tests_M3UA.ttcn
index 31bab93..08fc9c9 100644
--- a/stp/STP_Tests_M3UA.ttcn
+++ b/stp/STP_Tests_M3UA.ttcn
@@ -407,7 +407,7 @@
integer idx_rx, template (omit) OCT4 rctx_receiver, OCT4 pc_rx,
OCT1 si := '23'O, OCT1 ni := '00'O, OCT1 mp := '00'O, OCT1 sls := '00'O)
runs on RAW_M3UA_CT {
- var octetstring data := f_rnd_octstring(f_rnd_int(100));
+ var octetstring data := f_rnd_octstring_rnd_len(100);
f_M3UA_send(idx_tx, ts_M3UA_DATA(rctx_sender,
ts_M3UA_protocol_data(pc_tx, pc_rx, si, ni, mp, sls, data)), 1);
f_M3UA_exp(idx_rx, tr_M3UA_DATA(rctx_receiver,
@@ -482,7 +482,7 @@
const integer iter_per_asp := 5;
var integer num_rx[NR_M3UA] := { 0, 0, 0 };
for (i := 0; i < 2*iter_per_asp; i := i+1) {
- var octetstring data := f_rnd_octstring(f_rnd_int(100));
+ var octetstring data := f_rnd_octstring_rnd_len(100);
var template (value) M3UA_Protocol_Data tx_pd;
var template (present) M3UA_Protocol_Data rx_pd;
tx_pd := ts_M3UA_protocol_data(pc_sender, pc_receiver, '23'O, '00'O, '00'O, '00'O, data);
@@ -533,7 +533,7 @@
/* verify traffic is routed from sender to new receiver */
for (i := 0; i < 10; i := i+1) {
- var octetstring data := f_rnd_octstring(f_rnd_int(100));
+ var octetstring data := f_rnd_octstring_rnd_len(100);
var template (value) M3UA_Protocol_Data tx_pd;
var template (present) M3UA_Protocol_Data rx_pd;
tx_pd := ts_M3UA_protocol_data(pc_sender, pc_receiver, '23'O, '00'O, '00'O, '00'O, data);
--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/27763
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: I818a113ff8d2a2f7cab2ec7d9c8661607c6331d6
Gerrit-Change-Number: 27763
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged
Attention is currently required from: osmith, pespin.
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-bsc-nat/+/27767 )
Change subject: bssap: forward paging to relevant BSCs only
......................................................................
Patch Set 1:
(1 comment)
Patchset:
PS1:
we also have to think of the case when a BTS is added during runtime of the BSC. At this point the bsc-nat doesn't know yet about the related cell identifier.
A new BTS cannot yet have any subscribers registered to it, so one could still use CIL sniffing of the COMPLETE L3 INFO in addition to the BSSMAP RESET based mechanism.
So we'll need the RESTET based mechanism, and either
* CIL sniffing duriung COMPLETE L3 INFO, or
* some new non-standard BSSMAP message to let the bsc-nat know of cell-ids that have been added
I would think the CIL sniffing is the more elegant approach. So The RESET based list helps us with the initial state after e.g. a bsc-nat reset, and the CIL sniffing helps us to keep up with changes afterwards.
Last, but not least we *may* have to keep in mind that BSSMAP message have a maximum length (typically imposted by the underlying SCCP/M3UA capability) and a very long list of BTSs in the BSC might overflow the BSSMAP RESET message that we're generating. For a pure SIGTRAN network this should not be a problem. However, for anything that actually still uses traditional SS7 circuits, there is a 272 byte limit on the MTP level. I guess we can ignore that for now but make sure to document this in the (bsc?) user manual, i.e. that with a large numer of BTSs this BSSMAP RESET message size could exceed the 272 byte limit of circuit-switched SS7/MTP, and that it is intended to be used over pure M3UA/SIGTRAN where such constraints don't exist (see RFC 4666 Section 1.3.2.1).
--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc-nat/+/27767
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-bsc-nat
Gerrit-Branch: master
Gerrit-Change-Id: Iad3d1de8339206fa80f9fd10ac9213a7728a3c73
Gerrit-Change-Number: 27767
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-CC: laforge <laforge(a)osmocom.org>
Gerrit-CC: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: osmith <osmith(a)sysmocom.de>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Comment-Date: Wed, 13 Apr 2022 15:08:53 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment