Commit Graph
51 Commits
Author SHA1 Message Date
Aleksander Morgado e9932bde9d libqcdm: fix heap out-of-bounds read in qcdm_cmd_pilot_sets_result
Validate the active, candidate, and neighbor count fields in
qcdm_cmd_pilot_sets_result() before parsing the sets.

Ensure that the sum of counts does not exceed the size of the static
sets array in the response structure, and that the calculated size
based on the counts fits within the received buffer len.

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/work_items/1069

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-07-13 10:59:28 +02:00
Aleksander Morgado 9642ed9ab5 ublox: fix UAF in custom init ready URC handler
Clear the unsolicited message handler in ready_received() before
completing the task. Otherwise, if the modem sends subsequent READY
URCs, the handler would fire again using the freed GTask pointer.

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/work_items/1074

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-07-10 15:00:07 +02:00
Aleksander Morgado db72a182c1 port-serial-at: fix crash if URC handler is cleared mid-dispatch
Update parse_unsolicited() to re-check handler->callback on each
iteration of the match dispatch loop. If a URC handler callback clears
itself during dispatch (e.g. to stop listening), subsequent matches in
the same buffer would attempt to call the NULL pointer, causing a crash.

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/work_items/1074

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-07-10 15:00:07 +02:00
Aleksander Morgado c3e7ffaae0 plugins: fix GError double-frees when returning errors from tasks
Use g_steal_pointer() when passing g_autoptr(GError) to
g_task_return_error() to prevent double-free by the automatic cleanup.

GTask takes ownership of the passed GError. If we use g_autoptr(GError)
locally, it will also call g_error_free() when the function returns,
causing a double-free / heap corruption. Stealing the pointer clears the
local variable and prevents the automatic cleanup.

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/work_items/1073

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-07-10 15:00:07 +02:00
Aleksander Morgado 166d6c5bc8 quectel: fix UAF in RDY URC handler
Defer the validity change (which triggers modem reprobe/removal) to an
idle callback in rdy_handler().

Calling mm_base_modem_set_valid(FALSE) synchronously from the URC
handler triggers the immediate destruction of the modem object while the
serial port is still iterating the unsolicited message handlers. Deferring
the operation to an idle callback and taking a reference to the modem
ensures the modem object is kept alive until parse_unsolicited() has
returned.

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/work_items/1072

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-07-10 15:00:07 +02:00
Aleksander Morgado 46a91399ca shared-qmi: fix UAF on duplicate list-configs indications
Disconnect the 'list-configs' indication handler immediately inside the
callback. If the modem sends a duplicate indication before the whole
config load sequence completes, it could overwrite the stored
'get-config-info' signal handler ID, orphaning the old handler and
leading to a Use-After-Free when the GTask is completed and the
orphaned handler eventually fires.

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/work_items/1071

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-07-10 15:00:07 +02:00
Aleksander Morgado 2b1aaca4a0 ifaces: fix UAFs in signal handlers when hot-unplugging
Use g_signal_connect_object() to connect to child list/object signals
in the 3GPP, Messaging, Voice, and Cell Broadcast interfaces.

Passing the raw D-Bus skeleton pointer as user_data to these signals
can lead to a Use-After-Free if the skeleton is disposed of (e.g. on
hot-unplug) while the parent object or child list survives. By using
g_signal_connect_object(), the signal handlers are automatically
disconnected when the D-Bus skeleton is destroyed.

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/work_items/1068

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-07-10 15:00:07 +02:00
Aleksander Morgado 0280bbae3b time: fix GSource leak and UAF in timezone poll
Introduce a timezone poll session ID to validate timezone load
results. This ensures that when a pending timezone load completes, we
discard the result if a new poll session has been started (e.g. due to
registration state changes) or if polling has been stopped.

