Compare commits

...

9 Commits

Author SHA1 Message Date
Pekka Vuorela
a7227c6cad Merge pull request #43 from sailfishos/conf_unit_test
[ofono] Don't care about whitespace in config unit test. JB#61330
2024-02-19 16:01:47 +02:00
Pekka Vuorela
cff7c7adb1 [ofono] Don't care about whitespace in config unit test. JB#61330
New glib keeps some extra line feed on the merged conf file data.
It shouldn't really matter so ignore such differences on the test.
2024-02-19 15:56:39 +02:00
Matti Lehtimäki
a50522b062 Merge pull request #42 from sailfishos/jb61571
Backport two patches from upstream to fix CVE-2023-4233 and CVE-2023-4234
2024-02-19 14:13:18 +02:00
Denis Grigorev
bb7d65f41a smsutil: Validate the length of the address field
This addresses CVE-2023-4233.
2024-02-16 17:50:58 +02:00
Denis Grigorev
278f28d15c smsutil: Check that submit report fits in memory
This addresses CVE-2023-4234.
2024-02-16 17:50:43 +02:00
Matti Lehtimäki
3afa0876c6 Merge pull request #40 from sailfishos/jb58763
[ofono] Add support for NR networks. JB#58763
2023-04-14 22:36:31 +03:00
Matti Lehtimäki
04162f719e [ofono] Add support for NR networks. JB#58763 2023-01-02 11:26:51 +02:00
Slava Monich
4ae4d688ce Merge pull request #41 from monich/uaf
Fix use after free
2023-01-02 11:13:43 +02:00
Slava Monich
224b551feb [voicecall] Fix use after free. JB#54354
Thanks to Denis Grigorev for pointing it out.
2023-01-02 00:38:40 +02:00
13 changed files with 195 additions and 18 deletions

View File

