thunderbolt: make sure that authorized to add updatable flag

If the device is not authorized, it may cause a composite update that it's part
of to not behave properly.

If device is authorized at runtime, add updatable flag at runtime as well
See #2374 for more details
This commit is contained in:
Mario Limonciello 2020-09-10 21:55:44 -05:00 committed by Mario Limonciello
parent c756405529
commit 76cc23c736
2 changed files with 47 additions and 2 deletions

View File

@ -396,7 +396,7 @@ mock_tree_attach_device (gpointer user_data)
"device", dev->id, "device", dev->id,
"vendor", "042", "vendor", "042",
"vendor_name", "GNOME.org", "vendor_name", "GNOME.org",
"authorized", "0", "authorized", "1",
"nvm_authenticate", authenticate, "nvm_authenticate", authenticate,
"nvm_version", tree->nvm_version, "nvm_version", tree->nvm_version,
"unique_id", tree->uuid, "unique_id", tree->uuid,

View File

@ -110,6 +110,42 @@ fu_thunderbolt_device_read_status_block (FuThunderboltDevice *self, GError **err
return TRUE; return TRUE;
} }
static gboolean
fu_thunderbolt_device_check_authorized (FuThunderboltDevice *self, GError **error)
{
guint64 status;
g_autofree gchar *attribute = NULL;
const gchar *update_error = NULL;
/* read directly from file to prevent udev caching */
g_autofree gchar *safe_path = g_build_path ("/", self->devpath, "authorized", NULL);
if (!g_file_test (safe_path, G_FILE_TEST_EXISTS)) {
g_set_error_literal (error,
FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED,
"missing authorized attribute");
return FALSE;
}
if (!g_file_get_contents (safe_path, &attribute, NULL, error))
return FALSE;
status = g_ascii_strtoull (attribute, NULL, 16);
if (status == G_MAXUINT64 && errno == ERANGE) {
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
"failed to read 'authorized: %s",
g_strerror (errno));
return FALSE;
}
if (status == 1)
fu_device_add_flag (FU_DEVICE (self), FWUPD_DEVICE_FLAG_UPDATABLE);
else
update_error = "Not authorized";
fu_device_set_update_error (FU_DEVICE (self), update_error);
return TRUE;
}
static gboolean static gboolean
fu_thunderbolt_device_can_update (FuThunderboltDevice *self) fu_thunderbolt_device_can_update (FuThunderboltDevice *self)
{ {
@ -362,8 +398,12 @@ fu_thunderbolt_device_setup_controller (FuDevice *device, GError **error)
(guint) vid, (guint) vid,
(guint) did, (guint) did,
self->is_native ? "-native" : ""); self->is_native ? "-native" : "");
fu_device_add_flag (device, FWUPD_DEVICE_FLAG_UPDATABLE);
fu_device_add_flag (device, FWUPD_DEVICE_FLAG_DUAL_IMAGE); fu_device_add_flag (device, FWUPD_DEVICE_FLAG_DUAL_IMAGE);
/* check if device is authorized */
if (!fu_thunderbolt_device_check_authorized (self, error))
return FALSE;
} else { } else {
device_id = g_strdup ("TBT-fixed"); device_id = g_strdup ("TBT-fixed");
} }
@ -517,6 +557,11 @@ static gboolean
fu_thunderbolt_device_rescan (FuDevice *device, GError **error) fu_thunderbolt_device_rescan (FuDevice *device, GError **error)
{ {
FuThunderboltDevice *self = FU_THUNDERBOLT_DEVICE (device); FuThunderboltDevice *self = FU_THUNDERBOLT_DEVICE (device);
/* refresh updatability */
if (!fu_thunderbolt_device_check_authorized (self, error))
return FALSE;
/* refresh the version */ /* refresh the version */
return fu_thunderbolt_device_get_version (self, error); return fu_thunderbolt_device_get_version (self, error);
} }