This prevents leaking GSource timeout sources and a subsequent
Use-After-Free if the modem is hot-unplugged while a poll is pending.

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/work_items/1067

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-07-10 15:00:07 +02:00
Aleksander Morgado 6b3682ed65 voice: validate outgoing and deflect call numbers
Validate the number parameter in Voice.CreateCall and Call.Deflect
D-Bus methods to ensure they do not contain control characters or
semicolons. This prevents AT command injection when the number is
later spliced into ATD or +CTFR commands.

Introduce a common helper mm_utils_is_valid_dial_number() to validate
dial numbers, and add unit tests for it.

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/work_items/1067

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-07-10 13:43:48 +02:00
Aleksander Morgado 3291e7dd1c sim: validate preferred networks operator codes
Validate preferred network operator codes in the SIM D-Bus interface
handler to ensure they are numeric. This prevents injecting AT
command delimiters (like CR) into this field, which is later spliced
into AT commands (+CPOL).

This change also plugs the network list leak, that was a problem on
its own.

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/work_items/1065

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-07-10 13:43:48 +02:00
Aleksander Morgado 50202ad76a sim: validate PIN and PUK codes
Validate PIN and PUK codes in the SIM D-Bus interface handlers to
ensure they are numeric. This prevents injecting AT command
delimiters (like CR) into these fields, which are later spliced
into AT commands (+CPWD, +CLCK, +CPIN).

Introduce a common helper mm_utils_is_numeric() to check if a string
contains only digits, and add unit tests for it.

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/work_items/1065

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-07-10 13:43:48 +02:00
Aleksander Morgado dd54145d71 ussd: quote USSD command to prevent AT injection
When sending an unencoded USSD command, the user-supplied string was
spliced directly into the +CUSD AT command. If the string contained
CR or semicolons, it could lead to AT command injection.

Use mm_at_quote_string() to properly quote and escape the USSD
command before sending it.

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/work_items/1064

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-07-10 13:43:48 +02:00
Aleksander Morgado a39d46c637 location: validate SUPL host as FQDN or IP
When parsing a SUPL address, if the host is not a valid IPv4 address,
validate it as a FQDN (allowing only alphanumeric characters, dots,
and hyphens). This prevents injecting AT command delimiters (like CR
or semicolon) into the host string, which is later spliced into
modem-specific AT commands (+XLCSSLP).

Introduce a common helper mm_utils_is_valid_fqdn() to validate FQDNs,
and add unit tests for it.

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/work_items/1063

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-07-10 13:43:48 +02:00
Aleksander Morgado 1ee3a443b1 sms: sanitize decoded alphanumeric SMS addresses
Alphanumeric SMS addresses decoded from GSM-7 could contain control
characters (like CR/LF), which could lead to AT command injection
if the address is later spliced into an AT+CMGS command during
stored SMS send fallback.

Sanitize the decoded address by removing all control characters.

Introduce a common helper mm_utils_remove_control_characters() to
remove control characters from a string in-place, and add unit
tests for it.

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/work_items/1062

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-07-10 13:43:48 +02:00
Aleksander Morgado 44330936c6 rolling: fix single plugin build
The MTK specific modem object should be included in the 'mtk' shared
utils, so that they're available to other plugins.

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-04-22 14:27:38 +00:00
Aleksander Morgado b6d53915a6 port-qmi: add missing QMI_DATA_ENDPOINT_TYPE_ETHERNET
Fixes build with latest libqmi.

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-04-15 12:54:09 +00:00
Aleksander Morgado c34b326709 modem-helpers-qmi: add missing QMI_WDS_PDP_TYPE_NON_IP check
Fixes build with latest libqmi.

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-04-15 12:46:28 +00:00
Aleksander Morgado d8a01479ed api,doc: fix a typo in 'Modem.Device' documentation
Originally reported by Lubomir Rintel.

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2026-02-03 11:59:32 +01:00
Aleksander Morgado a24b60e52e fibocom: setup several +SIM URCs as hotplug event indications
Treat the following URCs as indications of possible SIM hot swap
events:
  +SIM: Inserted
  +SIM: Removed
  +SIM DROP

