From 937299d72b5060fd3e98527b0a4268c549a94d3f Mon Sep 17 00:00:00 2001 From: Mario Limonciello Date: Tue, 13 Mar 2018 22:08:39 -0500 Subject: [PATCH] uefi: Check that EFI system partition is mounted (Fixes: #436) If the ESP isn't mounted it's possible that the update may look succesful on the Linux side, but certain to fail later. --- plugins/uefi/fu-plugin-uefi.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/plugins/uefi/fu-plugin-uefi.c b/plugins/uefi/fu-plugin-uefi.c index f587c1d41..c089a7e37 100644 --- a/plugins/uefi/fu-plugin-uefi.c +++ b/plugins/uefi/fu-plugin-uefi.c @@ -377,6 +377,30 @@ fu_plugin_uefi_update_splash (GError **error) return fu_plugin_uefi_update_resource (re, 0, image_bmp, error); } +static gboolean +fu_plugin_uefi_esp_mounted (FuPlugin *plugin, GError **error) +{ + FuPluginData *data = fu_plugin_get_data (plugin); + g_autofree gchar *contents = NULL; + g_auto(GStrv) lines = NULL; + gsize length; + + if (!g_file_get_contents ("/proc/mounts", &contents, &length, error)) + return FALSE; + lines = g_strsplit (contents, "\n", 0); + + for (guint i = 0; lines[i] != NULL; i++) { + if (lines[i] != NULL && g_strrstr (lines[i], data->esp_path)) + return TRUE; + } + g_set_error (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_SUPPORTED, + "EFI System partition %s is not mounted", + data->esp_path); + return FALSE; +} + gboolean fu_plugin_update (FuPlugin *plugin, FuDevice *device, @@ -403,6 +427,10 @@ fu_plugin_update (FuPlugin *plugin, str = _("Installing firmware update…"); g_assert (str != NULL); + /* make sure that the ESP is mounted */ + if (!fu_plugin_uefi_esp_mounted (plugin, error)) + return FALSE; + /* perform the update */ g_debug ("Performing UEFI capsule update"); fu_device_set_status (device, FWUPD_STATUS_SCHEDULING);