summaryrefslogtreecommitdiff
path: root/lib/efi_loader
diff options
context:
space:
mode:
Diffstat (limited to 'lib/efi_loader')
-rw-r--r--lib/efi_loader/efi_device_path.c11
-rw-r--r--lib/efi_loader/efi_disk.c24
2 files changed, 32 insertions, 3 deletions
diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
index 897fc1b2e8a..ac5e6f7e14f 100644
--- a/lib/efi_loader/efi_device_path.c
+++ b/lib/efi_loader/efi_device_path.c
@@ -15,6 +15,7 @@
#include <part.h>
#include <sandboxblockdev.h>
#include <asm-generic/unaligned.h>
+#include <linux/compat.h> /* U16_MAX */
#ifdef CONFIG_SANDBOX
const efi_guid_t efi_guid_host_dev = U_BOOT_HOST_DEV_GUID;
@@ -888,13 +889,16 @@ struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
{
struct efi_device_path_file_path *fp;
void *buf, *start;
- unsigned dpsize = 0, fpsize;
+ size_t dpsize = 0, fpsize;
if (desc)
dpsize = dp_part_size(desc, part);
fpsize = sizeof(struct efi_device_path) +
2 * (utf8_utf16_strlen(path) + 1);
+ if (fpsize > U16_MAX)
+ return NULL;
+
dpsize += fpsize;
start = buf = dp_alloc(dpsize + sizeof(END));
@@ -908,7 +912,7 @@ struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
fp = buf;
fp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
fp->dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH;
- fp->dp.length = fpsize;
+ fp->dp.length = (u16)fpsize;
path_to_uefi(fp->str, path);
buf += fpsize;
@@ -1070,5 +1074,8 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr,
*file = efi_dp_from_file(((!is_net && device) ? desc : NULL),
part, filename);
+ if (!file)
+ return EFI_INVALID_PARAMETER;
+
return EFI_SUCCESS;
}
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index 9007a5f77f3..861fcaf3747 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -9,6 +9,7 @@
#include <blk.h>
#include <dm.h>
#include <efi_loader.h>
+#include <fs.h>
#include <part.h>
#include <malloc.h>
@@ -262,6 +263,27 @@ efi_fs_from_path(struct efi_device_path *full_path)
return handler->protocol_interface;
}
+/**
+ * efi_fs_exists() - check if a partition bears a file system
+ *
+ * @desc: block device descriptor
+ * @part: partition number
+ * Return: 1 if a file system exists on the partition
+ * 0 otherwise
+ */
+static int efi_fs_exists(struct blk_desc *desc, int part)
+{
+ if (fs_set_blk_dev_with_part(desc, part))
+ return 0;
+
+ if (fs_get_type() == FS_TYPE_ANY)
+ return 0;
+
+ fs_close();
+
+ return 1;
+}
+
/*
* Create a handle for a partition or disk
*
@@ -315,7 +337,7 @@ static efi_status_t efi_disk_add_dev(
diskobj->dp);
if (ret != EFI_SUCCESS)
return ret;
- if (part >= 1) {
+ if (part >= 1 && efi_fs_exists(desc, part)) {
diskobj->volume = efi_simple_file_system(desc, part,
diskobj->dp);
ret = efi_add_protocol(&diskobj->header,