Any time any of these is received, a SIM hot swap event is reported,
and the logic can then determine what to do. These should lead to
doing nothing if they happen as part of a controlled SIM slot switch.

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2025-06-18 22:10:54 +00:00
Aleksander Morgado 7d4784ed28 iface-modem: ignore SIM events during a controlled SIM slot switch
If there is an ongoing SIM slot switch, we must ignore all SIM hotswap
related events happening during the process. The flag that is set in
the Modem interface private info to track this is never reset back to
FALSE on a successful SIM slot switch, it will be set for as long as
the modem object exists.

After the successful SIM slot switch, a new modem reprobe will be
requested, which leads to the old modem object to be disposed (the one
that had the flag set) and a new modem object created.

The logic that already existed in the MBIM modem object is now
generalized in the Modem interface itself so that SIM events reported
via other protocols are also properly ignored.

Signed-off-by: Aleksander Morgado <aleksandermj@google.com>
2025-06-18 22:10:54 +00:00
Aleksander Morgado 48a686a6d9 api: fix license headers in MM API
The libmm-glib library, as well as the ModemManager headers installed
as part of the D-Bus service API, have always been LGPLv2+ licensed,
because we want users of the service to rely on them in their own
programs, even if they are proprietary.

Some files had an incorrect GPLv2+ header instead of the LGPLv2+ and
that was confusing. All public headers in the MM API have the correct
license text now.

Signed-off-by: Aleksander Morgado <aleksandermj@chromium.org>
2025-03-13 00:35:24 +00:00
Aleksander Morgado ef5fe9b8d5 broadband-modem: prefer explicit return to break
Just to make it explicit that there is no more logic running
afterwards.
2025-02-03 10:21:32 +00:00
Aleksander Morgado 4ce23a9ebd broadband-modem: exit with error if enable() while in unknown state
We should not assert if the modem is flagged as invalid but an
outstanding enabling request is processed. Let's exit gracefully and
let the object get properly disposed afterwards.

   (libc.so.6 - pthread_kill.c: 44)         __pthread_kill_implementation
   (libc.so.6 - raise.c: 26)    raise
   (libc.so.6 - abort.c: 79)    abort
   (libglib-2.0.so.0 - gtestutils.c: 3450)  g_assertion_message
   (libglib-2.0.so.0 - gtestutils.c: 3476)  g_assertion_message_expr
   (ModemManager - mm-broadband-modem.c)    enable
   (ModemManager - mm-iface-modem.c: 2340)  handle_enable_auth_ready
   (libgio-2.0.so.0 - gtask.c: 1309)        g_task_return_now
   (libgio-2.0.so.0 - gtask.c: 1378)        g_task_return
   (ModemManager - mm-base-modem.c: 2011)   lock_after_authorize_ready
   (libgio-2.0.so.0 - gtask.c: 1309)        g_task_return_now
   (libgio-2.0.so.0 - gtask.c: 1378)        g_task_return
   (ModemManager - mm-base-modem.c: 1841)   base_modem_operation_run
   (ModemManager - mm-base-modem.c: 764)    state_operation_ready
   (libgio-2.0.so.0 - gtask.c: 1309)        g_task_return_now
   (libgio-2.0.so.0 - gtask.c: 1323)        complete_in_idle_cb
   (libglib-2.0.so.0 - gmain.c: 3460)       g_main_dispatch
   (libglib-2.0.so.0 - gmain.c: 4200)       g_main_context_dispatch
   (libglib-2.0.so.0 - gmain.c: 4276)       g_main_context_iterate
   (libglib-2.0.so.0 - gmain.c: 4479)       g_main_loop_run
   (ModemManager - main.c: 236) main
   (libc.so.6 - libc_start_call_main.h: 58) __libc_start_call_main
   (libc.so.6 - libc-start.c: 360)          __libc_start_main_impl
   (ModemManager + 0x000b8850)              _start
