mirror of
https://git.savannah.gnu.org/git/grub.git
synced 2026-10-29 02:31:05 +00:00
luks2: Better error handling when setting up the cryptodisk
Do some sanity checking on data coming from the LUKS2 header. If segment.size is "dynamic", verify that the offset is not past the end of disk. Otherwise, check for errors from grub_strtoull() when converting segment size from string. If a GRUB_ERR_BAD_NUMBER error was returned, then the string was not a valid parsable number, so skip the key. If GRUB_ERR_OUT_OF_RANGE was returned, then there was an overflow in converting to a 64-bit unsigned integer. So this could be a very large disk (perhaps large RAID array). In this case skip the key too. Additionally, enforce some other limits and fail if needed. Signed-off-by: Glenn Washburn <development@efficientek.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
1 parent
278201bc31
commit
9c3149a2f2
2 files changed
+93
-3
No files matched your search
@@ -27,6 +27,8 @@
|
||||
#include <grub/device.h>
|
||||
/* For NULL. */
|
||||
#include <grub/mm.h>
|
||||
/* For ALIGN_UP. */
|
||||
#include <grub/misc.h>
|
||||
|
||||
/* These are used to set a device id. When you add a new disk device,
|
||||
you must define a new id for it here. */
|
||||
@@ -180,6 +182,23 @@ typedef struct grub_disk_memberlist *grub_disk_memberlist_t;
|
||||
/* Return value of grub_disk_native_sectors() in case disk size is unknown. */
|
||||
#define GRUB_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL
|
||||
|
||||
/* Convert sector number from one sector size to another. */
|
||||
static inline grub_disk_addr_t
|
||||
grub_convert_sector (grub_disk_addr_t sector,
|
||||
grub_size_t log_sector_size_from,
|
||||
grub_size_t log_sector_size_to)
|
||||
{
|
||||
if (log_sector_size_from == log_sector_size_to)
|
||||
return sector;
|
||||
else if (log_sector_size_from < log_sector_size_to)
|
||||
{
|
||||
sector = ALIGN_UP (sector, 1 << (log_sector_size_to - log_sector_size_from));
|
||||
return sector >> (log_sector_size_to - log_sector_size_from);
|
||||
}
|
||||
else
|
||||
return sector << (log_sector_size_from - log_sector_size_to);
|
||||
}
|
||||
|
||||
/* Convert to GRUB native disk sized sector from disk sized sector. */
|
||||
static inline grub_disk_addr_t
|
||||
grub_disk_from_native_sector (grub_disk_t disk, grub_disk_addr_t sector)
|
||||
|
||||
Reference in new issue
Block a user