@@ -23,14 +23,17 @@ extern "C" {
#endif
#include <ofono/types.h>
#include <stdint.h>
enum ofono_cell_type {
OFONO_CELL_TYPE_GSM,
OFONO_CELL_TYPE_WCDMA,
OFONO_CELL_TYPE_LTE
OFONO_CELL_TYPE_LTE,
OFONO_CELL_TYPE_NR /* Since 1.29+git8 */
};
#define OFONO_CELL_INVALID_VALUE (INT_MAX)
#define OFONO_CELL_INVALID_VALUE_INT64 (INT64_MAX)
struct ofono_cell_info_gsm {
int mcc; /* Mobile Country Code (0..999) */
@@ -70,6 +73,22 @@ struct ofono_cell_info_lte {
int timingAdvance; /* (Distance = 300m/us) TS 36.321 */
};
/* Since 1.29+git8 */
struct ofono_cell_info_nr {
int mcc; /* Mobile Country Code (0..999) */
int mnc; /* Mobile Network Code (0..999) */
int64_t nci; /* NR Cell Identity */
int pci; /* Physical cell id (0..1007) */
int tac; /* Tracking area code */
int nrarfcn; /* 22-bit NR Absolute RC Channel Number */
int ssRsrp; /* SS Reference Signal Receive Power TS 38.215 */
int ssRsrq; /* SS Reference Signal Receive Quality TS 38.215 and 38.133 */
int ssSinr; /* SS Reference Signal-to-Noise Ratio TS 38.215 and 38.133*/
int csiRsrp; /* CSI Reference Signal Receive Power TS 38.215 */
int csiRsrq; /* CSI Reference Signal Receive Quality TS 38.215 */
int csiSinr; /* CSI Reference Signal-to-Noise Ratio TS 38.215 and 38.133 */
};
typedef struct ofono_cell {
enum ofono_cell_type type;
ofono_bool_t registered;
@@ -77,6 +96,7 @@ typedef struct ofono_cell {
struct ofono_cell_info_gsm gsm;
struct ofono_cell_info_wcdma wcdma;
struct ofono_cell_info_lte lte;
struct ofono_cell_info_nr nr; /* Since 1.29+git8 */
} info;
} *ofono_cell_ptr;

View File

@@ -34,6 +34,7 @@ enum ofono_radio_access_mode {
OFONO_RADIO_ACCESS_MODE_GSM = 0x1,
OFONO_RADIO_ACCESS_MODE_UMTS = 0x2,
OFONO_RADIO_ACCESS_MODE_LTE = 0x4,
OFONO_RADIO_ACCESS_MODE_NR = 0x8, /* Since 1.29+git8 */
};
enum ofono_radio_band_gsm {

View File

@@ -57,7 +57,11 @@ enum ofono_access_technology {
OFONO_ACCESS_TECHNOLOGY_UTRAN_HSDPA_HSUPA = 6,
OFONO_ACCESS_TECHNOLOGY_EUTRAN = 7,
OFONO_ACCESS_TECHNOLOGY_NB_IOT_M1 = 8,
OFONO_ACCESS_TECHNOLOGY_NB_IOT_NB1 = 9
OFONO_ACCESS_TECHNOLOGY_NB_IOT_NB1 = 9,
OFONO_ACCESS_TECHNOLOGY_EUTRA_5GCN = 10, /* Since 1.29+git8 */
OFONO_ACCESS_TECHNOLOGY_NR_5GCN = 11, /* Since 1.29+git8 */
OFONO_ACCESS_TECHNOLOGY_NG_RAN = 12, /* Since 1.29+git8 */
OFONO_ACCESS_TECHNOLOGY_EUTRA_NR = 13, /* Since 1.29+git8 */
};
/* 27.007 Section 6.2 */

View File

@@ -57,14 +57,19 @@ struct cell_property {
const char *name;
glong off;
int flag;
int type;
};
#define CELL_GSM_PROPERTY(value,name) \
{ #name, G_STRUCT_OFFSET(struct ofono_cell_info_gsm,name), value }
{ #name, G_STRUCT_OFFSET(struct ofono_cell_info_gsm,name), value, DBUS_TYPE_INT32 }
#define CELL_WCDMA_PROPERTY(value,name) \
{ #name, G_STRUCT_OFFSET(struct ofono_cell_info_wcdma,name), value }
{ #name, G_STRUCT_OFFSET(struct ofono_cell_info_wcdma,name), value, DBUS_TYPE_INT32 }
#define CELL_LTE_PROPERTY(value,name) \
{ #name, G_STRUCT_OFFSET(struct ofono_cell_info_lte,name), value }
{ #name, G_STRUCT_OFFSET(struct ofono_cell_info_lte,name), value, DBUS_TYPE_INT32 }
#define CELL_NR_PROPERTY(value,name) \
{ #name, G_STRUCT_OFFSET(struct ofono_cell_info_nr,name), value, DBUS_TYPE_INT32 }
#define CELL_NR_PROPERTY64(value,name) \
{ #name, G_STRUCT_OFFSET(struct ofono_cell_info_nr,name), value, DBUS_TYPE_INT64 }
static const struct cell_property cell_gsm_properties [] = {
CELL_GSM_PROPERTY(0x001,mcc),
@@ -104,6 +109,21 @@ static const struct cell_property cell_lte_properties [] = {
CELL_LTE_PROPERTY(0x800,timingAdvance)
};
static const struct cell_property cell_nr_properties [] = {
CELL_NR_PROPERTY(0x001,mcc),
CELL_NR_PROPERTY(0x002,mnc),
CELL_NR_PROPERTY64(0x004,nci),
CELL_NR_PROPERTY(0x008,pci),
CELL_NR_PROPERTY(0x010,tac),
CELL_NR_PROPERTY(0x020,nrarfcn),
CELL_NR_PROPERTY(0x040,ssRsrp),
CELL_NR_PROPERTY(0x080,ssRsrq),
CELL_NR_PROPERTY(0x100,ssSinr),
CELL_NR_PROPERTY(0x200,csiRsrp),
CELL_NR_PROPERTY(0x400,csiRsrq),
CELL_NR_PROPERTY(0x800,csiSinr),
};
#define CELL_PROPERTY_REGISTERED 0x1000
typedef void (*cell_info_dbus_append_fn)(DBusMessageIter *it,
@@ -124,6 +144,8 @@ static const char *cell_info_dbus_cell_type_str(enum ofono_cell_type type)
return "wcdma";
case OFONO_CELL_TYPE_LTE:
return "lte";
case OFONO_CELL_TYPE_NR:
return "nr";
default:
return "unknown";
}
@@ -142,6 +164,9 @@ static const struct cell_property *cell_info_dbus_cell_properties
case OFONO_CELL_TYPE_LTE:
*count = G_N_ELEMENTS(cell_lte_properties);
return cell_lte_properties;
case OFONO_CELL_TYPE_NR:
*count = G_N_ELEMENTS(cell_nr_properties);
return cell_nr_properties;
default:
*count = 0;
return NULL;
@@ -202,10 +227,18 @@ static void cell_info_dbus_append_properties(DBusMessageIter *it,
dbus_message_iter_open_container(it, DBUS_TYPE_ARRAY, "{sv}", &dict);
for (i = 0; i < n; i++) {
gint32 value = G_STRUCT_MEMBER(int, &cell->info, prop[i].off);
if (value != OFONO_CELL_INVALID_VALUE) {
ofono_dbus_dict_append(&dict, prop[i].name,
DBUS_TYPE_INT32, &value);
if (prop[i].type == DBUS_TYPE_INT64) {
gint64 value = G_STRUCT_MEMBER(gint64, &cell->info, prop[i].off);
if (value != OFONO_CELL_INVALID_VALUE_INT64) {
ofono_dbus_dict_append(&dict, prop[i].name,
DBUS_TYPE_INT64, &value);
}
} else {
gint32 value = G_STRUCT_MEMBER(int, &cell->info, prop[i].off);
if (value != OFONO_CELL_INVALID_VALUE) {
ofono_dbus_dict_append(&dict, prop[i].name,
DBUS_TYPE_INT32, &value);
}
}
}
dbus_message_iter_close_container(it, &dict);
@@ -375,11 +408,20 @@ static int cell_info_dbus_compare(const struct ofono_cell *c1,
for (i = 0; i < n; i++) {
const glong offset = prop[i].off;
gint32 v1 = G_STRUCT_MEMBER(int, &c1->info, offset);
gint32 v2 = G_STRUCT_MEMBER(int, &c2->info, offset);
if (prop[i].type == DBUS_TYPE_INT64) {
gint64 v1 = G_STRUCT_MEMBER(gint64, &c1->info, offset);
gint64 v2 = G_STRUCT_MEMBER(gint64, &c2->info, offset);
if (v1 != v2) {
mask |= prop[i].flag;
if (v1 != v2) {
mask |= prop[i].flag;
}
} else {
gint32 v1 = G_STRUCT_MEMBER(int, &c1->info, offset);
gint32 v2 = G_STRUCT_MEMBER(int, &c2->info, offset);
if (v1 != v2) {
mask |= prop[i].flag;
}
}
}
@@ -427,7 +469,7 @@ static void cell_info_dbus_property_changed(CellInfoDBus *dbus,
ofono_dbus_clients_signal_property_changed(
dbus->clients, entry->path,
CELL_DBUS_INTERFACE, prop[i].name,
DBUS_TYPE_INT32,
prop[i].type,
G_STRUCT_MEMBER_P(&cell->info, prop[i].off));
mask &= ~prop[i].flag;
}

View File

@@ -70,6 +70,23 @@ int ofono_cell_compare_location(const struct ofono_cell *c1,
} else {
return l1->tac - l2->tac;
}
} else if (c1->type == OFONO_CELL_TYPE_NR) {
const struct ofono_cell_info_nr *n1 =
&c1->info.nr;
const struct ofono_cell_info_nr *n2 =
&c2->info.nr;
if (n1->mcc != n2->mcc) {
return n1->mcc - n2->mcc;
} else if (n1->mnc != n2->mnc) {
return n1->mnc - n2->mnc;
} else if (n1->nci != n2->nci) {
return n1->nci - n2->nci;
} else if (n1->pci != n2->pci) {
return n1->pci - n2->pci;
} else {
return n1->tac - n2->tac;
}
} else {
ofono_warn("Unexpected cell type");
return 0;

View File

@@ -710,6 +710,12 @@ const char *registration_tech_to_string(enum ofono_access_technology tech)
return "lte-cat-m1";
case ACCESS_TECHNOLOGY_NB_IOT_NB1:
return "lte-cat-nb1";
case ACCESS_TECHNOLOGY_EUTRA_5GCN:
return "lte";
case ACCESS_TECHNOLOGY_NR_5GCN:
case ACCESS_TECHNOLOGY_NG_RAN:
case ACCESS_TECHNOLOGY_EUTRA_NR:
return "nr";
case OFONO_ACCESS_TECHNOLOGY_NONE:
break;
default:

View File

@@ -46,6 +46,14 @@
OFONO_ACCESS_TECHNOLOGY_NB_IOT_M1 /* 8 */
#define ACCESS_TECHNOLOGY_NB_IOT_NB1 \
OFONO_ACCESS_TECHNOLOGY_NB_IOT_NB1 /* 9 */
#define ACCESS_TECHNOLOGY_EUTRA_5GCN \
OFONO_ACCESS_TECHNOLOGY_EUTRA_5GCN /* 10 */
#define ACCESS_TECHNOLOGY_NR_5GCN \
OFONO_ACCESS_TECHNOLOGY_NR_5GCN /* 11 */
#define ACCESS_TECHNOLOGY_NG_RAN \
OFONO_ACCESS_TECHNOLOGY_NG_RAN /* 12 */
#define ACCESS_TECHNOLOGY_EUTRA_NR \
OFONO_ACCESS_TECHNOLOGY_EUTRA_NR /* 13 */
/* 27.007 Section 7.2 <stat> */
#define NETWORK_REGISTRATION_STATUS_NOT_REGISTERED \

View File

@@ -65,7 +65,9 @@ struct ofono_radio_settings {
enum ofono_radio_access_mode ofono_radio_access_max_mode(
enum ofono_radio_access_mode mask)
{
return (mask & OFONO_RADIO_ACCESS_MODE_LTE) ?
return (mask & OFONO_RADIO_ACCESS_MODE_NR) ?
OFONO_RADIO_ACCESS_MODE_NR :
(mask & OFONO_RADIO_ACCESS_MODE_LTE) ?
OFONO_RADIO_ACCESS_MODE_LTE :
(mask & OFONO_RADIO_ACCESS_MODE_UMTS) ?
OFONO_RADIO_ACCESS_MODE_UMTS :
@@ -86,6 +88,8 @@ const char *ofono_radio_access_mode_to_string(enum ofono_radio_access_mode m)
return "umts";
case OFONO_RADIO_ACCESS_MODE_LTE:
return "lte";
case OFONO_RADIO_ACCESS_MODE_NR:
return "nr";
default:
return NULL;
}
@@ -110,6 +114,9 @@ ofono_bool_t ofono_radio_access_mode_from_string(const char *str,
} else if (g_str_equal(str, "lte")) {
*mode = OFONO_RADIO_ACCESS_MODE_LTE;
return TRUE;
} else if (g_str_equal(str, "nr")) {
*mode = OFONO_RADIO_ACCESS_MODE_NR;
return TRUE;
}
return FALSE;
@@ -438,7 +445,7 @@ static void radio_available_rats_query_callback(const struct ofono_error *error,
struct ofono_radio_settings *rs = data;
if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
rs->available_rats = available_rats & 0x7;
rs->available_rats = available_rats & 0xF;
else
DBG("Error while querying available rats");

View File

@@ -628,6 +628,10 @@ gboolean sms_decode_address_field(const unsigned char *pdu, int len,
if (!next_octet(pdu, len, offset, &addr_len))
return FALSE;
/* According to 23.040 9.1.2.5 Address-Length must not exceed 20 */
if (addr_len > 20)
return FALSE;
if (sc && addr_len == 0) {
out->address[0] = '\0';
return TRUE;
@@ -941,10 +945,16 @@ static gboolean decode_submit_report(const unsigned char *pdu, int len,
return FALSE;
if (out->type == SMS_TYPE_SUBMIT_REPORT_ERROR) {
if (expected > (int) sizeof(out->submit_err_report.ud))
return FALSE;
out->submit_err_report.udl = udl;
memcpy(out->submit_err_report.ud,
pdu + offset, expected);
} else {
if (expected > (int) sizeof(out->submit_ack_report.ud))
return FALSE;
out->submit_ack_report.udl = udl;
memcpy(out->submit_ack_report.ud,
pdu + offset, expected);

View File

@@ -2665,9 +2665,9 @@ void ofono_voicecall_disconnected(struct ofono_voicecall *vc, int id,
if (l) {
/* Incoming call was disconnected in the process of being
* filtered. voicecall_destroy cancels it. */
voicecall_destroy(l->data);
vc->incoming_filter_list = g_slist_delete_link
(vc->incoming_filter_list, l);
voicecall_destroy(l->data);
return;
}

View File

@@ -318,6 +318,28 @@ static struct ofono_cell *test_cell_init_lte(struct ofono_cell *cell)
return cell;
}
static struct ofono_cell *test_cell_init_nr(struct ofono_cell *cell)
{
struct ofono_cell_info_nr *nr = &cell->info.nr;
memset(cell, 0, sizeof(*cell));
cell->type = OFONO_CELL_TYPE_NR;
cell->registered = TRUE;
nr->mcc = 244;
nr->mnc = 91;
nr->nci = 36591883;
nr->pci = 309;
nr->tac = 4030;
nr->nrarfcn = INT_MAX;
nr->ssRsrp = 106;
nr->ssRsrq = 6;
nr->ssSinr = INT_MAX;
nr->csiRsrp = 106;
nr->csiRsrq = 6;
nr->csiSinr = INT_MAX;
return cell;
}
/* ==== Misc ==== */
static void test_misc(void)
@@ -540,6 +562,13 @@ static void test_get_all4(void)
{
struct ofono_cell cell;
test_get_all(test_cell_init_nr(&cell), "nr");
}
static void test_get_all5(void)
{
struct ofono_cell cell;
/* Invalid cell */
memset(&cell, 0xff, sizeof(cell));
test_get_all(&cell, "unknown");
@@ -1145,6 +1174,7 @@ int main(int argc, char *argv[])
g_test_add_func(TEST_("GetAll2"), test_get_all2);
g_test_add_func(TEST_("GetAll3"), test_get_all3);
g_test_add_func(TEST_("GetAll4"), test_get_all4);
g_test_add_func(TEST_("GetAll5"), test_get_all5);
g_test_add_func(TEST_("GetInterfaceVersion"), test_get_version);
g_test_add_func(TEST_("GetType"), test_get_type);
g_test_add_func(TEST_("GetRegistered"), test_get_registered);

View File

@@ -226,6 +226,35 @@ static void test_compare(void)
c2 = c1; c2.info.lte.timingAdvance++;
g_assert(!ofono_cell_compare_location(&c1, &c2));
/* NR */
c1.type = OFONO_CELL_TYPE_NR;
c2 = c1;
g_assert(!ofono_cell_compare_location(&c1, &c2));
c2 = c1; c2.info.nr.mcc++;
g_assert(ofono_cell_compare_location(&c1, &c2) < 0);
c2 = c1; c2.info.nr.mnc++;
g_assert(ofono_cell_compare_location(&c1, &c2) < 0);
c2 = c1; c2.info.nr.nci++;
g_assert(ofono_cell_compare_location(&c1, &c2) < 0);
c2 = c1; c2.info.nr.pci++;
g_assert(ofono_cell_compare_location(&c1, &c2) < 0);
c2 = c1; c2.info.nr.tac++;
g_assert(ofono_cell_compare_location(&c1, &c2) < 0);
/* Other attributes are not being compared */
c2 = c1; c2.info.nr.nrarfcn++;
g_assert(!ofono_cell_compare_location(&c1, &c2));
c2 = c1; c2.info.nr.ssRsrp++;
g_assert(!ofono_cell_compare_location(&c1, &c2));
c2 = c1; c2.info.nr.ssRsrq++;
g_assert(!ofono_cell_compare_location(&c1, &c2));
c2 = c1; c2.info.nr.ssSinr++;
g_assert(!ofono_cell_compare_location(&c1, &c2));
c2 = c1; c2.info.nr.csiRsrp++;
g_assert(!ofono_cell_compare_location(&c1, &c2));
c2 = c1; c2.info.nr.csiRsrq++;
g_assert(!ofono_cell_compare_location(&c1, &c2));
c2 = c1; c2.info.nr.csiSinr++;
g_assert(!ofono_cell_compare_location(&c1, &c2));
/* Unknown type */
c1.type = c2.type = (enum ofono_cell_type)-1;
g_assert(!ofono_cell_compare_location(&c1, &c2));

View File

@@ -75,6 +75,7 @@ static void test_merge1(const char *conf, const char *conf1, const char *out)
char *file1 = g_strconcat(subdir, "/bar.conf", NULL);
GKeyFile *k = g_key_file_new();
char *data;
char *out_stripped = g_strstrip(g_strdup(out));
g_assert(!mkdir(subdir, 0700));
g_assert(g_file_set_contents(file, conf, -1, NULL));
@@ -84,8 +85,9 @@ static void test_merge1(const char *conf, const char *conf1, const char *out)
g_key_file_set_list_separator(k, ',');
ofono_conf_merge_files(k, file);
data = g_key_file_to_data(k, NULL, NULL);
g_strstrip(data);
DBG("\n%s", data);
g_assert(!g_strcmp0(data, out));
g_assert(!g_strcmp0(data, out_stripped));
g_free(data);
g_key_file_unref(k);
@@ -94,6 +96,7 @@ static void test_merge1(const char *conf, const char *conf1, const char *out)
remove(subdir);
remove(dir);
g_free(out_stripped);
g_free(file);
g_free(file1);
g_free(dir);