2025-02-03 10:18:19 +00:00
Aleksander Morgado 87e1e8b2d4 shared-qmi: don't assume LOC assistance data servers is initialized once
0x00007bcb78abf8b4	(libglib-2.0.so.0 -gtestutils.c:3450)		??g_assertion_message
  0x00007bcb78abf928	(libglib-2.0.so.0 -gtestutils.c:3476)		??g_assertion_message_expr
  0x00005594f143b221	(ModemManager -mm-shared-qmi.c:6651)		loc_location_get_predicted_orbits_data_source_indication_cb
  0x00007bcb78866043	(libgobject-2.0.so.0 -gmarshal.c:1686)		??g_cclosure_marshal_VOID__BOXEDv
  0x00007bcb7886338b	(libgobject-2.0.so.0 -gclosure.c:895)		_g_closure_invoke_va
  0x00007bcb78878a10	(libgobject-2.0.so.0 -gsignal.c:3472)		??g_signal_emit_valist
  0x00007bcb78879486	(libgobject-2.0.so.0 -gsignal.c:3622)		??g_signal_emit
  0x00007bcb785acc70	(libqmi-glib.so.5 -qmi-loc.c:16976)		process_indication
  0x00007bcb78520ede	(libqmi-glib.so.5 -qmi-device.c:1697)		process_indication_idle
  0x00007bcb78a9b75c	(libglib-2.0.so.0 -gmain.c:3460)		??g_main_dispatch
  0x00007bcb78a9b75c	(libglib-2.0.so.0 -gmain.c:4200)		??g_main_context_dispatch
  0x00007bcb78a9ba81	(libglib-2.0.so.0 -gmain.c:4276)		g_main_context_iterate
  0x00007bcb78a9bcff	(libglib-2.0.so.0 -gmain.c:4479)		??g_main_loop_run
  0x00005594f13a7463	(ModemManager -main.c:236)		??main
  0x00007bcb7825c705	(libc.so.6 -libc_start_call_main.h:58)		??__libc_start_call_main
  0x00007bcb7825c7c1	(libc.so.6 -libc-start.c:360)		??__libc_start_main_impl
  0x00005594f13a6da0	(ModemManager + 0x000b5da0)		??_start
2024-11-12 18:21:25 +00:00
Aleksander Morgado 3238ccdbb2 sim-qmi: implement loading GID1 and GID2 2022-08-19 15:53:43 +00:00
Aleksander Morgado 442c722d48 sim-qmi: define common SIM file paths for MF and ADF 2022-08-19 15:53:43 +00:00
Aleksander Morgado f61061044b base-sim: add steps to load GID1 and GID2 during init 2022-08-19 15:53:43 +00:00
Aleksander Morgado 210020c7d2 cli,sim: print GID1 and GID2 fields if available 2022-08-19 15:53:43 +00:00
Aleksander Morgado 59e36c6838 cli,sms: minor alignment fix 2022-08-19 15:53:43 +00:00
Aleksander Morgado cd933c740e libmm-glib,sim: add support to get GID1 and GID2 fields 2022-08-19 15:53:43 +00:00
Aleksander Morgado 219efb0253 libmm-glib,sim: add missing separators in source code 2022-08-19 15:53:43 +00:00
Aleksander Morgado b6b21f8fa6 api,introspection: add Gid1 and Gid2 properties in SIM interface 2022-08-19 15:53:43 +00:00
Aleksander Morgado a783d9f68a shared-qmi: minor rework SetPacketServiceState()
Port to using g_autoptr() so that we avoid the gotos.
2022-08-04 14:26:33 +00:00
Aleksander Morgado f58dcc832b iface-modem-3gpp: update packet service state in the interface
The skeleton property will be update automatically as they're bound.
2022-08-04 14:26:33 +00:00
Aleksander Morgado d82f0d5371 iface-modem-simple: wait for packet service state is 3GPP specific 2022-08-04 14:26:33 +00:00
Aleksander Morgado 9746600a12 broadband-modem-qmi: force IDLE state if PS registered but DSD RAT unavailable
We provide a consolidated method to update the PS/EPS/5GS registration
states, based on the actual state reported via NAS and the availabiity
or not of the DSD data RAT.

