Skip to contentSkip to conversation

sim: validate IMS private identity

PATCH Superseded Sergey Matyukevich 2 participants 4 messages Jan 15, 2021

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sim: validate IMS private identity

Make sure that IMPI is a valid UTF8 string before attempting to report it via DBus. Otherwise ofono may crash on dbus assert. This field may not be defined for ISIM in use. In this case the field still can be read from ISIM, though it will not contain a valid UTF8 string. For instance, it may contain 255 0xFF bytes.

---
 src/sim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/sim.c +1 -1
index 33e1245f..f60f5d1b 100644
@@ -423,7 +423,7 @@ static DBusMessage *sim_get_properties(DBusConnection *conn,
 		ofono_dbus_dict_append(&dict, "ServiceProviderName",
 					DBUS_TYPE_STRING, &sim->spn);
 
-	if (sim->impi)
+	if (sim->impi && g_utf8_validate(sim->impi, 255, NULL))
 		ofono_dbus_dict_append(&dict, "ImsPrivateIdentity",
 					DBUS_TYPE_STRING, &sim->impi);
 
#1 lore raw

Hi Sergey,

Quoted 5 lines · Sergey Matyukevich

Make sure that IMPI is a valid UTF8 string before attempting to report it via DBus. Otherwise ofono may crash on dbus assert. This field may not be defined for ISIM in use. In this case the field still can be read from ISIM, though it will not contain a valid UTF8 string. For instance, it may contain 255 0xFF bytes.

Ugh, seems like the SIM vendor can't follow RFC's either? 31.103 Section 4.2.2 says:

"For contents and syntax of NAI TLV data object values see IETF RFC 2486 [24]. The NAI shall be encoded to an octet string according to UTF-8 encoding rules as specified in IETF RFC 3629 [27]. The tag value of the NAI TLV data object shall be '80'. "

Quoted 9 lines
---
  src/sim.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
src/sim.c +0 -0
index 33e1245f..f60f5d1b 100644

src/sim.c static DBusMessage *sim_get_properties(DBusConnection *conn, · line 426

Quoted 5 lines
src/sim.c +1 -1
@@ -423,7 +423,7 @@ static DBusMessage *sim_get_properties(DBusConnection *conn,
  		ofono_dbus_dict_append(&dict, "ServiceProviderName",
  					DBUS_TYPE_STRING, &sim->spn);
 
-	if (sim->impi)
+	if (sim->impi && g_utf8_validate(sim->impi, 255, NULL))

Hmm, this would imply that we're setting sim->impi incorrectly.. Also, since we have __ofono_sim_get_impi() API, the better fix would be to make sure sim->impi is set correctly in impi_read_cb()

Quoted 7 lines
src/sim.c +0 -0
  		ofono_dbus_dict_append(&dict, "ImsPrivateIdentity",
  					DBUS_TYPE_STRING, &sim->impi);
 

_______________________________________________
ofono mailing list -- ofono(a)ofono.org
To unsubscribe send an email to ofono-leave(a)ofono.org

Regards,
-Denis

#2 lore raw

Hi Denis,

Quoted 6 lines
Quoted 5 lines

Make sure that IMPI is a valid UTF8 string before attempting to report it via DBus. Otherwise ofono may crash on dbus assert. This field may not be defined for ISIM in use. In this case the field still can be read from ISIM, though it will not contain a valid UTF8 string. For instance, it may contain 255 0xFF bytes.

Quoted 7 lines

Ugh, seems like the SIM vendor can't follow RFC's either? 31.103 Section 4.2.2 says:

"For contents and syntax of NAI TLV data object values see IETF RFC 2486 [24]. The NAI shall be encoded to an octet string according to UTF-8 encoding rules as specified in IETF RFC 3629 [27]. The tag value of the NAI TLV data object shall be '80'. "

This crash occured during my experiments with eSIM. As I mentioned, the content of that TLV data object was 0xff bytes. IIUC it looks like vendor could just skip initialization of that particular TLV data object during bootstrap. Though I am not yet familiar with eSIM init procedure...

Quoted 4 lines
Quoted 4 lines
---
  src/sim.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

src/sim.c static DBusMessage *sim_get_properties(DBusConnection *conn, · line 425

Quoted 9 lines
src/sim.c +1 -1
index 33e1245f..f60f5d1b 100644
@@ -423,7 +423,7 @@ static DBusMessage *sim_get_properties(DBusConnection *conn,
  		ofono_dbus_dict_append(&dict, "ServiceProviderName",
  					DBUS_TYPE_STRING, &sim->spn);
-	if (sim->impi)
+	if (sim->impi && g_utf8_validate(sim->impi, 255, NULL))

Hmm, this would imply that we're setting sim->impi incorrectly.. Also, since we have __ofono_sim_get_impi() API, the better fix would be to make sure sim->impi is set correctly in impi_read_cb()

Ok. I will set sim->impi in impi_read_cb only if it is a valid UTF8 string.

Regards,
Sergey

#3 lore raw

Hi Sergey,

Quoted 12 lines
Quoted 11 lines
Quoted 3 lines

This field may not be defined for ISIM in use. In this case the field still can be read from ISIM, though it will not contain a valid UTF8 string. For instance, it may contain 255 0xFF bytes.

Ugh, seems like the SIM vendor can't follow RFC's either? 31.103 Section 4.2.2 says:

"For contents and syntax of NAI TLV data object values see IETF RFC 2486 [24]. The NAI shall be encoded to an octet string according to UTF-8 encoding rules as specified in IETF RFC 3629 [27]. The tag value of the NAI TLV data object shall be '80'. "

Quoted 5 lines

This crash occured during my experiments with eSIM. As I mentioned, the content of that TLV data object was 0xff bytes. IIUC it looks like vendor could just skip initialization of that particular TLV data object during bootstrap. Though I am not yet familiar with eSIM init procedure...

I figured. The likely reason for this is that SIM strings are generally encoded in another format. If you're interested, see src/util.c sim_string_to_utf8(). 0xff is used as padding in such cases and thus a field with only 0xffs is treated as empty.

However, the above would seem not to apply to EFimpi and a few others that 3GPP wants encoded as a utf-8 string. So, likely, a bug on the SIM, but we should have sanitized the contents better.

Regards,
-Denis