On this consolidated method, we now force the IDLE state for every
case where it would have been HOME/ROAMING if the data RAT reported
via the DSD service is unknown. This includes not only transitions
into the HOME/ROAMING state, but also transitions to unknown data RAT.
2022-08-04 14:26:33 +00:00
Aleksander Morgado 86f6d33513 sim-mbim: clear cached subscriber info on modem sync request 2022-08-01 20:17:43 +00:00
Aleksander Morgado f5b3dc7689 broadband-modem: notify when a sync is needed after a suspend/resume
Modem/SIM implementations that keep cached info that is not supposed
to change during runtime of a modem may need to be notified about when
a suspend/resume has happened, so that they can clear and reload the
internally cached data.
2022-08-01 19:51:26 +00:00
Aleksander Morgado bda3ade5a8 iface-modem: reordering of ready methods in sync() 2022-07-29 15:07:45 +02:00
Aleksander Morgado dd51defd2b broadband-modem: quick sync the Modem interface also if disabled
If the modem was in disabled state, we still want to sync the Modem
interface, among other things to make sure no SIM event happened
during the system suspension.

Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/605
2022-07-29 15:06:49 +02:00
Aleksander Morgado 1615c8627c broadband-modem: don't make fatal SIM swap check of IMSI or ICCID
If the SIM swap check using ICCID or IMSI fail, don't completely fail
the operation, as the other one may still succeed.

Fail the operation only if both checks failed.
2022-07-16 22:24:33 +02:00
Aleksander Morgado 76f837697a broadband-modem: plug leaks in sim_swap_context_free() 2022-07-16 22:24:28 +02:00
Aleksander Morgado 41ff262006 shared-qmi: improve logging of steps in SIM hot swap setup 2022-07-16 22:24:25 +02:00
Aleksander Morgado e96a111a63 shared-qmi: only transfer state to priv info if SIM hotswap setup succeeds
Don't transfer state to the private info until we know the operation
has fully succeeded.
2022-07-16 22:24:23 +02:00
Aleksander Morgado c994ae1b3a shared-qmi: move indication callbacks out of the SIM hot swap setup 2022-07-16 22:24:20 +02:00
Aleksander Morgado ba3b15fe29 shared-qmi: return error if none of the methods succeeded in SIM hot swap setup 2022-07-16 22:24:17 +02:00
Aleksander Morgado b7da236567 shared-qmi: avoid jumps in the SIM hot swap setup state machine
Always transition to the next step, and decide what to do based on the
state tracked by the previously run steps.
2022-07-16 22:24:14 +02:00
Aleksander Morgado 21d24657eb shared-qmi: make refresh all non-fatal during SIM hot swap setup
If for any reason "Refresh all" fails, don't return an error, as we
may have already configured SIM slot status correctly.
2022-07-16 22:24:02 +02:00
Aleksander Morgado d2bc73f394 shared-qmi: add slot status indication in its own step during SIM hot swap setup 2022-07-16 22:23:57 +02:00
Aleksander Morgado 405f5867c7 shared-qmi: add slot status check in its own step during SIM hot swap setup
Also, don't make the "Get Slot Status" operation fatal; just go on
assuming that the slot status indications are unsupported.
2022-07-16 22:23:53 +02:00
Aleksander Morgado 76c0896535 shared-qmi: new step in SIM hot swap setup to connect to refresh signal
Instead of connecting to the signal in multiple places, do it in one
single place in the logic.
2022-07-16 22:23:45 +02:00